Processing commands that interact with LEDs in Node.js
Now that we have coded the web application that will allow the user to change the colors of the three LEDs, we will write the Node.js code that will control the LEDs wired to the IoT board. We can run the Node.js code in any computer or IoT board capable of running Node.js version 6.9.x or higher.
For this example, we have specified in the requirements that the LEDs would be wired to the following IoT boards: Intel Edison, Intel Joule 550x, Intel Joule 570x, and Raspberry Pi 3 boards. All of these boards can have Node.js installed and run the sample code. However, we can also run the code on many other IoT boards.
MQTT.js is an open source library that allows us to work with MQTT over WebSockets and direct MQTT with Node.js. The library is very easy to use and will allow us to process the received messages and publish the results by writing just a few lines of code. The web page for the MQTT.js library is http://www.npmjs.com.
Make sure...