nRF24L01+ MQTT



  • Hi there,

    I am working on a project with a Standalone ATmega328P-PU and a nRF24L01+-module which should communicate with a Wemos D1 mini with an attached nRF24L01+. The Wemos works as a Gateway and should transfer the messages to my MQTT broker. I now hooked up everything and loaded the sketches on the Wemos and the standalone ATmega. But sadly the standalone ATmega sends empty messages and turns down every 10 seconds for 10 seconds. When I use the same sketch on an Arduino Uno instead of the standalone ATmega, everything works fine. Also I am able to communicate with the standalone ATmega and the nRF-module if I use another library (RF24.h). But sadly this library doesnt support MQTT.

    Did anybody have same issues? I mean it is very suspicious, that the module turns down every 10 seconds for 10 seconds long...

    Thank,
    TimDe



  • hmm, maybe it is restarting every 10 seconds ?


  • Hardware Contributor

    Hello,

    It will be difficult to help you without sketch and wiring of the problematic node, can you post them (or at least explain for the Iring, tell us what you use as power source etc)



  • you are right, Nca78.

    So here is my sketch of the sender

    #include <SPI.h>
    
    #define MY_RADIO_NRF24
    
    #include <MySensors.h>
    int Payload;
    
    #define CHILD_ID 2
    
    MyMessage msg(CHILD_ID, V_TRIPPED);
    
    void setup()
    {
    }
    
    void presentation()
    {
    }
    
    void loop()
    {
      Payload = Payload+2;
      send(msg.set(Payload));
      delay(2000);
    }
    

    and here is the sketch of the recheiver:

    #define MY_DEBUG
    #define MY_RADIO_NRF24
    
    #define MY_GATEWAY_MQTT_CLIENT
    #define MY_GATEWAY_ESP8266
    
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "nRFGateway-Publish"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "nRFGateway-Subscribe"
    
    #define MY_MQTT_CLIENT_ID "mysensors-1"
    
    // Enable these if your MQTT broker requires usenrame/password
    //#define MY_MQTT_USER "username"
    //#define MY_MQTT_PASSWORD "password"
    
    #define MY_ESP8266_SSID "..."
    #define MY_ESP8266_PASSWORD "..."
    
    // Set the hostname for the WiFi Client. This is the hostname
    // it will pass to the DHCP server if not static.
    // #define MY_ESP8266_HOSTNAME "mqtt-sensor-gateway"
    
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    //#define MY_IP_ADDRESS 192,168,178,87
    
    // If using static ip you can define Gateway and Subnet address as well
    //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
    //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    // MQTT broker ip address and port.
    #define MY_CONTROLLER_IP_ADDRESS ...
    #define MY_PORT ...
    
    #include <ESP8266WiFi.h>
    #include <MySensors.h>
    
    void setup() {
      Serial.begin(38400);
    }
    
    void presentation() {
    }
    
    void loop() {
    }
    

    I think there is no problem with the sketch, because both sketches work when I am using an Arduino Uno instead of the standalone ATmega with the same sketch and wiring.

    And here are photos of the wiring. The radio is wired correctly, I checked it several times. And I also use the same wiring for the ATmega as I do usually...
    0_1517580253597_b618ae95-7482-4f8d-ac61-3baa6afb6f7f-image.png

    0_1517580272148_2cf39497-d90a-4458-9e17-f463b9e76364-image.png



  • A short addition:
    After starting the Mikrocontroller, my MQTT broker always receives the same messages. They have no payload and the syntax of the first four messages for example is:

    nRFGateway-Publish/255/16/3/0/3
    nRFGateway-Publish/255/239/3/0/3
    nRFGateway-Publish/255/206/3/0/3
    nRFGateway-Publish/255/174/3/0/3

    I hope this may help...


  • Hardware Contributor

    I'm sorry I won't be able to help for the MQTT side, I've not implemented this at my home yet...

    But if you run exactly the same script on the same chip then the difference is the wiring.
    What bootloader/frequency do you use on the atmega ?
    I see no 100nF cap on the power pins, maybe it would help for stability ?


  • Mod

    I think you need to add something in presentation function of the node, otherwise the mysensors gw down't know what the node is sending



  • So there is the difference. The Uno has 16MHz and the standalone 1MHz... and the wiring is 100% correct, I did this again and again like 10 Times and also tried a Second microcontroller without improvements. And the Strange Thing is that I Receive Messages (from Time to Time) but the Data Sent are Strange)
    And so the only difference is in the Frequence and the missing other Parts. Is there anything in the mqtt background which prohibits the correct transmission?



  • @gohan

    But the exact same Code works on the uno...


  • Mod

    I don't know much about the 1Mhz, but I read quite some times it can give problems.



  • @gohan until now everything worked well with this 1MHz. Also other libraries directly worked without Problems


  • Mod

    You'd never know what an updated library could do to your setup. Even a newer board definition could add a bug that you didn't have before.


  • Hardware Contributor

    @gohan said in nRF24L01+ MQTT:

    I don't know much about the 1Mhz, but I read quite some times it can give problems.

    It can give problems to speed/time accuracy related stuff, like driving neopixels or sensors with bit-banging and need for very precise pulse duration. For sending messages with a NRF24 it has never been a problem for me.

    It can also be a problem ... with serial. @TimDe is debug set in your MyConfig.h file ? and what baudrate is set for serial ?
    Can you try to set baudrate to 9600 as 1MHz with internal oscillator you can't go faster than that reliably, maybe your node is trying to write something on serial too fast for what it can handle ?
    Try to put the 100nf ceramic caps first (between gnd/avcc and gnd/vcc), that will close one possibility.

    Can you get a debug log on the mqtt gateway to see the content of the MySensors messages it receives from the node ?


 

256
Online

7.6k
Users

8.5k
Topics

91.2k
Posts