Azure IoT Shunya API

Azure IoT#

Azure configuration in Shunya#

ConfigDescription
IoT Hub nameAzure IoT hub name where your device is registered.
PortAzure connection port, usually it is 443, 8883 incase 443 is blocked by company proxy.
Device IdAzure IoT device ID
SAS TokenSAS Token for the device generated from the Azure portal.
Root CA certificateAzure provides you with the Root CA certificate. Used for secure communication with Azure.

The configurations need to be set manually by the user before using the API's

For example:

A sample JSON snippet should contain

"azure": {
"azureIotHubName": "azure-iot-hub-name",
"azureIotPort": 8883,
"azureIotDeviceId": "azure-iot-device-id-here",
"azureIotSASToken": "azure-iot-sas-token",
"azureIotRootCA" : "azure-iot-root-certificate"
},

Commonly configured parameters#

For example:

A typical configuration will look like this

"azure": {
"azureIotHubName": "test-rpi",
"azureIotPort": 8883,
"azureIotDeviceId": "rpi-test",
"azureIotSASToken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"azureIotRootCA" : "AzureIoTBalitmore.pem"
},

Azure API#

APIDescriptionDetails
newAzure()Creates a new Azure InstanceRead More
azureConnectMqtt()Connects to the Azure IoT CloudRead More
azurePublishMqtt()Publishes to the given TopicRead More
azureSetSubCallbackMqtt()Set subscribe callback functionRead More
azureDisconnectMqtt()Subscribes to the given TopicRead More

newAzure()#

Description : Creates a new Azure Instance

Parameters

  • name (char *) - Name of the JSON object.

Return-type : azureObj

Returns : azureObj Instance for Azure

Usage :

For example: Lets say your /etc/shunya/config.json JSON file looks like

"azure1": {
"azureIotHubName": "test-rpi",
"azureIotPort": 8883,
"azureIotDeviceId": "rpi-test",
"azureIotSASToken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"azureIotRootCA" : "AzureIoTBalitmore.pem"
},

So the usage of the API's will be

azureObj azureAccount1 = newAzure("azure1");

azureConnectMqtt()#

Description : Connects to the Azure IoT Cloud.

Parameters

  • *obj(azureObj) - Pointer to the Azure Instance.

Return-type : int32_t

Returns : Azure Status Code on ERROR or SUCCESS

Usage :

/* Load settings and then connect to Azure */
azureObj azureAccount1 = newAzure("azureAccount1");
azureConnectMqtt(&azureAccount1);

azurePublishMqtt()#

Description : Publishes to the given Topic

Parameters

  • *obj(azureObj) - Pointer to the Azure Instance.
  • topic (char *) - MQTT Topic to publish.
  • msg (char *) - Message that needs to be published.

Return-type : int32_t

Returns : Azure Status Code on ERROR or SUCCESS

Usage :

/* Load settings and then connect to Azure */
azureObj azureAccount1 = newAzure("azureAccount1");
azureConnectMqtt(&azureAccount1);
azurePublishMqtt(&azureAccount1, "topic", "Send this message");

azureSetSubCallbackMqtt()#

Description: Set the subscribe callback function that executes the when the topic subscribed gets a message.

The Callback function arguments need to be in the specified format,

void callback(int topicLen, char *topic, int msgLen, char *message)

This format is used to pass the message received to the callback function.

Parameters

  • *obj(azureObj) - Pointer to the Azure Instance.
  • callback (void *) - A callback function that will get called when the subscribed topic gets a message

Return-type : int32_t

Returns : Azure Status Code on ERROR or SUCCESS

Usage :

/* Load settings and then connect to Azure */
azureObj azureAccount1 = newAzure("azureAccount1");
void callback(int topicLen, char *topic, int msgLen, char *message)
{
printf("Received Message is: %s", message);
}
azureSetSubCallbackMqtt(&azureAccount1, callback);

azureDisconnectMqtt()#

Description: Disconnects the Azure MQTT Broker.

Parameters:

  • *obj(azureObj) - Pointer to the Azure Instance.

Return-type : void

Usage :

azureDisconnectMqtt(&azureAccount1);