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
    
    //Kontaktschalter
    #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
    
    //Tempsensor
    #include <DHT.h>  
    #define CHILD_ID_HUM 3
    #define CHILD_ID_TEMP 4
    #define HUMIDITY_SENSOR_DIGITAL_PIN 2
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
    MySensor gw;
    
    //Kontaktschalter
    Bounce debouncer1 = Bounce(); 
    Bounce debouncer2 = Bounce(); 
    int oldValueReed1=-1;
    int oldValueReed2=-1;
    
    //tempsensor
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true; 
    
    //Messages
    // Kontaktschalter
    MyMessage msgReed1(CHILD1_ID,V_TRIPPED); // Kontaktschalter 1
    MyMessage msgReed2(CHILD2_ID,V_TRIPPED); // Kontaktschalter 2
    
    //TempMessage
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    void setup()  
    {  
      gw.begin(NULL, MY_NODE_ID, true);
    
      //Tempsensor
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
    // Setup Kontaktschalter 1
      pinMode(BUTTON1_PIN,INPUT);
        // Activate internal pull-up
      digitalWrite(BUTTON1_PIN,HIGH);
    // Setup Kontaktschalter 2
      pinMode(BUTTON2_PIN,INPUT);
      // Activate internal pull-up
      digitalWrite(BUTTON2_PIN,HIGH);
      
      // After setting up the button, setup debouncer
      debouncer1.attach(BUTTON1_PIN);
      debouncer2.attach(BUTTON2_PIN);
      debouncer1.interval(5);
      debouncer2.interval(5);
      
      // 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); 
      //Tempsensor
      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
      debouncer1.update();
      // Get the update value
      int valueReed1 = debouncer1.read();
     
      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
      debouncer2.update();
      // Get the update value
      int valueReed2 = debouncer2.read();
     
      if (valueReed2 != oldValueReed2) {
         // Send in the new value
         gw.send(msgReed2.set(valueReed2==HIGH ? 1 : 0));
         Serial.println("Button 2 geschaltet");
         oldValueReed2 = valueReed2;
      }
      
     //Tempsensor
    
     delay(dht.getMinimumSamplingPeriod());
    
      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: ");
        Serial.println(temperature);
      }
      
      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: ");
          Serial.println(humidity);
      }
    
      //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

    @siod

    Hi!

    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:
    http://forum.mysensors.org/topic/666/debug-faq-and-how-ask-for-help/3
    😄

    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

    @siod

    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: http://forum.mysensors.org/topic/2067/my-slim-2aa-battery-node


  • Plugin Developer

    @siod

    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

58
Online

11.4k
Users

11.1k
Topics

112.6k
Posts