Sensors & IoT Stuff: Home Automation with NodeRed, RF24Ethernet/RF24Gateway & MQTT

Sensors & IoT Stuff: Home Automation with NodeRed, RF24Ethernet/RF24Gateway & MQTT 

Control a homemade, Arduino-based RGB light, other devices or display data using NodeRed

I made a video demonstrating how to configure NodeRed with RF24Ethernet/RF24Gateway to control a homemade, Arduino-based RGB light. The process is fairly straightforward, with the Arduino node subscribing to the MQTT server, and the NodeRed device publishing some RGB values. The same system can be used to send or receive data from a wide range of devices, thus enabling an nrf24l01 based home automation/IoT and/or monitoring system.

The video assumes users are already somewhat familiar with the RF24 communication stack, having the radios installed and ready to go. The sketch used in the video is very closely based on the existing RF24Ethernet MQTT examples, with some extra code to control some NeoPixel based lighting.

Note: As of mosquitto 2.0 you need to add  listener 1883 and  allow_anonymous true in /etc/mosquitto/mosquitto.conf.

With this setup, users can add simple input/output toggles, sliders and charts to manage devices and display incoming sensor data. It is just a matter of configuring the Arduino devices to handle the input/output messages to and from MQTT. NodeRed can also log incoming MQTT data to a database, to store and display historical data.

This system has the benefit of requiring no apps, so everything can be controlled from a mobile device or PC etc. with some simple button clicks. Everything used is also completely open-source and free, so setup costs are minimal, and there is a host of information available for Arduino and Raspberry Pi.


Zee said...

Hi!, I've tried to follow your video and have the IP setup in ncurses as, and the address as and so I have set the following:

IPAddress ip(10, 1, 3, 8);
IPAddress gateway(10, 1, 3, 134); //Specify the gateway in case different from server
IPAddress server(10, 1, 3, 134);

On my Arduino pro mini, the CE and CSN pins are connected to A7 and 10, so I have put this:
RF24 radio(PIN_A7, 10);

However, running mesh.begin() in the script always results in a "FAILED". Can you offer any advice/help on this please? I don't seem to have any issues running any of the RF24 examples.

TMRh20 said...

If mesh.begin() fails with RF24Gateway, but the other examples work, that usually indicates some sort of basic configuration error. If it works running the RF24Mesh examples with the RPi, I would suggest to check your pin assignments in the RF24Gateway example, (RF24 radio(22,0)) and make sure it is configured with the correct pins. The most likely cause of failure is the pin assignments or something simple like that.

If it fails using RF24Mesh, then test with RF24 gettingstarted example and again verify the correct pin assignments and wiring etc.

Zee said...

Thanks, I double checked with the example here:, and my NRF24L01 modules seem to be working.

My bad however as running the RF24Mesh example doesn't actually work. Sorry, I got confused with other examples earlier.

I've followed your video here to the letter, and running 'sudo ./RF24Gateway_ncursesInt' after uploading the "RF24Ethernet InteractiveServer example", I can't seem to connect to the Mesh (no new IPs listed under Mesh Info). There was initially a "wiringPiISR: Can't find gpio program" error that popped up in the qqqq part of the ncursesInt example program, which I think has stopped after I ran sudo apt install wiringpi.

I've commented the code with Serial.printlns and found that the loop repeats without triggering (EthernetClient client = server.available()), probably because there is no available server?

ifconfig lists tun_nrf24 with the correct ip (, netmask and the only other things setup on the pi is node-red and mosquitto, so I'm not sure why this is happening. If you have any other advice I could use to troubleshoot this that'll be great.

TMRh20 said...

If the arduino code works, its probably the pin assignments on the RPi. The RF24Gateway_ncursesInt uses an interrupt pin so it may be worthwhile to try using the RF24Gateway_ncurses example instead to minimize the failure points. See the pin assignments at the bottom of the page here:
I would test with the RF24 gettingstarted examples between the arduino and RPi as well.

Zee said...
This comment has been removed by the author.
Zee said...

Hi again. OK, I've tried the gettingstarted example on the Pi and its really weird.


1) Configuring pi:1, nano:0; 2) Pi: Receiving, Nano: Transmitting
I get the message 'Nothing received in 6 seconds. Leaving RX role.' on the Pi. Occasionally there is 'Received 4 bytes on pipe 1: 1.5' or so but nothing else.

2) Configuring pi:0, nano:1; 2) Pi: Transmitting, Nano: Receiving
On the Pi terminal it keeps saying '...Transmission failed or timed out. 6 failures detected. Leaving TX role.' BUT on the serial monitor end of the Nano, I constantly observe 'Received 4 bytes on pipe 1: 0.00'

Is it worthwhile for me transferring this conversation/topic over to Github as an issue BTW?

Screenshot here:

TMRh20 said...

It looks like it is working, just with spotty transmission. You will need better connectivity for the mesh to work properly.

It could have to do with your power supply or interference on the channel.
One thing to try could be using a different radio channel: mesh.begin(channelNumber);
I typically add a 10uF capacitor directly to the VCC and GND terminals of the radio, as well as scraping down the last bit of antenna trace to solder on a 3-4 inch piece of wire to use as an extra antenna.

All in all it looks like it is working.
BTW this is not a library issue, more like a hardware issue so opening a github issue is not preferred.

Zee said...

Thanks for your help - the 10uF across the V/G pins solved the connectivity issue and everything seems to be working now!

zhao yuan said...
This comment has been removed by the author.
zhao yuan said...

Hi I had a second go at this to try and get the MQTT working. So during mesh.begin(), OK only starts when RF24gateway.ncurses is running on the Pi.

Once I close this, I can't get mesh.begin() to work - it keeps saying "Failed".

Also, mosquitto/MQTT has been installed but for some reason the Arduino script is not connecting to MQTT.

The other examples from RF24Mesh works with no problem, and I can send values over fine. Not sure what is happening here?

Basically my settings are:
IPAddress ip(10, 10, 3, 103);
IPAddress gateway(10, 10, 3, 1); //Specify the gateway in case different from the server
IPAddress server(10, 10, 3, 1); //The ip of the MQTT server

My ifconfig reads:
tun_nrf24: flags=4241 mtu 1500
inet netmask destination
inet6 fe80::7bba:7f2b:6ac2:5415 prefixlen 64 scopeid 0x20
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 500 (UNSPEC)
RX packets 190 bytes 8336 (8.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 169 bytes 6792 (6.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wlan0: flags=4163 mtu 1500
inet netmask broadcast
inet6 fe80::2b35:9226:5c90:936d prefixlen 64 scopeid 0x20
ether b8:27:eb:a1:1b:2d txqueuelen 1000 (Ethernet)
RX packets 18011 bytes 1630610 (1.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 41841 bytes 16254721 (15.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

TMRh20 said...

@zhao yuan

Yes the Gateway needs to be running for the mesh nodes to be assigned an address.

The problem with MQTT may be that it just needs to be configured.
As of mosquitto v2.0 you need to add the following lines to /etc/mosquitto/mosquitto.conf :

listener 1883
allow_anonymous true

zhao yuan said...

Thanks, this did the job.

XIAO BLE SENSE: nrf52840 radio communication with nrf24L01+

XIAO BLE SENSE: nrf52840 radio communication with nrf24L01+ Establishing a communication layer using the RF24 API  I recently received an XI...