IMD SolutionComputing LibraryShop main store

How-to

Dynamically create IoT Central devices from Node-RED

Edge computing and IIoT Published 5 min read By IMD Solution engineering team

Short answer

A Node-RED device connector authenticates and publishes telemetry; it does not create device identities. Register one device manually, prove the connection end to end, then automate enrollment through Azure Device Provisioning Service or pre-registered device IDs with SAS keys, one identity per sensor.

On this page
  1. Pick the identity model before writing flows
  2. Install the device connector
  3. Prove one device end to end
  4. Add enrollment as its own flow stage
  5. Worked example: twelve sensors, per-sensor identities
  6. Keep secrets and failures contained
  7. Questions asked

A Node-RED connector can authenticate and publish telemetry to Azure IoT Central, but it cannot create device identities by itself. Split the job in two: an administrative path that authorizes an identity (an individual enrollment in Azure Device Provisioning Service, or a device ID and SAS key you register by hand) and a telemetry path where the device connection sends measurements. Prove one registered device end to end first, then automate enrollment for the rest of the fleet.

Pick the identity model before writing flows #

Decide what one IoT Central device represents. For a 900 MHz sensor fleet behind a Linux gateway you have three choices, and the choice fixes everything downstream: credential storage, connection count, and how operators find data in the application.

Model Cloud side Gateway side Choose when
Gateway is the device One identity carries all sensor data One credential set; each message carries the sensor ID Operators manage the gateway as the asset
One identity per sensor Each sensor has its own device record Gateway keeps a sensor-to-identity map and per-identity credentials Operators need a per-sensor inventory and lifecycle
Automated enrollment DPS creates identities on first connect Gateway detects an unknown sensor, requests enrollment, stores the result Sensors are added in the field without manual registration

For dynamic creation, the third row builds on the second: an authorized enrollment workflow creates the identity, then the device connection uses it.

Install the device connector #

Install node-red-contrib-azure-iot-device from the gateway's Node-RED palette manager, or with the package command in the Node-RED user directory:

npm install node-red-contrib-azure-iot-device

The node's documented configuration supports multiple attestation methods and provisioning against Azure IoT Hub and Azure IoT Central, including use as a transparent-gateway device. Check the package documentation for the attestation method you plan to use (SAS key or X.509) before committing a site design; if you go the certificate route, the steps in the X.509 certificate auth article for Azure IoT Hub over MQTT carry over directly.

Prove one device end to end #

Do not automate anything yet. Register one device in the IoT Central application, note its device ID and primary key, configure the node with those values, deploy, and confirm the connection status plus one received telemetry message against the device template. This single success separates connector and network problems from enrollment problems, which is the whole reason for doing it first.

Add enrollment as its own flow stage #

For dynamic creation, give the flow an enrollment stage that runs only when a sensor is unknown:

  1. Decode the incoming radio frame and reject anything without a stable sensor identifier.
  2. Look the identifier up in a persistent local store (a context store or a file the flow maintains). If it exists, skip to step 5.
  3. If it does not, run the authorized provisioning mechanism: an individual enrollment through the Device Provisioning Service using the scope ID and the sensor's derived key, or a device ID and key pre-registered in the IoT Central application.
  4. Store the returned identity, credential reference and expiry so a gateway restart does not re-enroll. Handle the already-exists case without creating duplicates.
  5. Connect with the stored credential and publish telemetry under that identity.

Keep the administrative credential out of the telemetry path. A compromised sensor input must not become an unrestricted provisioning request, and a model definition (DTDL, Plug and Play) describes telemetry shape but grants no permission to create identities. The pattern of authorizing each device with its own derived key is the same one fleet provisioning scales on; the MQTT fleet provisioning page walks through unique per-device keys.

Worked example: twelve sensors, per-sensor identities #

Assume one gateway and 12 sensors, each with a serial number. Give each sensor one IoT Central identity created through a DPS individual enrollment. The flow keeps a file with 12 entries; entry for sensor 7 holds the device ID derived from its serial and the stored credential reference from the enrollment result.

Count what changes at steady state: 12 identities, 12 stored credentials, and 12 connections if each sensor opens its own device connection, versus one identity, one credential and one connection if the gateway itself is the device. Provisioning traffic is bounded by new sensors only: adding sensor 13 costs one enrollment request, not a reconfiguration of the flow.

Issue each sensor's SAS token with an expiry that matches the gateway's reconnect cycle. For example, a 24-hour expiry works when the gateway refreshes credentials daily from the stored enrollment result; a site with week-long planned outages needs a longer expiry or a refresh step at startup, or every restart becomes a re-enrollment.

Keep secrets and failures contained #

Use the gateway's own credential storage for keys; never echo them to debug nodes or into exported flows. Bound the queue ahead of the device node so a cloud outage cannot fill gateway storage with pending messages. A fallback worth knowing when a sensor cannot authenticate: some connectors also connect devices straight to IoT Hub, so a site migrating off IoT Central can reuse the flow shape, as shown in the gateway selection article for publishing Modbus data to Azure IoT Hub.

The decision, per case: if operators treat the gateway as the asset, register the gateway once and carry sensor IDs in the payload. If operators need per-sensor inventory, use per-sensor identities with the enrollment stage above, proven first on one hand-registered device. Never attempt dynamic creation through a device connector alone; the enrollment path, DPS or pre-registered IDs, is the only supported way to make identities appear.

Questions asked

Why does installing node-red-contrib-azure-iot-device not create my devices in IoT Central?

The Azure IoT Device node is a device-side connection: it authenticates an identity that already exists or an enrollment that DPS already authorizes, then sends telemetry. Creating identities is an administrative action done through DPS enrollment or the IoT Central application itself. Treat the two as separate flows so a provisioning failure is not mistaken for a transport failure.

How long should a SAS key stay valid for a dynamically enrolled sensor?

Pick an expiry that matches how often the gateway can re-run provisioning, not a fixed rule. For example, issue tokens that expire in 24 hours and let the gateway refresh them from the DPS result at each reconnect. If a site takes the gateway offline for a week of maintenance, a one-day expiry turns every restart into a re-enrollment, so choose the value from the site's downtime pattern.

Can one gateway identity carry telemetry from all my sensors instead of one identity per sensor?

Yes, and it is simpler: the gateway authenticates once and tags each measurement with the sensor identifier in the payload. Use one identity per sensor only when operators need each sensor as a separate asset in the IoT Central inventory with its own lifecycle. The connection count and credential handling drop sharply with the single-gateway-identity model.

Keep reading

  • How-to

    Connect Node-RED on ctrlX CORE to a MySQL server

    Send the SQL as msg.topic to a node-red-node-mysql node: create the table once as an administrator, prove one INSERT and SELECT from Inject nodes, then route Read Datalayer values into a multi-row insert. Grant the runtime account only SELECT and INSERT on db1, match its host part to the client address the server reports, and keep a local snap's data directory on external media.

    Edge computing and IIoT

  • Troubleshooting

    Expose a serial port to Node-RED in a Docker container

    A serial device is reachable in a Node-RED Docker container only when it is mapped under devices at the same host path and the container process belongs to the group that owns that device on the host, usually dialout. Mapping without the group leaves the port visible but unopenable.

    Edge computing and IIoT

  • Troubleshooting

    Fixing X.509 certificate auth to Azure IoT Hub over MQTT

    The controller fails because the selected .key file is only half an X.509 credential: TLS client authentication must present the device certificate and its chain, so the key passes file validation and the handshake still has nothing to send. Convert the test certificates to PEM, import the leaf-plus-chain with its matching key as one pair, make the hub's device ID or thumbprint match, and verify with a real MQTT connection.

    Edge computing and IIoT

Docker OCI runtime create failed on SD card storage