Skip to content

Latest commit

 

History

History
45 lines (27 loc) · 1.53 KB

File metadata and controls

45 lines (27 loc) · 1.53 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 <device_ID> "Hello Node-RED"

You might need to login again with IoTHub-Exporer if your session has expired.

Inmediately, you will see the message 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 your device, 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.