Azure IoT Hub is the Microsoft cloud service that connects, monitors and manages IoT devices. The Weble IoT Universal Gateway Azure driver connects the box to an IoT Hub as one device: it publishes gateway values as device-to-cloud (D2C) telemetry, receives cloud-to-device (C2D) messages and mirrors the device twin.
The driver works in three directions over a single connection:
%azure:out) is sent to the hub as one D2C message. Typical use: route meter, BACnet or Modbus values to Azure.%azure:telemetry_in. Typical use: send commands from a cloud application and route them to field addresses.%azure:twin/properties/desired, and the box can update the reported properties.Driver key:
azure— listed as Azure under IoT in Gateway driver. Licence: required, contact support@weble.ch. Platforms: Linux and Windows.
HostName=<hub>.azure-devices.net;DeviceId=<id>;SharedAccessKey=<key>.HostName=…;SharedAccessKeyName=iothubowner;…).<hub>.azure-devices.net on the port of the chosen Protocol (see 2). No inbound port is needed.MQTT over WebSocket (port 443) unless your network allows another port.%azure:twin, %azure:telemetry_out and %azure:telemetry_in.out after the %azure: prefix and keep the default options.%azure:out.{"out": 21.5}. The message also appears on %azure:telemetry_out, with its body, its properties and the send date. In Azure, check the incoming messages with the IoT Hub tools (for example Azure IoT Explorer or az iot hub monitor-events).
Name, Cluster ID and Description are common to all drivers: see Gateways.
| Label | JSON key | Default | Description |
|---|---|---|---|
| Connection string | json.connectionString |
(empty) | Device connection string of the IoT Hub: HostName=<hub>.azure-devices.net;DeviceId=<id>;SharedAccessKey=<key>. Required: when it is empty the driver logs missing required gateway config field 'connectionString' and cannot connect. |
| Protocol | json.protocol |
mqtt ws |
Transport to the hub. mqtt ws = MQTT over WebSocket (port 443), mqtt tcp = MQTT (port 8883), amqp = AMQP (port 5671), amqp ws = AMQP over WebSocket (port 443), http = HTTPS (port 443). Gateways created before this choice existed may show mqtt (legacy value): it is the same transport as mqtt ws. |
Saving the gateway restarts the driver, so a new connection string or protocol takes effect immediately.
Choose the protocol according to the firewall of the site: the three port 443 transports pass most corporate firewalls; MQTT (port 8883) and AMQP (port 5671) need these ports open towards
*.azure-devices.net.
{
"connectionString": "HostName=myhub.azure-devices.net;DeviceId=wbox-01;SharedAccessKey=<key>",
"protocol": "mqtt ws"
}
%azure:<name>[/<key>[/<key>…]] — <name> is a root address, each /<key> a key of its JSON value.
| Address | Created by | Role |
|---|---|---|
%azure:<name> |
you | Root address. Each write is sent to the hub as one D2C message. |
%azure:<name>/<key> |
the driver, or you | Child of a root address, one per key of its JSON value. Writing a child updates that key of the parent and sends the parent. |
%azure:telemetry_out |
the driver | Last message sent: { "body": …, "properties": …, "date": … }. Read only. |
%azure:telemetry_in |
the driver | Last C2D message received, same format. Read only. Children (telemetry_in/body/…) are created for the keys of the message. |
%azure:twin |
the driver | Copy of the device twin. Read only, except the reported properties. |
%azure:twin/properties/desired/… |
the driver | Desired properties set in the cloud. Read only. |
%azure:twin/properties/reported/… |
the driver, or you | Reported properties. Writable (except $version): a write sends a reported-property update to the hub. |
%azure:file_upload |
the driver | File upload to the storage linked to the hub. Created only when the upload function is available on the box; its value reports the result of the last upload. |
Examples:
%azure:out — root address; writing 21.5 sends {"out": 21.5}.%azure:building with the value {"temp": 21.5, "co2": 640} — the driver creates %azure:building/temp and %azure:building/co2; writing 22 to %azure:building/temp sends {"building": {"temp": 22, "co2": 640}}.%azure:twin/properties/reported/firmware — writing "9.1" reports firmware: "9.1" in the device twin.The options apply to root addresses. The form hides them on children.
| Label | JSON key | Default | Description |
|---|---|---|---|
| Repeat delay (ms) | json.delay |
0 |
0: a message is sent each time the value changes. Above 0: the value is sent again every n ms, and the changes that occur within the period are grouped into one message. The repeated sending starts when the gateway connects. |
| Extend | json.jsonExtend |
true |
Checked: a written object is merged into the current value instead of replacing it, and the send waits 100 ms so that writes to several children at the same time are grouped into one message. |
| Name in body | json.nameInBody |
true |
Checked: the message body is {"<name>": <value>}. Unchecked: the value is sent as it is. |
| Allow duplicate | json.allowSameValue |
false |
Checked: a write is sent even if the value has not changed. Unchecked: an identical value is not sent. |
| No children | json.noSubAddresses |
false |
Checked: the driver does not create child addresses for the keys of the value. Also offered on %azure:telemetry_in and %azure:telemetry_out (and their /body), to avoid one address per key of large messages. |
| Description | description |
(empty) | Free text. |
The Azure address form has no Log or Store value field.
| Property | Value |
|---|---|
| Readable | No — the driver keeps the last value; nothing is read from the hub on demand |
| Writable | Root addresses and their children, %azure:twin/properties/reported/…, %azure:file_upload |
| Created automatically | Yes — twin, telemetry_in, telemetry_out, file_upload at start, and children from the keys of JSON values |
| Routable | Yes |
| Loggable | Yes |
A write to a root address (or one of its children) builds one message:
application/json, UTF-8), wrapped in {"<name>": …} when Name in body is checked;properties key, its entries become message properties (an IoT Hub can route on them without reading the body), and properties is removed from the body.Example: writing {"temp": 21.5, "properties": {"site": "geneva"}} to %azure:room1 sends the body {"room1": {"temp": 21.5}} with the property site=geneva.
Each sent message is copied to %azure:telemetry_out.
C2D messages are accepted (completed) as soon as they arrive. A JSON body is decoded, otherwise it is kept as text. The message appears on %azure:telemetry_in as { "body": …, "properties": { … }, "date": "…" }, and each key of the body gets a child address, for example %azure:telemetry_in/body/setpoint. Route these children to field addresses to act on commands from the cloud.
A direct method named reboot called on the device restarts the driver.
At connection, the driver reads the twin and publishes it on %azure:twin, with one child per property. When the cloud changes a desired property, the new value appears under %azure:twin/properties/desired/….
To report a value, write it to %azure:twin/properties/reported/<key> (create the address if it does not exist yet). Deleting a reported child address removes that property from the twin in the hub.
Deleting an address of this driver is not neutral: on a reported twin property it removes the property in the hub, and on a child of a root address (with Extend checked) it removes the key from the next messages.
The API driver page gives a complete example: commands from Azure routed to the box API, replies and subscriptions sent back to Azure, with the routes to create.
| Address | JSON | Purpose |
|---|---|---|
%azure:energy |
{ "delay": 900000, "jsonExtend": true, "nameInBody": true } |
Root address, sent every 15 min with the latest values |
%azure:energy/main_kWh |
Routed from the main meter | |
%azure:energy/pv_kWh |
Routed from the PV meter |
Every 15 minutes the hub receives {"energy": {"main_kWh": …, "pv_kWh": …}} with the latest values.
| Symptom | Cause | What to do |
|---|---|---|
Gateway restarts in a loop; log missing license |
No licence for the driver. | Add the licence in Gateways › License manager. |
Log missing required gateway config field 'connectionString' |
Connection string is empty. | Paste the device connection string. |
Log client open failed: … or Could not open IotHub client |
Wrong connection string (hub name, device ID, key), device disabled in the hub, or port blocked. | Check the string in the Azure portal, check that the device is enabled, try a port 443 protocol. |
Log client disconnected - restarting driver |
The connection to the hub was lost. | Normal recovery: the driver restarts and reconnects. If it happens often, check the Internet link and the hub quotas. |
Log timeout after 30s waiting for device twin - restarting driver |
The hub did not return the device twin. | Check the hub status and try another Protocol. |
| No message in the hub | The value did not change, or the address is not a root address. | Check Allow duplicate, Repeat delay (ms) and that the route writes to a root address or one of its children. |
To read the driver log: open the gateway log (see Gateways). The log shows starting client - protocol = … at start and device twin acquired - client connected and operational once connected.
Keep this gateway on Cluster ID
0: the driver restarts its process when the connection to the hub is lost, which would restart every gateway of a shared cluster.