MQTT, Openhab, Mosquitto and static Node ID Problem

  • I have a setup of openhab and mosquitto on a raspberry pi and also a MQTT Gateway. Everything works fine in my test setup. Now I uploaded a sketch on one of my sensors and I only assigned a static Node_ID as well as child ID´s (Node ID is 1, child´s are 1,2,3,4). When I power up the sensor the serial monitor (of the gateway) gives the following output:

    0;0;3;0;9;read: 1-1-0 s=255,c=3,t=15,pt=2,l=2,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=255,c=0,t=18,pt=0,l=5,sg=0:1.5.4
    0;0;3;0;9;read: 1-1-0 s=255,c=3,t=6,pt=1,l=1,sg=0:0
    0;0;3;0;9;send: 0-0-1-1 s=255,c=3,t=6,pt=0,l=1,sg=0,st=ok:M

    If I am correct the "3" means : "I_ID_REQUEST 3 Use this to request a unique node id from the controller."

    So there is something wrong with my static ID!? Funnily enough it worked in my test setup.
    Here is the code where I initialze the gw:

    gw.begin(NULL, MY_NODE_ID, true);

    where MY_NODE_ID is 1.

    Any idea what´s going wrong? Do I have to do some extra settings in mosquitto or openhab to use static Node ID´s? Or is it sth. absolutely different?

    Thank you guys!!

    BTW, here my full code/sketch:

    // Simple binary switch example 
    // Connect button or door/window reed switch between 
    // digitial I/O pin 3 (BUTTON1_PIN below) and GND.
    #include <MySensor.h>
    #include <SPI.h>
    // Define Node ID
    #define MY_NODE_ID 1
    #include <Bounce2.h>
    #define CHILD1_ID 1 // Kontaktschalter 1
    #define CHILD2_ID 2 // Kontaktschalter 1
    #define BUTTON1_PIN  9  // Kontaktschalter 1
    #define BUTTON2_PIN  10  // Kontaktschalter 2
    #include <DHT.h>  
    #define CHILD_ID_HUM 3
    #define CHILD_ID_TEMP 4
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    MySensor gw;
    Bounce debouncer1 = Bounce(); 
    Bounce debouncer2 = Bounce(); 
    int oldValueReed1=-1;
    int oldValueReed2=-1;
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true; 
    // Kontaktschalter
    MyMessage msgReed1(CHILD1_ID,V_TRIPPED); // Kontaktschalter 1
    MyMessage msgReed2(CHILD2_ID,V_TRIPPED); // Kontaktschalter 2
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    void setup()  
      gw.begin(NULL, MY_NODE_ID, true);
    // Setup Kontaktschalter 1
        // Activate internal pull-up
    // Setup Kontaktschalter 2
      // Activate internal pull-up
      // After setting up the button, setup debouncer
      // Register binary input sensor to gw (they will be created as child devices)
      // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
      // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
      gw.present(CHILD1_ID, S_DOOR); 
      gw.present(CHILD2_ID, S_DOOR); 
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP); 
      metric = gw.getConfig().isMetric;
    //  Check if digital input has changed and send in new value
    void loop() 
      //Kontakstschalter 1
      // Get the update value
      int valueReed1 =;
      if (valueReed1 != oldValueReed1) {
         // Send in the new value
         gw.send(msgReed1.set(valueReed1==HIGH ? 1 : 0));
         Serial.println("Button 1 geschaltet");
         oldValueReed1 = valueReed1;
      //Kontakstschalter 2
      // Get the update value
      int valueReed2 =;
      if (valueReed2 != oldValueReed2) {
         // Send in the new value
         gw.send(msgReed2.set(valueReed2==HIGH ? 1 : 0));
         Serial.println("Button 2 geschaltet");
         oldValueReed2 = valueReed2;
      float temperature = dht.getTemperature();
      if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT");
      } else if (temperature != lastTemp) {
        lastTemp = temperature;
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        gw.send(msgTemp.set(temperature, 1));
        Serial.print("T: ");
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum) {
          lastHum = humidity;
          gw.send(msgHum.set(humidity, 1));
          Serial.print("H: ");
      //gw.sleep(SLEEP_TIME); //sleep a bit 

  • @siod I may be wrong - have had similar problems in the past. Try putting the bit that sets the node ID before the include for Mysensor.h

  • Plugin Developer



    There's nothing wrong with those lines of the log. The third digit from the left is the command type, 3 for internal. See the serial API for more info.

    This post is also good, it explains all those characters and numbers of the log:

    You should get some more lines after that. Presentation of the sensors.

    I can't see anything wrong with your sketch either.👍

  • Hi Martin, but that's all that comes in, not more. Its also not reacting when I trigger one of my reed switches.

    When triggering the reed switches of another sensor, an arduino nano with autoid configured, I can see mqtt messages coming in, so the gateway works fine.

  • Plugin Developer


    How did you connect the radio? The default connection uses D9 and D10 for CE/CS, but you have defined D9 and D10 for the reed switches.

  • I've ordered and then built the board from here:

  • Plugin Developer


    OK, if you look at the schematics for that PCB, you can see that CE and CS on the radio are routed the standard way, to D9 and D10. So you shouldn't use those pins for anything else in your sketch.

    I suggest using pin D2 and D3 for the reed switches. I think your problem now is happening when you change the mode and activate pullups of D9 and D10 which probably screws up the radio functions.

    Move the DHT to pin D4 for example.

  • Thank you Martin, that solved my issue!!

Log in to reply

Suggested Topics