NRF24l01 Sensor_id aleatory



  • Hello, i need help
    I have a gateway with nrf24l01 with the mysensor lib and a client with the arduino mini pro.
    However when I get in the gatway the topic of the sensor_id is random.
    I tested with an arduino nano and it worked well.
    Something that is escaping me?

    63551 GWT:TPS:TOPIC=mygateway1-out/255/174/3/0/3,MSG SENT
    64551 TSF:MSG:READ,255-255-0,s=139,c=3,t=3,pt=0,l=0,sg=0:
    64557 GWT:TPS:TOPIC=mygateway1-out/255/139/3/0/3,MSG SENT
    65557 TSF:MSG:READ,255-255-0,s=104,c=3,t=3,pt=0,l=0,sg=0:
    65562 GWT:TPS:TOPIC=mygateway1-out/255/104/3/0/3,MSG SENT
    66562 TSF:MSG:READ,255-255-0,s=69,c=3,t=3,pt=0,l=0,sg=0:
    66567 GWT:TPS:TOPIC=mygateway1-out/255/69/3/0/3,MSG SENT

    174,139,104,69

    in the client I only have two registered:

    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1

    float lastTemp;
    float lastHum;
    uint8_t nNoUpdatesTemp;
    uint8_t nNoUpdatesHum;
    bool metric = true;

    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);

    void presentation()
    {
    // Send the sketch version information to the gateway
    sendSketchInfo("TemperatureAndHumidity", "1.1");

    // Register all sensors to gw (they will be created as child devices)
    present(CHILD_ID_HUM, S_HUM);
    present(CHILD_ID_TEMP, S_TEMP);


  • Mod

    Strange problem.

    Could you post the full sketch and the log from the node? (preferably with gateway log for the same time)



  • This??

    Basic gateway :

    // Enable debug prints to serial monitor
    #define MY_DEBUG

    // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
    #define MY_BAUD_RATE 115200

    // Enables and select radio type (if attached)
    #define MY_RADIO_RF24
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95

    #define MY_GATEWAY_MQTT_CLIENT
    #define MY_GATEWAY_ESP8266

    // Set this node's subscribe and publish topic prefix
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"

    // Set MQTT client id
    #define MY_MQTT_CLIENT_ID "mysensors-1"

    // Enable these if your MQTT broker requires username/password
    //#define MY_MQTT_USER "username"
    //#define MY_MQTT_PASSWORD "password"

    // Set WIFI SSID and password
    #define MY_WIFI_SSID "xxx"
    #define MY_WIFI_PASSWORD "xxx"

    // Set the hostname for the WiFi Client. This is the hostname
    // it will pass to the DHCP server if not static.
    // #define MY_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.
    #define MY_CONTROLLER_IP_ADDRESS 192, 168, 1, 211

    //MQTT broker if using URL instead of ip address.
    //#define MY_CONTROLLER_URL_ADDRESS "192.168.1.211"

    // The MQTT broker port to to open
    #define MY_PORT 1883

    // Enable inclusion mode
    //#define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    //#define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN D1

    // Set blinking period
    //#define MY_DEFAULT_LED_BLINK_PERIOD 300

    // Flash leds on rx/tx/err
    //#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED

    #include <ESP8266WiFi.h>
    #include <MySensors.h>

    void setup()
    {
    // Setup locally attached sensors

    }

    void presentation()
    {
    // Present locally attached sensors here
    }

    void loop()
    {
    // Send locally attached sensors data here
    }

    Client, simple sketch to send only simple values like temperature a humidity :

    // Enable debug prints
    #define MY_DEBUG

    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    //#define MY_RS485

    #include <SPI.h>
    #include <MySensors.h>

    // Set this offset if the sensor has a permanent small offset to the real temperatures
    //#define SENSOR_TEMP_OFFSET 0

    // Sleep time between sensor updates (in milliseconds)
    // Must be >1000ms for DHT22 and >2000ms for DHT11
    static const uint64_t UPDATE_INTERVAL = 5000;

    // Force sending an update of the temperature after n sensor reads, so a controller showing the
    // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
    // the value didn't change since;
    // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
    //static const uint8_t FORCE_UPDATE_N_READS = 10;

    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1

    bool metric = true;

    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);

    void presentation()
    {
    // Send the sketch version information to the gateway
    sendSketchInfo("TemperatureAndHumidity", "1.1");

    // Register all sensors to gw (they will be created as child devices)
    present(CHILD_ID_HUM, S_HUM);
    present(CHILD_ID_TEMP, S_TEMP);

    metric = getControllerConfig().isMetric;
    }

    void setup()
    {

    }

    void loop()
    {

    send(msgTemp.set(12, 1));

    send(msgHum.set(66, 1));

    // Sleep for a while to save energy
    //sleep(UPDATE_INTERVAL);
    delay(UPDATE_INTERVAL);

    }

    0_1559485704664_ef06d18f-fdd9-489b-9358-cb7500661c70-image.png



  • Forget, i use node-red, the message arrives, but of course empty, because i subscribe : mygateway1-out/#...



  • I think that is a insufficient current. A mini is a 3.3v. Now a use a pro mini 5v, and work....



  • NRF24 can work with wemos d1 mini as client? I try but the result is the sensor_id in topic, in gateway is aleatory .


  • Mod

    @maos the node is trying to request a node id.

    Add #define MY_NODE_ID 3 (or whatever number between 1 and 254 you want your node to have) in the node sketch, above #include MySensors.h



  • @mfalkvidd said in NRF24l01 Sensor_id aleatory:

    _NODE_ID 3 (or whatever nu

    Yes, it does. This is the first time I work with this livrary. Thank you for taking the time to help me.

    I have this scenario. Have a gateway with mqtt and others to send to this gateway. However I also need to send some information to the gateways. I have control receive (const MyMessage & message) {
    However can I, send this information to all the clients that are sending to this gateway?


  • Mod

    @maos great that you got it working.

    Sending to all clients can be done, but there are a few things to consider:

    • nodes on battery will be sleeping and will therefore not be able to receive messages. To handle this case, look at smartsleep.
    • when should the information be sent? Is it triggered by some message from something? Or by time? Something else?
    • will you be sending the exact same information, or will the information be customized per node?

    Some controllers support sending to multiple nodes. How to do this differs depending on which controller you are using. Sometimes it is better to let the nodes request information from the controller.



  • Sorry, I guess I was not very clear. At this point would be to just send to another nearby node 3 or 4.
    I do not want to send it to everyone at the same time.
    From gateway to another node.



  • Stupid.....
    mygateway1-in / 3/0/1/0/1, to publish .....
    I'm going to study the library gradually, so far I think top


Log in to reply
 

Suggested Topics

  • 1
  • 5
  • 6
  • 2
  • 10
  • 3

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts