nRF24L01 Large network help needed


  • Hardware Contributor

    Good afternoon,

    At the moment what i have setup is a OpenHAB Controller running on a raspberry pi which is also running MQTT Broker (Mosquitto) and then two arduinos, 1 as a Action node to turn on and off lighting and the other arduino as a Sensor node keeping track of the state of a light switch connected to it as a pushbutton. Everything is working perfectly apart from a little 1 second time delay between pressing the lightswitch and the light coming on. Everything is communicating without fail using nRF24L01 modules.

    The question i would like some assistance with is, how many of these nodes can i have connected to the controller. I can see from the datasheet and some research work around the internet that these modules are 6 data pipe MultiCeivers. Does this literally mean i can only have 6 nRF24L01's talking to each other? If so, i would like to go down the route of having repeaters in my network, so my gateway/controller is talking to 4 repeating gateways, which in turn are then listening to another gateway each, then they are connected to the nodes themselves. Is this possible?

    My desired mapping would be as per the attached image.

    Now, my first instincts are to the use the RF24Mesh library link, now because i'm already running my MQTTController which uses node addresses to communicate with the other nodes, I think i need to make a 'hybrid' file consisting of the mosquitto communication side of MQTTController.cpp (that i'm using currently) and the addressing from the RF24Mesh file from the link.

    Hope someone can shed some light on this situation, thanks in advance, Sam.

    Untitled-2.jpg


  • Admin

    The MySensors library takes care of routing for you. It permits 254 nodes per gateway. And it uses two of the "pipes" on the NRF-radio.


  • Hardware Contributor

    If i remember correctly, it uses JS for the raspberry pi master, correct? What're the benefits of using JS over C++?


  • Admin

    NodeJS? You can choose from 18+ controllers including OpenHab. The serial protocol is pretty easy to parse from NodeJS or any other language.


  • Hardware Contributor

    As I'm doing this to learn C++ at the moment, i would prefer to be able to accomplish this through using the method i suggested if i could, however i understand that you would prefer to use node.js for this. It may be that i have no choice if i can't get this to work through using C++.



  • @samuel235 its easy in any language. With the serial protocol it's just a little bit splitting of strings.
    The "master" ("Controller" in MySensors speech) can be written in any language.

    As hek said you can choose from 18+ controllers including OpenHab (mentioned in your picture),
    or write your controller in any language you want.


  • Hardware Contributor

    @Oitzu said:

    @samuel235 its easy in any language. With the serial protocol it's just a little bit splitting of strings.
    The "master" ("Controller" in MySensors speech) can be written in any language.

    As hek said you can choose from 18+ controllers including OpenHab (mentioned in your picture),
    or write your controller in any language you want.

    I'm sorry but I'm completely lost now.... The moment you said "Serial protocol" it just went all over the place, what do you mean by the serial protocol?

    If i decided to use the mysensors libs how would my configuration look? Would i still have the controller (OpenHAB), Gateway and MQTT Broker all located on my raspberry pi or would i need a seperate gateway to then feed the MQTT broker that would be running on the raspberry pi?


  • Admin

    Please do read the documentation on www.mysensors.org.


  • Hardware Contributor

    I'll have to come back to it another day, I've been reading your guides about gateways all morning and they're simply making no sense to me at all any more >.<


  • Hardware Contributor

    There are nodes, repeaters, gateways and a controller in a Mysensors setup.

    Nodes have sensors or act as actuators. They can send radio messages to other nodes or to the controller. In the MySensors code you can define the destination.

    Repeaters in MySensors, are nodes that can receive radio messages and pass them on. They do not change the messages, just pass them on to the next repeater or the gateway or the destination node.
    In the latest versions of the MySensors library they can also have sensors or act as actuators. These repeaters need to be awake at all times to be able to function as repeaters. Nodes that sleep can not receive radio messages, so giving them a repeater function would not make sense.

    Gateways are devices sitting between nodes (sensors or actuators) / repeaters and a controller (any of the 18+ which now can understand the data sent by a MySensors gateway).

    Gateways in MySensors receive the radio messages, and translate those radio messages into a string per radio message and sends those strings to a controller over serial port or USB or over ethernet. The format of those translated messages is described in the documentation.

    Basically for each message (packet of bytes sent by the radio of the node) over the radionetwork addressed to the controller, the gateway would send a string to the controller. The controller can send a string to the gateway, which is then translated into a radio packet by the gateway and send to the appropriate node over the radionetwork.

    Address and payload of that packet are all defined in 1 string from controller sent to gateway.
    That is how I understood the "serial protocol".

    On a network you can have only 1 gateway per radio-channel. Since a gateway can handle 254 nodes, any need for more nodes, means using several gateways on a different radiochannel each. Some controllers are capable of handling several gateways in parallel. So the maximum size of your network depends on the controller used.


  • Hardware Contributor

    @GertSanders said:

    sends those strings to a controller over serial port or USB or over ethernet. The format of those translated messages is described in the documentation.

    This is the part that i was getting confused about. Now, i would like to keep my current structure of having the controller and gateway as the same machine, if possible, do you know if this is possible? At the moment my .cpp file is handling all the data coming in, sorting it to the correct structure and channels, then passing them over to the MQTT broker (Mosquitto) via the loopback address that i specify in the .cpp file. (127.0.0.1) through the following code:

    // Print some radio details (for debug purposes)
    	radio.printDetails();
    	
    	network.update();
    	
    	mosq.connect("127.0.0.1");
    	mosq.subscribe(0, action_channel1);
    	mosq.subscribe(0, action_channel2);
    

    So, essentially i have it complete now, i just need to be able to have more nodes on my network, and i fear that i may need to reprogram the whole of my controller/gateway machine for this.


  • Hardware Contributor

    @samuel235 It is certainly possible, I use PiSerialGateway on my Raspi. I have an nrf24l01+ directly connected to some GPIO pins. The PiSerialGateway software takes care of the gateway function and sends it's data to Domoticz running on the very same Raspi 2. I know nothing about MQTT so I can not help there. Just to prove it's possible: here is my gateway/controller in one:
    IMG_7301.jpg
    Hardware is simple, software does all the work.


  • Hardware Contributor

    Fantastic! Now, the only thing i want different is to use OpenHAB over Domoticz. And for that to work i just simply use the MQTT. I think the MQTT isnt that hard to sort out, the big struggle for me is in the radio communication.

    I have a feeling that with a little research on this site i might be able to see that openhab can use a serial connection. I will have a look now 🙂

    Thank you for going to the extent of an image, that brings back so much faith in my to complete this project now.


  • Hardware Contributor

    Does anyone happen to know where the MQTT gateway library/repo is for the RaspberryPi? I can't seem to find it anywhere, I've looked in the raspberrypi directory of the mysensors github, nothing there either. I have the arduino version, just not the raspberrypi one.


  • Mod

    Domoticz (which I run on my Raspberry Pi) uses mosquitto. Binary packages are available for at least the following platforms:
    Windows, Max, Arch Linux, CentOS, Fedora, FreeBSD, Gentoo, Mandriva, OpenSUSE, OpenWRT, Raspberry Pi (Raspbian), Redhat Enterprise Linux, Slackware, SUSE Linux Enterprise Server, Ubuntu, QNX, iOS. In Raspbian you can install it by running

    sudo apt-get install mosquitto
    

    The source for mosquitto is available here.

    Other mqtt implementations are also available, for example paho.


  • Hardware Contributor

    @mfalkvidd said:

    Domoticz (which I run on my Raspberry Pi) uses mosquitto. Binary packages are available for at least the following platforms:
    Windows, Max, Arch Linux, CentOS, Fedora, FreeBSD, Gentoo, Mandriva, OpenSUSE, OpenWRT, Raspberry Pi (Raspbian), Redhat Enterprise Linux, Slackware, SUSE Linux Enterprise Server, Ubuntu, QNX, iOS. In Raspbian you can install it by running

    sudo apt-get install mosquitto
    

    The source for mosquitto is available here.

    Other mqtt implementations are also available, for example paho.

    Sorry, i seems i confused you. I need the mysensors gateway file that communicates with the mosquitto program running on the pi.

    This, but for the Raspberry Pi, not arduino.


  • Hardware Contributor

    Would i be correct in saying that i need to modify this to use MQTT to pass the messages onto the MQTT program that i have running in the background?


  • Mod

    @samuel235 I developed a Perl implementation of a MySensors serial protocol to MQTT converter. You can find it here.
    I use it to connect to a MySensors ethernet gateway, but support is in for a serial gateway. Serial gateway support hasn't been tested by me, so there might be issues using it.
    Anyway, the converter (also called gateway to raise the confusion 😉 ) you can just run on your raspberry Pi. It connects to the MySensors gateway on one side and your MQTT broker (e.g. Mosquitto) on the other side.


  • Hardware Contributor

    @Yveaux At the moment i obviously have my MQTT broker running, OpenHAB running and my current 'method' of using MQTTController.cpp to read the RF network, grab the messages from the sensors and then convert them to the MQTT topics for OpenHAB to use, for example i have the MQTTController.cpp receiving a message of '1' or '0' and publishing it on a topic 'home/bedroom/lightswitch' and then OpenHAB converts the 1, 0 or - to a readable message (On, Off or Unavailable).

    Do you think that i could just implement mysensors gateway for the raspberry pi, then refer to it in OpenHAB using:

    mqtt:mysensor.url=tcp://localhost:1883
    mqtt:mysensor.clientId=MQTT
    

    The current config I'm using is:

    mqtt:mymosquitto.url=tcp://localhost:1883
    mqtt:mymosquitto.retain=true
    

    Is there any difference between the two apart from one is using mymosquitto and the other mysensor? Why is one using .retain=true and the other is using a clientId=MQTT?


  • Hardware Contributor

    @Yveaux From looking through the openhab.cfg file i have found the following information regarding the code for the binding:

    #######################################################################################
    #####                       Transport configurations                              #####
    #######################################################################################
    
    ################################# MQTT Transport ######################################
    #
    # Define your MQTT broker connections here for use in the MQTT Binding or MQTT
    # Persistence bundles. Replace <broker> with a id you choose.
    #
    
    # URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
    #mqtt:<broker>.url=tcp://<host>:1883
    
    # Optional. Client id (max 23 chars) to use when connecting to the broker.
    # If not provided a default one is generated.
    #mqtt:<broker>.clientId=<clientId>
    
    # Optional. User id to authenticate with the broker.
    # mqtt:<broker>.user=<user>
    
    # Optional. Password to authenticate with the broker.
    #mqtt:<broker>.pwd=<password>
    
    # Optional. Set the quality of service level for sending messages to this broker. 
    # Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2 
    # (Deliver exactly once). Defaults to 0.
    #mqtt:<broker>.qos=<qos>
    
    # Optional. True or false. Defines if the broker should retain the messages sent to
    # it. Defaults to false.
    #mqtt:<broker>.retain=<retain>
    
    # Optional. True or false. Defines if messages are published asynchronously or
    # synchronously. Defaults to true.
    #mqtt:<broker>.async=<async>
    
    # Optional. Defines the last will and testament that is sent when this client goes offline
    # Format: topic:message:qos:retained <br/>
    #mqtt:<broker>.lwt=<last will definition>
    

    So, from this it shows that the only part that i would need to specify is the URL to the MQTT broker, which i'm assuming that once i install the mysensor package onto my Pi i can then just call the localhost in this line like i currently doing so, nothing needs to be changed as the broker name is not relevant to anything. However because it has to match throughout all of the bindings and items i will just change it to mysensor for ease.

    I'm just stuck with how the controller reads the data from the sensors.... I need to modify or replace my MQTTController.cpp with a file from here that reads the radio communications...


  • Hardware Contributor

    Finally found the repo for what i think is the raspberry pi MQTT Gateway... Link, I'm assuming the file i need to be looking at is the MyGatewayTransportMQTTClient.cpp. However, there is no MakeFile there, am i being stupid or blind, how would i compile this gateway file to then be able to run it?


Log in to reply
 

Suggested Topics

  • 87
  • 9
  • 6
  • 2
  • 7
  • 10

1
Online

11.2k
Users

11.1k
Topics

112.5k
Posts