Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Latest commit

 

History

History
44 lines (26 loc) · 1.46 KB

node-red_lab_5.md

File metadata and controls

44 lines (26 loc) · 1.46 KB

Innovation-Day: Internet of Things - Node-RED Lab 5. Receive Cloud to Device messages

Add a new function node and set this code, it converts an array of bytes into a string:

msg.payload = 
 String.fromCharCode.apply(null, 
      new Uint16Array(msg.payload));
return msg;

Then connect the output of the Azure IoT Hub node you already have to the function and the function output to a debug node like this:

c2dmessages

Now from your command line you can send a message to your device:

iothub-explorer send EdisonNodeRed "Hello Node-RED"

You can see the messages sent to your device in the debug tab:

hello node-red

To make it more interesting, we will switch a light remotely, with the help of the recently created website.

Connecting a LED to manage it remotely

In Node-RED we will convert the string to an object again with the JSON node and a Change node that will move the information in the ledState property directly inside the payload when configured like this:

Message to LED

Connect at the end your blue LED and deploy it.

If you go to the site and set the name of the created device (EdisonNodeRed), you can send messages to the device from the website.

Remote Led

Get the full Flow that you can paste in Node-RED here.


Return to index.