Node-RED (IoT)


In this test setup both the MQTT Broker and the Node-Red are running as service on a Raspberry Pi V3 under Raspbian Stretch.
(For both the packages are in the standard Raspbian repository.)

Sample Flow 1


The MQTT node on the top left listens to Rocrail info messages, and shows them with help of a debug node on the right pane.
The two inject nodes on the left send at click a string to the function node in the middle. This function node tries to translate the string into a RCP XML message.
The MQTT node on the right receives the output from the function node and publish it at the MQTT broker.

Convert to RCP

The blue Inject nodes do write a string in the message payload at click.
The JavaScript in the function node convert those strings into RCP.

Sample Flow 2


The first flow is extended with email and RCP evaluation.
If an email comes in, with body text “power on”, this will be converted by the RCP function to a system command for global power on.
The MQTT messages are filtered and send by email.

Convert to RCP

This function is extended to support the email body text “power on”.

Evaluate RCP

The evaluation of RCP messages is done in two step:

  1. Use the standard Node-RED XML function which converts it into a JSON object.
  2. Evaluate the message and take action if needed.

Cookbook: Setup MQTT and Node-Red in Windows10 Environment

1. Install Visual C++ Redistributable für Visual Studio 2015

VC Redist

  • choose the 32bit (x86) Version - mandatory!

2. Install OpenSSL Rev. 1.0.2

Open SSL

  • choose the 32bit Version - mandatory!
  • Select Revision 1.0.2 to get the necessary DLL's for MQTT
  • Select the Option copy OpenSSL DLL's to the OpenSSL binaries directory

3. Install the Mosquitto Broker

Choose the Windows Installation Pack from here
(Example: mosquitto-1.4.14-install-win32.exe (~200 kB) (Native build, Windows Vista and up, built with Visual Studio Community 2015) as of 2018/01/08)
The first installation attempt fails, this is normal behaviour because some DLL are missing (see also prerequisites in readme.txt of MQTT)

  • copy the libeay32.dll and ssleay32.dll from the OpenSLL/bin directory to the now created mosquitto directory
  • get the pthreadVC2.dll from here and copy into mosquitto directory
  • then restart the mosquitto installation, should be successful now.
  • after successful installation go to windows –> Setup –> Services, select the mosquitto service and start it
  • after once started the service should be started in every windows session automatically
  • to check the mqtt service running: open a console and enter “netstat -an”, you should find a listener on Port 1883

4. Configure the MQTT Service in Rocrail

  • define MQTT Hostname “localhost” and Port “1883” when running MQTT on the same machine as Rocrail
  • “Group” must not selected

5.Install Node-Red

  • Follow the well documented instructions here (Quick Start Chapter 1-2)

Personal Tools