int comp_iot_add_resource(comp_resource_type_e resource_type, const char *uri);
int comp_iot_delete_resource(comp_resource_type_e resource_type);
int comp_iot_discovery_resource(comp_resource_type_e resource_type, int timeout, void *user_data);
+int comp_iot_send_data(comp_resource_type_e resource_type, int timeout,
+ comp_command_t *cmd);
int comp_iot_deinitialize();
#ifdef __cplusplus
cmd->command = COMP_REQ_SEND_DATA;
cmd->uuid = g_strdup(uuid_dev);
+ /* IPv6 Address should be encoded for RFC6874 */
if (strchr(ip, ':')) /* IPv6 Adress */
- cmd->host = g_strdup_printf("coap://[%s]:%d", ip, port);
+ cmd->host = g_strdup_printf("coaps://[%s%s%s]:%d", ip, "%25",
+ percent + 1, port);
else /* IPv4 Address */
- cmd->host = g_strdup_printf("coap://%s:%d", ip, port);
+ cmd->host = g_strdup_printf("coaps://%s:%d", ip, port);
cmd->arg1 = g_malloc0(len + 1);
if (NULL == cmd->arg1) {
LOG_DEBUG("UUID %s host %s", cmd->uuid, cmd->host);
- ret = comp_iot_discovery_resource(COMP_RESOURCE_TYPE_DATA, 5, cmd);
+ ret = comp_iot_send_data(COMP_RESOURCE_TYPE_DATA, 3, cmd);
if (ret != COMP_ERROR_NONE) {
- LOG_ERR("Failed to discover resource : %s",
+ LOG_ERR("Failed to send data : %s",
comp_log_get_error_string(ret));
}
return ret;
}
+int comp_iot_send_data(comp_resource_type_e resource_type, int timeout,
+ comp_command_t *cmd)
+{
+ int ret;
+ OCResource::Ptr resource;
+ std::string requestURI;
+ std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
+ std::vector<std::string> resource_types;
+ resource_types = {comp_resource_get_type(resource_type)};
+
+ try {
+ requestURI = std::string(comp_resource_get_uri_prefix(resource_type)) +
+ "1";
+
+ LOG_DEBUG("Request URI %s", requestURI.c_str());
+
+ resource = OCPlatform::constructResourceObject(std::string(cmd->host),
+ requestURI, CT_ADAPTER_IP, false,
+ resource_types, ifaces);
+ if (!resource) {
+ LOG_ERR("Failed to construct resource");
+ return -1;
+ }
+
+ OCRepresentation rep;
+ rep.setValue("CMD", COMP_REQ_SEND_DATA);
+ rep.setValue("data", std::string(cmd->arg1));
+
+ ret = resource->post(rep, QueryParamsMap(),
+ std::bind (&_on_post, std::placeholders::_1,
+ std::placeholders::_2, std::placeholders::_3, cmd));
+
+ } catch (OCException &e) {
+ LOG_ERR("Failed to send data %s", e.what());
+ ret = e.code();
+ }
+
+ cmd->resource_type = resource_type;
+ cmd->tid = g_timeout_add_seconds(timeout + 1, _timeout_cb, cmd);
+
+ LOG_DEBUG("Send Data : %s", get_error_message(ret));
+
+ return ret;
+}
+
int comp_iot_delete_resource(comp_resource_type_e resource_type)
{
//delete resource from resource list using resource_type and index