AIoThings Connector

Connect to AIoThings and let AIoThings find the device.


This flow is used to connect to AIoThings (https://www.aiothings.com) cloud services from an IoT edge device.

Why we need this flow.

  • AIoThings uses MQTT protocol to communicate with its edge devices.
  • AIoThings uses a simple set of handshake MQTT messages to check the status of its edge devices.
  • This flow defines the example MQTT nodes and the handshake messages of AIoThings connectivity.

Prerequisite

Create a Thing Object from AIoThings.

A Thing includes a set of certificates and public/private keys that are required by this flow in the following steps.

How to configure this flow.

  1. Log-in to the Node-RED editor (of the edge device) from your browser.
  2. Put this flow to the Node-RED workspace of your edge device.
  3. Download Certificates and Keys from AIoThings Thing Object to the workstation running your browser.
  4. There are two MQTT nodes inside the flow. One for subscribing messages, and One for publishing messages.
  5. Edit either one of the MQTT nodes,
    1. Click the Server Edit button to configure MQTT server.
    2. Edit TLS Configuration, to load Certificate and Private Key from your files downloaded from AIoThings at the step [3]
    3. Set Client ID to your Thing Object's Thing ID.
  6. Replace ThingId part of the MQTT Topic to your Thing ID for both MQTT nodes in use.
  7. Deploy this flow.

MQTT topics for user domain messages

For user applications running in Node-RED to communicate with other AIoThings microservices, their MQTT message topics must comply to the following format:

aiot/{User ID}/{input or output topics defined in AIoThings microservices}
[{"id":"1799663a.4ff55a","type":"inject","z":"b0b895e4.1d37a8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":149.5,"y":120,"wires":[["82257007.3539e"]]},{"id":"2821e6f1.5f146a","type":"mqtt in","z":"b0b895e4.1d37a8","name":"AIoT Alive Request","topic":"aiot/ThingId/alive/req","qos":"1","datatype":"auto","broker":"e1e04bb1.5c7ac8","x":200.5,"y":204,"wires":[["1908efee.4ff99","82257007.3539e"]]},{"id":"1908efee.4ff99","type":"debug","z":"b0b895e4.1d37a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":521.5,"y":139,"wires":[]},{"id":"db3b8abd.cc0fa8","type":"mqtt out","z":"b0b895e4.1d37a8","name":"AIoT Alive Response","topic":"aiot/ThingId/alive/resp","qos":"1","retain":"","broker":"e1e04bb1.5c7ac8","x":420.5,"y":357,"wires":[]},{"id":"87a1451.4a04cb8","type":"function","z":"b0b895e4.1d37a8","name":"Send IP","func":"msg.payload = { \"hostIp\" : \"1.2.3.4\" }\nreturn msg;","outputs":1,"noerr":0,"x":190.5,"y":327,"wires":[["db3b8abd.cc0fa8","1908efee.4ff99"]]},{"id":"82257007.3539e","type":"exec","z":"b0b895e4.1d37a8","command":"curl ipecho.net/plain; echo","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":365.5,"y":53.5,"wires":[["2c5f39bd.9e8f76"],[],[]]},{"id":"2c5f39bd.9e8f76","type":"function","z":"b0b895e4.1d37a8","name":"Send IP","func":"let ipAddr = msg.payload\nipAddr = ipAddr.replace(/(\\r\\n|\\n|\\r)/gm, \"\");\nmsg.payload = { \"hostIp\" : ipAddr }\nreturn msg;","outputs":1,"noerr":0,"x":596,"y":54,"wires":[["1908efee.4ff99","db3b8abd.cc0fa8"]]},{"id":"e1e04bb1.5c7ac8","type":"mqtt-broker","z":"","name":"","broker":"iot.aiothings.com","port":"8883","tls":"bc082ee2.b3137","clientid":"ThingId","usetls":true,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"bc082ee2.b3137","type":"tls-config","z":"","name":"","cert":"","key":"","ca":"","certname":"aiot-ThingId-certificate.crt","keyname":"aiot-ThingId-private.key","caname":"aiot-root-CA.crt","servername":"","verifyservercert":false}]

Flow Info

Created 7 years, 7 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • exec (x1)
  • function (x2)
  • inject (x1)
  • mqtt in (x1)
  • mqtt out (x1)
  • mqtt-broker (x1)
  • tls-config (x1)

Tags

  • aiothings
  • mqtt
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option