Skip to main content

Lesson 3.3 Node-RED

Node-RED is a low-code, flow-based tool for wiring together hardware, APIs and services. With the IoT platform it's used to simulate devices, integrate third-party systems, and as an SDK for building and testing translators. In this lesson you'll connect Node-RED to the IoT platform and push simulated data in.

The full guide is Node-RED; this lesson is the hands-on walkthrough.

Before you start

  • Node-RED installed (nodered.org).
  • Access to your server's Swagger UI (https://staging.yggio.net/swagger).
  • Network access from Node-RED to the IoT platform's MQTT broker and REST API. Keep Node-RED behind a firewall.

Node-RED example flow

Exercise 1 - Send one simulated reading (fastest first success)

  1. In Swagger, create a basicCredentialSet (a username/password for MQTT), then reserve one reservedMqttTopic of the form yggio/generic/v2/<your-unique-id>.
  2. In Node-RED, add an MQTT out node. Create an MQTT server pointing at the IoT platform's URL, with the basicCredentialSet username/password under Security, and set the topic to the one you reserved.
  3. Wire an inject node (payload = JSON {"temperature": 21}) into the MQTT out node and Deploy.
  4. In the IoT platform, a new device appears within a minute, showing temperature.

You've just pushed data into the IoT platform from Node-RED.

Exercise 2 - The full example flow

Import the ready-made example to see bidirectional MQTT plus the REST API:

  1. Import the example flow.
  2. Follow the setup in the Node-RED guide (the IoT platform: token, basicCredentialSet, 6 reserved topics; Node-RED: credentials and MQTT server). Deploy.
  3. Watch six simulated devices report into the IoT platform, a REST GET /iotnodes call run, and (after the final MQTT-channel step) data flow back out of the IoT platform.

Exercise 3 - Build a translator in Node-RED

Because Node-RED and the IoT platform share the same JavaScript engine, it's an ideal place to develop translators (see Lesson 3.7):

  1. Import the my-first-translator flow.
  2. It generates simulated data, runs a translate function, and prints the translator + spec to the console - ready to paste into the translator API.
  3. Remember: the output must use canonical field names, and the IoT platform's sandbox is narrower than Node-RED (no require, timers, network) - see the guide's caveats.

What you learned

  • How to connect Node-RED to the IoT platform over MQTT and simulate device data.
  • How the example flow demonstrates bidirectional MQTT + the REST API.
  • Why Node-RED is a strong translator SDK, and how it differs from the IoT platform's sandbox.

Where next