AVNET's iotconnect.io cloud platform is an online service that you can use to send data to, and then show it on a dashboard*. In this blog series I'm learning how to talk to it with Node-RED. In this post: install the palette and test!. |
Install the Node-RED SDK
The iotconnect module for Node-RED has two components, a connection and a command inserter.
To install, navigate to the Node-RED install directory.
On a Linux machine, that's often the .node-red subdir of your home.
Then register to the iotconnect repo
$ npm adduser --registry https://repo.iotconnect.io/ $ username: <retrieve from https://help.iotconnect.io/documentation/sdk-reference/device-sdks-flavors/node-red/ > $ password: <retrieve from https://help.iotconnect.io/documentation/sdk-reference/device-sdks-flavors/node-red/ >
Enter an email address - I used the one from my iotnet.io subscription. AVNET informed me that if you have issues with the download account, you can reach out to https://knowledgebase.iotconnect.io/contact/
Then install the nodes:
$ npm install iotconnect-nodered-sdk --registry https://repo.iotconnect.io/
The nodes are added to your installation.
Connect for the first time
Start node-red and surf to the designer page.
Create a new flow, and place a connection:
You have to enter 3 attributes:
- CPID. This is the customer number on the Key Vault page. Do not share this
- Unique ID. Your device's unique ID as available on the Device page
- ENV. Selection box. Select the Environment that's shown in the key vault.
Deploy the flow. If you did everything correctly, the node shows it's connected.
The dot coloured green:
Celebrate.
First Data exchange
Let's send the first telemetry data to the iotconnect.io cloud.
Add an IotConnect Injecter node and fill in the JASON package:
[ { "uniqueId": "e14nodered1", "data": { "Temperature": "21" } } ]
The uniqueID is the same one you used when defining the connection.
The attribute has to be one that's registered in the template. We added Temperature.
I added a debug block at the end as part of the test, but that's not needed.
It shows the payload , if it's sent correctly to the cloud.
Press the Inject node's button. The message is sent to iotconnect.io:
Celebrate again.
In the next post: commands from the cloud.
This is the source code of my final flow.
You can import this in Node-RED by clicking the 3-bars icon in the right up corner of your Node-RED editor, then select import.
You will have to update cpID and uniqueID.
[ { "id":"df3bfead.a2439", "type":"tab", "label":"AVNET IotConnect e14", "disabled":false, "info":"" }, { "id":"e711923e.ef5d8", "type":"IoTConnect", "z":"df3bfead.a2439", "cpId":"USEYOURCPID", "uniqueId":"e14nodered1", "env":"PROD", "offlineStorageEnable":false, "sizeLimit":0, "fileCount":0, "isSecure":false, "sslKey":"", "sslCert":"", "sslCA":"", "x":635, "y":380, "wires":[ [ "77a78d77.1e42a4" ], [ "43b9c47.dc8b83c", "66d83cd3.f10e34" ], [ ] ], "l":false }, { "id":"3f1d5622.789b8a", "type":"IoTConnect-Injector", "z":"df3bfead.a2439", "iType":"SendData", "descText":"", "payload":"", "x":475, "y":380, "wires":[ [ "e711923e.ef5d8" ] ], "l":false }, { "id":"93b6ac97.e0525", "type":"inject", "z":"df3bfead.a2439", "name":"", "props":[ { "p":"payload" } ], "repeat":"", "crontab":"", "once":false, "onceDelay":0.1, "topic":"", "payload":"[{\"uniqueId\":\"e14nodered1\",\"data\":{\"Temperature\":\"-1\"}}]", "payloadType":"json", "x":175, "y":380, "wires":[ [ "3f1d5622.789b8a" ] ], "l":false }, { "id":"80319059.b447a", "type":"random", "z":"df3bfead.a2439", "name":"random temperature", "low":"-10", "high":"65", "inte":"true", "property":"payload[0].data.Temperature", "x":235, "y":420, "wires":[ [ "3f1d5622.789b8a" ] ], "l":false }, { "id":"358a344c.e4788c", "type":"inject", "z":"df3bfead.a2439", "name":"", "props":[ { "p":"payload" } ], "repeat":"300", "crontab":"", "once":true, "onceDelay":0.1, "topic":"", "payload":"[{\"uniqueId\":\"e14nodered1\",\"data\":{\"Temperature\":\"0\"}}]", "payloadType":"json", "x":175, "y":420, "wires":[ [ "80319059.b447a" ] ], "l":false }, { "id":"da5174df.fac2b8", "type":"comment", "z":"df3bfead.a2439", "name":"iotconnect.io \\n send", "info":"", "x":510, "y":320, "wires":[ ] }, { "id":"a38ec099.0860e", "type":"comment", "z":"df3bfead.a2439", "name":"iotconnect.io \\n communicate", "info":"", "x":690, "y":320, "wires":[ ] }, { "id":"de5e0d4f.24ad8", "type":"comment", "z":"df3bfead.a2439", "name":"temperature", "info":"", "x":210, "y":340, "wires":[ ] }, { "id":"fa433c1a.1f67a", "type":"IoTConnect-Injector", "z":"df3bfead.a2439", "iType":"SendCommandAck", "descText":"", "payload":"", "x":715, "y":460, "wires":[ [ "e711923e.ef5d8" ] ], "l":false }, { "id":"43b9c47.dc8b83c", "type":"switch", "z":"df3bfead.a2439", "name":"ACK?", "property":"payload.ack", "propertyType":"msg", "rules":[ { "t":"true" }, { "t":"false" } ], "checkall":"false", "repair":false, "outputs":2, "x":610, "y":460, "wires":[ [ "fa433c1a.1f67a" ], [ ] ] }, { "id":"c8d6826d.93e39", "type":"comment", "z":"df3bfead.a2439", "name":"receipt mgt", "info":"", "x":640, "y":500, "wires":[ ] }, { "id":"77a78d77.1e42a4", "type":"debug", "z":"df3bfead.a2439", "name":"", "active":true, "tosidebar":true, "console":false, "tostatus":false, "complete":"true", "targetType":"full", "statusVal":"", "statusType":"auto", "x":915, "y":380, "wires":[ ], "icon":"font-awesome/fa-bug", "l":false }, { "id":"ecf3a6a7.18f888", "type":"comment", "z":"df3bfead.a2439", "name":"iotconnect.io \\n receive", "info":"", "x":930, "y":320, "wires":[ ] }, { "id":"66d83cd3.f10e34", "type":"debug", "z":"df3bfead.a2439", "name":"", "active":false, "tosidebar":true, "console":false, "tostatus":false, "complete":"true", "targetType":"full", "statusVal":"", "statusType":"auto", "x":735, "y":400, "wires":[ ], "icon":"font-awesome/fa-bug", "l":false } ]
Top Comments