ThinCloud Embedded C SDK
Macros | Functions | Variables
thincloud.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <json-c/json.h>
#include "aws_iot_log.h"
#include "aws_iot_error.h"
#include "aws_iot_mqtt_client_interface.h"

Go to the source code of this file.

Macros

#define TC_EMBEDDED_C_SDK_VERSION_MAJOR   1
 
#define TC_EMBEDDED_C_SDK_VERSION_MINOR   1
 
#define TC_EMBEDDED_C_SDK_VERSION_PATCH   0
 
#define TC_ID_LENGTH   37
 
#define MAX_TOPIC_LENGTH   257
 
#define REQUEST_METHOD_GET   "GET"
 
#define REQUEST_METHOD_PUT   "PUT"
 
#define REQUEST_METHOD_POST   "POST"
 
#define REQUEST_METHOD_DELETE   "DELETE"
 

Functions

IoT_Error_t commission_request_topic (char *buffer, const char *deviceType, const char *physicalId)
 Build a commission request topic. More...
 
IoT_Error_t commission_response_topic (char *buffer, const char *deviceType, const char *physicalId, const char *requestId)
 Build a commission response topic. More...
 
IoT_Error_t command_request_topic (char *buffer, const char *deviceId)
 Build a command request topic. More...
 
IoT_Error_t command_response_topic (char *buffer, const char *deviceId, const char *commandId)
 Build a command response topic. More...
 
IoT_Error_t service_request_topic (char *buffer, const char *deviceId)
 Build a service request topic. More...
 
IoT_Error_t service_response_topic (char *buffer, const char *deviceId, const char *requestId)
 Build a service response topic. More...
 
IoT_Error_t commissioning_request (char *buffer, const char *requestId, const char *deviceType, const char *physicalId, char **relatedDeviceIds, uint32_t idsSize)
 Build a commissioning request. More...
 
IoT_Error_t commissioning_response (char *deviceId, uint16_t *statusCode, char *requestId, char *payload, uint16_t payloadLen)
 Unmarshall a commissioning response. More...
 
IoT_Error_t command_response (char *buffer, const char *requestId, uint16_t statusCode, bool isErrorResponse, char *errorMessage, json_object *body)
 Marshal a command response. More...
 
IoT_Error_t command_request (char *requestId, char *method, json_object **params, const char *payload, const unsigned int payloadLen)
 Unmarshall a command request payload. More...
 
IoT_Error_t service_request (char *buffer, const char *requestId, const char *method, json_object *params)
 Marshal a service request. More...
 
IoT_Error_t service_response (char *requestId, uint16_t *statusCode, json_object **data, const char *payload, const unsigned int payloadLen)
 Unmarshall a service response payload. More...
 
IoT_Error_t send_command_response (AWS_IoT_Client *client, const char *deviceId, const char *commandId, uint16_t statusCode, bool isErrorResponse, char *errorMessage, json_object *body)
 Send a command response. More...
 
IoT_Error_t send_commissioning_request (AWS_IoT_Client *client, const char *requestId, const char *deviceType, const char *physicalId, char **relatedDeviceIds, uint32_t idsSize)
 Send commissioning request. More...
 
IoT_Error_t send_service_request (AWS_IoT_Client *client, const char *requestId, const char *deviceId, const char *method, json_object *reqParams)
 Send service request. More...
 
IoT_Error_t subscribe_to_commissioning_response (AWS_IoT_Client *client, const char *requestId, const char *deviceType, const char *physicalId, pApplicationHandler_t handler, void *subscribeData)
 Subscribe to commissioning respones. More...
 
IoT_Error_t subscribe_to_command_request (AWS_IoT_Client *client, const char *deviceId, pApplicationHandler_t handler, void *subscribeData)
 Subscribe to command requests. More...
 
IoT_Error_t subscribe_to_service_response (AWS_IoT_Client *client, const char *deviceId, const char *requestId, pApplicationHandler_t handler, void *subscribeData)
 Subscribe to service responses. More...
 
IoT_Error_t tc_init (AWS_IoT_Client *client, char *hostAddr, char *rootCAPath, char *clientCRTPath, char *clientKeyPath, iot_disconnect_handler handler, void *disconnectData)
 Initialize an AWS IoT Client. More...
 
IoT_Error_t tc_connect (AWS_IoT_Client *client, char *clientId, bool autoReconnect)
 Start MQTT connection to ThinCloud host. More...
 

Variables

char COMMISSIONING_RESPONSE_TOPIC_BUFFER [MAX_TOPIC_LENGTH]
 
char COMMAND_TOPIC_BUFFER [MAX_TOPIC_LENGTH]
 
char SERVICE_RESPONSE_TOPIC_BUFFER [MAX_TOPIC_LENGTH]
 

Macro Definition Documentation

◆ MAX_TOPIC_LENGTH

#define MAX_TOPIC_LENGTH   257

AWS IoT Max Topic Length plus null character

◆ REQUEST_METHOD_DELETE

#define REQUEST_METHOD_DELETE   "DELETE"

◆ REQUEST_METHOD_GET

#define REQUEST_METHOD_GET   "GET"

◆ REQUEST_METHOD_POST

#define REQUEST_METHOD_POST   "POST"

◆ REQUEST_METHOD_PUT

#define REQUEST_METHOD_PUT   "PUT"

◆ TC_EMBEDDED_C_SDK_VERSION_MAJOR

#define TC_EMBEDDED_C_SDK_VERSION_MAJOR   1

◆ TC_EMBEDDED_C_SDK_VERSION_MINOR

#define TC_EMBEDDED_C_SDK_VERSION_MINOR   1

◆ TC_EMBEDDED_C_SDK_VERSION_PATCH

#define TC_EMBEDDED_C_SDK_VERSION_PATCH   0

◆ TC_ID_LENGTH

#define TC_ID_LENGTH   37

UUID standard length plus null character

Function Documentation

◆ command_request()

IoT_Error_t command_request ( char *  requestId,
char *  method,
json_object **  params,
const char *  payload,
const unsigned int  payloadLen 
)

Unmarshall a command request payload.

Unmarshall a command request from a string payload.

Parameters
[out]requestIdID of the original request.
[out]methodCommand method.
[out]paramsCommand request parameters.
[in]payloadResponse payload.
[in]payloadLenReponse payload's length.
Returns
Zero on success, a negative value otherwise

◆ command_request_topic()

IoT_Error_t command_request_topic ( char *  buffer,
const char *  deviceId 
)

Build a command request topic.

Constructs a command request topic of the format "thincloud/devices/{deviceId}/command"

Parameters
[out]bufferPointer to a string buffer to write to.
[in]deviceIdDevice's ID.
Returns
Zero on success, negative value otherwise

◆ command_response()

IoT_Error_t command_response ( char *  buffer,
const char *  requestId,
uint16_t  statusCode,
bool  isErrorResponse,
char *  errorMessage,
json_object *  body 
)

Marshal a command response.

Marshal a command response into a JSON string.

Parameters
[out]bufferPointer to a string buffer to write to.
[in]requestIdCommand request's ID.
[in]statusCodeCommand's response status.
[in]isErrorResponseSignals if a command responds with an error.
[in]errorMessageResponse error message. Only used if isErrorResponse is set to true.
[in]bodyCommand response body.
Returns
Zero on success, a negative value otherwise

◆ command_response_topic()

IoT_Error_t command_response_topic ( char *  buffer,
const char *  deviceId,
const char *  commandId 
)

Build a command response topic.

Constructs a command response topic of the format "thincloud/devices/{deviceId}/command/{commandId}/response"

Parameters
[out]bufferPointer to a string buffer to write to.
[in]deviceIdDevices's ID.
[in]commandIdCommand request's ID.
Returns
Zero on success, negative value otherwise

◆ commission_request_topic()

IoT_Error_t commission_request_topic ( char *  buffer,
const char *  deviceType,
const char *  physicalId 
)

Build a commission request topic.

Constructs a commission request topic of the format "thincloud/registration/{deviceType}_{physicalId}/requests"

Parameters
[out]bufferPointer to a string buffer to write to.
[in]deviceTypeDevices's device type.
[in]physicalIdDevice's physical ID.
Returns
Zero on success, negative value otherwise

◆ commission_response_topic()

IoT_Error_t commission_response_topic ( char *  buffer,
const char *  deviceType,
const char *  physicalId,
const char *  requestId 
)

Build a commission response topic.

Constructs a commission response topic of the format "thincloud/registration/{deviceType}_{physicalId}/requests/{requestId}/response"

Parameters
[out]bufferPointer to a string buffer to write to.
[in]deviceTypeDevices's device type.
[in]physicalIdDevice's physical ID.
[in]requestIdUnique ID for the request.
Returns
Zero on success, negative value otherwise

◆ commissioning_request()

IoT_Error_t commissioning_request ( char *  buffer,
const char *  requestId,
const char *  deviceType,
const char *  physicalId,
char **  relatedDeviceIds,
uint32_t  idsSize 
)

Build a commissioning request.

Construct a commissioning request.

Parameters
[out]bufferPointer to a string buffer to write to
[in]requestIdUnique ID for the request
[in]deviceTypeRequesting device's type
[in]physicalIdDevice's physical ID
[in]relatedDeviceIdsList of devices to associate on commissioning
[in]idsSizeSize of related device ids list
Returns
Zero on success, negative value otherwise

◆ commissioning_response()

IoT_Error_t commissioning_response ( char *  deviceId,
uint16_t *  statusCode,
char *  requestId,
char *  payload,
uint16_t  payloadLen 
)

Unmarshall a commissioning response.

Unmarshall a commissioning response from a string stream.

Parameters
[out]deviceIdAssigned device ID.
[out]statusCodeCommissioning status.
[out]requestIdID of the original request.
[in]payloadResponse payload.
[in]payloadLenReponse payload's length.
Returns
Zero on success, a negative value otherwise

◆ send_command_response()

IoT_Error_t send_command_response ( AWS_IoT_Client *  client,
const char *  deviceId,
const char *  commandId,
uint16_t  statusCode,
bool  isErrorResponse,
char *  errorMessage,
json_object *  body 
)

Send a command response.

Publish a command response to MQTT.

Parameters
[in]clientAWS IoT MQTT Client instance.
[in]deviceIdDevice's ID.
[in]commandIdID of the requested command.
[in]statusCodeCommand's status code.
[in]isErrorResponseSignals if a command responds with an error.
[in]errorMessageResponse error message. Only used if isErrorResponse is set to true.
[in]bodyCommand response body.
Returns
Zero on success, negative value otherwise

◆ send_commissioning_request()

IoT_Error_t send_commissioning_request ( AWS_IoT_Client *  client,
const char *  requestId,
const char *  deviceType,
const char *  physicalId,
char **  relatedDeviceIds,
uint32_t  idsSize 
)

Send commissioning request.

Publish a commissioning request to MQTT.

Parameters
[in]clientAWS IoT MQTT Client instance.
[in]requestIdUnique ID for the request.
[in]deviceTypeDevices's device type.
[in]physicalIdDevice's physical ID.
[in]relatedDeviceIdsList of devices to associate on commissioning
[in]idsSizeSize of related device ids list
Returns
Zero on success, negative value otherwise

◆ send_service_request()

IoT_Error_t send_service_request ( AWS_IoT_Client *  client,
const char *  requestId,
const char *  deviceId,
const char *  method,
json_object *  reqParams 
)

Send service request.

Publish a service request to MQTT.

Parameters
[in]clientAWS IoT MQTT Client instance.
[in]requestIdUnique ID for the request.
[in]deviceIdDevices's ID.
[in]methodService method to request.
[in]paramsService request parameters.
Returns
Zero on success, negative value otherwise

◆ service_request()

IoT_Error_t service_request ( char *  buffer,
const char *  requestId,
const char *  method,
json_object *  params 
)

Marshal a service request.

Marshal a service request to a JSON string.

Parameters
[out]bufferPointer to a string buffer to write to.
[in]requestIdUnique ID for the request.
[in]methodService method to request.
[in]paramsService request parameters.
Returns
Zero on success, a negative value otherwise

◆ service_request_topic()

IoT_Error_t service_request_topic ( char *  buffer,
const char *  deviceId 
)

Build a service request topic.

Constructs a service request topic of the format "thincloud/devices/{deviceId}/requests"

Parameters
[out]bufferPointer to a string buffer to write to.
[in]deviceIdDevices's ID.
Returns
Zero on success, negative value otherwise

◆ service_response()

IoT_Error_t service_response ( char *  requestId,
uint16_t *  statusCode,
json_object **  data,
const char *  payload,
const unsigned int  payloadLen 
)

Unmarshall a service response payload.

Unmarshall a service response from a string payload.

Parameters
[out]requestIdRequest ID of the original request.
[out]statusCodeRequest's status.
[out]dataResponse's data.
[in]payloadResponse payload.
[in]payloadLenReponse payload's length.
Returns
Zero on success, a negative value otherwise

◆ service_response_topic()

IoT_Error_t service_response_topic ( char *  buffer,
const char *  deviceId,
const char *  requestId 
)

Build a service response topic.

Constructs a service response topic of the format "thincloud/devices/{deviceId}/requests/%s/response"

Parameters
[out]bufferPointer to a string buffer to write to.
[in]deviceIdDevices's ID.
[in]requestIdRequest's ID.
Returns
Zero on success, negative value otherwise

◆ subscribe_to_command_request()

IoT_Error_t subscribe_to_command_request ( AWS_IoT_Client *  client,
const char *  deviceId,
pApplicationHandler_t  handler,
void *  subscribeData 
)

Subscribe to command requests.

Parameters
[in]clientAWS IoT MQTT Client instance.
[in]deviceIdDevice's ID.
[in]handlerSubscription response handler.
[in]subscriberDataData blob to be passed to the subscription handler on invoke.
Returns
Zero on success, negative value otherwise

◆ subscribe_to_commissioning_response()

IoT_Error_t subscribe_to_commissioning_response ( AWS_IoT_Client *  client,
const char *  requestId,
const char *  deviceType,
const char *  physicalId,
pApplicationHandler_t  handler,
void *  subscribeData 
)

Subscribe to commissioning respones.

Parameters
[in]clientAWS IoT MQTT Client instance.
[in]requestIdUnique ID of a request.
[in]deviceTypeDevices's device type.
[in]physicalIdDevice's physical ID.
[in]handlerSubscription response handler.
[in]subscriberDataData blob to be passed to the subscription handler on invoke.
Returns
Zero on success, negative value otherwise

◆ subscribe_to_service_response()

IoT_Error_t subscribe_to_service_response ( AWS_IoT_Client *  client,
const char *  deviceId,
const char *  requestId,
pApplicationHandler_t  handler,
void *  subscribeData 
)

Subscribe to service responses.

Parameters
[in]clientAWS IoT MQTT Client instance.
[in]deviceIdDevice's ID.
[in]requestIdUnique ID of a request.
[in]handlerSubscription response handler.
[in]subscriberDataData blob to be passed to the subscription handler on invoke.
Returns
Zero on success, negative value otherwise

◆ tc_connect()

IoT_Error_t tc_connect ( AWS_IoT_Client *  client,
char *  clientId,
bool  autoReconnect 
)

Start MQTT connection to ThinCloud host.

Initialize an MQTT conenction to a thincloud host.

Parameters
[in]clientAWS IoT MQTT Client instance.
[in]clientIdAn unique ID for the client instance.
[in]autoReconnectSignals if the MQTT client should attempt to auto-reconnect after connection failures.
Returns
Zero on success, negative value otherwise

◆ tc_init()

IoT_Error_t tc_init ( AWS_IoT_Client *  client,
char *  hostAddr,
char *  rootCAPath,
char *  clientCRTPath,
char *  clientKeyPath,
iot_disconnect_handler  handler,
void *  disconnectData 
)

Initialize an AWS IoT Client.

Initialize an AWS IoT Client instance with ThinCloud specific parameters and defaults.

Parameters
[in]clientAWS IoT MQTT Client instance.
[in]hostAddrThinCloud host address.
[in]rootCAPathPath to a root CA.
[in]clientCRTPathPath to a client CRT.
[in]clientKeyPathPath to a client private key.
[in]handlerDisconnect handler.
[in]disconnectDataData blob to be passed to the disconnect handler on invoke.
Returns
Zero on success, negative value otherwise

Variable Documentation

◆ COMMAND_TOPIC_BUFFER

char COMMAND_TOPIC_BUFFER[MAX_TOPIC_LENGTH]

◆ COMMISSIONING_RESPONSE_TOPIC_BUFFER

char COMMISSIONING_RESPONSE_TOPIC_BUFFER[MAX_TOPIC_LENGTH]

◆ SERVICE_RESPONSE_TOPIC_BUFFER

char SERVICE_RESPONSE_TOPIC_BUFFER[MAX_TOPIC_LENGTH]