This page contains detailed information about the Azure IoT Hub service in the Tartabit IoT Bridge. This service lets you integrate LPWAN devices as devices in Azure HoT Hub. The Tartabit IoT Bridge acts as a proxy, when an action is executed on an Azure IoT service instance, the platform will connect to Azure IoT Hub. The connector can use DPS or a service connection to establish device connections
Connections to an Azure IoT Hub instance are managed at two levels:
The Azure IoT Hub service contains the information required to establish a service connection to Azure for the purpose of dynamically creating and retrieving device configurations.
ServiceAccount
or DPS
to select between which mechanism should be used to manage and create device connections to your IoT Hub.ServiceAccount
authentication, then you must supply a connection string from your Azure IoT Hub instance. The connection string requires The shared access policy must have Registry Read
, Registry Write
, Service Connect
, and Device Connect
permissions.DPS
authentication, then you need to supply the ID Scope associated with your DPS registration.DPS
authentication, then you need to supply the access key associated with a group enrollment in your DPS account.This event fires when a direct method is executed on a connected device. A common design paradigm is to filter the trigger by the method name. You can apply the filter by defining a custom rule method
==
mymethod
. Currently only an exact match is supported.
{
"payload":{
"key1":"abc",
"key2":456
},
"method":"mymethod",
"replyId":"alskdfjaawper"
}
This event fires whenever a cloud-to-device message is received.
{
"deviceId": "mydevice",
"data":{
"key1":"abc",
"key2":456
},
"properties":{
"prop1":"fast"
}
}
This event fires when twins are updated.
{
"deviceId": "mydevice",
"state": {
"field1": "abc",
"field2": "def"
}
}
Send telemetry data as a device to cloud message.
// Send telemetry message from 'mydevice'.
azure_iot.send('mydevice','mydevice', {"field1": "abc", "field2": 456})
// Send telemetry message from 'mydevice' with properties.
azure_iot.send('mydevice','mydevice', {"field1": "abc", "field2": 456}, {"prop1": "value"})
Retrieve the current state of a device twin.
// Update 'mydevice' twin with new data.
var twin = azure_iot.twin_retrieve('myservice', 'mydevice')
desired
and reported
containing objects with the relevelant twin properties.Send an update to the reported state of the device twin.
// Update 'mydevice' twin with new data.
azure_iot.twin_update('myservice', 'mydevice',{"field1":"abc123", "field2": "def456"})
Complete a direct method that was received for a device. This call must be invoked or the method will timeout on the server. A common pattern is to invoke this function within a trigger that handles the incoming method receiver.
// Reply to a method from within a trigger fired when a method is received.
azure_iot.method_complete('myservice', 'mydevice', event.data.replyId,{"replyField":"reply value"})
On 2021-02-25 the iot_hub.method_update() function signature was changed. It now requires 4 paremeters instead of 2, after the upgrade, your triggers will fail until you update your triggers to supply the new parameters. This fixes a problem with method replies being lost.
Use the service API to get the device definition from IoT Hub. Note this function does not work if using DPS.
// Get "mydevice" from IoT Hub
var dev = azure_iot.device_get('myservice', 'mydevice')
{
"authentication": {
"symmetricKey": {
"primaryKey": "<key>",
"secondaryKey": "<key>"
},
"type": "sas",
"x509Thumbprint": {
"primaryThumbprint": null,
"secondaryThumbprint": null
}
},
"capabilities": {
"iotEdge": false
},
"cloudToDeviceMessageCount": 0,
"connectionState": "Connected",
"connectionStateUpdatedTime": "2022-09-28T14:20:00.8680052Z",
"deviceId": "mydevice",
"etag": "NTE4MDc1NDc4",
"generationId": "637970416805287223",
"lastActivityTime": "0001-01-01T00:00:00Z",
"status": "enabled",
"statusReason": null,
"statusUpdatedTime": "0001-01-01T00:00:00Z"
}
Use the service API to set the desired twin properties and/or tags on a device. Note this function does not work if using DPS.
// Update 'mydevice' with desired twin properties and tags.
azure_iot.device_update('myservice', 'mydevice',{"field1":"abc123", "field2": "def456"}, {"tag1", "value1"})
// Update 'mydevice' with only desired twin properties.
azure_iot.device_update('myservice', 'mydevice',{"field1":"abc123", "field2": "def456"}, {"tag1", "value1"})
Use the service API to get the twin from IoT Hub using the service API. Note this function does not work if using DPS.
// Get "mydevice" from IoT Hub
var twin = azure_iot.twin_get('myservice', 'mydevice')
{
"authenticationType": "sas",
"capabilities": {
"iotEdge": false
},
"cloudToDeviceMessageCount": 0,
"connectionState": "Connected",
"deviceEtag": "NTE4MDc1NDc4",
"deviceId": "mydevice",
"etag": "AAAAAAAAAAI=",
"lastActivityTime": "0001-01-01T00:00:00Z",
"properties": {
"desired": {
},
"reported": {
}
},
"status": "enabled",
"statusUpdateTime": "0001-01-01T00:00:00Z",
"tags": {
"tag1": "foo"
},
"version": 7,
"x509Thumbprint": {
"primaryThumbprint": null,
"secondaryThumbprint": null
}
}
The following properties can be added on an azure_iot.send()
call to enrich the data for IoT Central.
var props = { mycomponent: { '__t': 'c', myprop: 'value'}}
The following events are considered billable:
The following events are NOT billable:
Once established, connections will automatically reconnect until the activity timer expires. This can create issues if you attempt to connect to IoT Hub using the same deviceId as the two will continue to compete for the connection.
On 2021-02-25 the iot_hub.method_update() function signature was changed. It now requires 4 paremeters instead of 2, after the upgrade, your triggers will fail until you update your triggers to supply the new parameters.