ThinCloud Embedded C SDK
|
#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] |
#define MAX_TOPIC_LENGTH 257 |
AWS IoT Max Topic Length plus null character
#define REQUEST_METHOD_DELETE "DELETE" |
#define REQUEST_METHOD_GET "GET" |
#define REQUEST_METHOD_POST "POST" |
#define REQUEST_METHOD_PUT "PUT" |
#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 |
UUID standard length plus null character
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.
[out] | requestId | ID of the original request. |
[out] | method | Command method. |
[out] | params | Command request parameters. |
[in] | payload | Response payload. |
[in] | payloadLen | Reponse payload's length. |
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"
[out] | buffer | Pointer to a string buffer to write to. |
[in] | deviceId | Device's ID. |
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.
[out] | buffer | Pointer to a string buffer to write to. |
[in] | requestId | Command request's ID. |
[in] | statusCode | Command's response status. |
[in] | isErrorResponse | Signals if a command responds with an error. |
[in] | errorMessage | Response error message. Only used if isErrorResponse is set to true. |
[in] | body | Command response body. |
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"
[out] | buffer | Pointer to a string buffer to write to. |
[in] | deviceId | Devices's ID. |
[in] | commandId | Command request's ID. |
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"
[out] | buffer | Pointer to a string buffer to write to. |
[in] | deviceType | Devices's device type. |
[in] | physicalId | Device's physical ID. |
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"
[out] | buffer | Pointer to a string buffer to write to. |
[in] | deviceType | Devices's device type. |
[in] | physicalId | Device's physical ID. |
[in] | requestId | Unique ID for the 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.
[out] | buffer | Pointer to a string buffer to write to |
[in] | requestId | Unique ID for the request |
[in] | deviceType | Requesting device's type |
[in] | physicalId | Device's physical ID |
[in] | relatedDeviceIds | List of devices to associate on commissioning |
[in] | idsSize | Size of related device ids list |
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.
[out] | deviceId | Assigned device ID. |
[out] | statusCode | Commissioning status. |
[out] | requestId | ID of the original request. |
[in] | payload | Response payload. |
[in] | payloadLen | Reponse payload's length. |
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.
[in] | client | AWS IoT MQTT Client instance. |
[in] | deviceId | Device's ID. |
[in] | commandId | ID of the requested command. |
[in] | statusCode | Command's status code. |
[in] | isErrorResponse | Signals if a command responds with an error. |
[in] | errorMessage | Response error message. Only used if isErrorResponse is set to true. |
[in] | body | Command response body. |
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.
[in] | client | AWS IoT MQTT Client instance. |
[in] | requestId | Unique ID for the request. |
[in] | deviceType | Devices's device type. |
[in] | physicalId | Device's physical ID. |
[in] | relatedDeviceIds | List of devices to associate on commissioning |
[in] | idsSize | Size of related device ids list |
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.
[in] | client | AWS IoT MQTT Client instance. |
[in] | requestId | Unique ID for the request. |
[in] | deviceId | Devices's ID. |
[in] | method | Service method to request. |
[in] | params | Service request parameters. |
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.
[out] | buffer | Pointer to a string buffer to write to. |
[in] | requestId | Unique ID for the request. |
[in] | method | Service method to request. |
[in] | params | Service request parameters. |
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"
[out] | buffer | Pointer to a string buffer to write to. |
[in] | deviceId | Devices's ID. |
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.
[out] | requestId | Request ID of the original request. |
[out] | statusCode | Request's status. |
[out] | data | Response's data. |
[in] | payload | Response payload. |
[in] | payloadLen | Reponse payload's length. |
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"
[out] | buffer | Pointer to a string buffer to write to. |
[in] | deviceId | Devices's ID. |
[in] | requestId | Request's ID. |
IoT_Error_t subscribe_to_command_request | ( | AWS_IoT_Client * | client, |
const char * | deviceId, | ||
pApplicationHandler_t | handler, | ||
void * | subscribeData | ||
) |
Subscribe to command requests.
[in] | client | AWS IoT MQTT Client instance. |
[in] | deviceId | Device's ID. |
[in] | handler | Subscription response handler. |
[in] | subscriberData | Data blob to be passed to the subscription handler on invoke. |
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.
[in] | client | AWS IoT MQTT Client instance. |
[in] | requestId | Unique ID of a request. |
[in] | deviceType | Devices's device type. |
[in] | physicalId | Device's physical ID. |
[in] | handler | Subscription response handler. |
[in] | subscriberData | Data blob to be passed to the subscription handler on invoke. |
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.
[in] | client | AWS IoT MQTT Client instance. |
[in] | deviceId | Device's ID. |
[in] | requestId | Unique ID of a request. |
[in] | handler | Subscription response handler. |
[in] | subscriberData | Data blob to be passed to the subscription handler on invoke. |
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.
[in] | client | AWS IoT MQTT Client instance. |
[in] | clientId | An unique ID for the client instance. |
[in] | autoReconnect | Signals if the MQTT client should attempt to auto-reconnect after connection failures. |
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.
[in] | client | AWS IoT MQTT Client instance. |
[in] | hostAddr | ThinCloud host address. |
[in] | rootCAPath | Path to a root CA. |
[in] | clientCRTPath | Path to a client CRT. |
[in] | clientKeyPath | Path to a client private key. |
[in] | handler | Disconnect handler. |
[in] | disconnectData | Data blob to be passed to the disconnect handler on invoke. |
char COMMAND_TOPIC_BUFFER[MAX_TOPIC_LENGTH] |
char COMMISSIONING_RESPONSE_TOPIC_BUFFER[MAX_TOPIC_LENGTH] |
char SERVICE_RESPONSE_TOPIC_BUFFER[MAX_TOPIC_LENGTH] |