Missing sensor nodes in domoticz



  • Hi everybody,

    for my start with mysensors I try to setup a serial gateway with sensors connected directly (no radio) to the arduino. But the sensors don't show up completely in domoticz. I have a DHT22 humidity sensor and a bmp180 for air pressure.
    In domoticz I can setup the gateway and see all three childs (T, H, P) in the hardware node setup with a "last seen" time stamp a few seconds ago and updating once in a while. But in the devices list only temperature and humidity show up. So I don't see the pressure data. I believe, there must be a mistake in my sketch. Has anybody an idea? Thanks.

    On the serial monitor the log seems good:

    0;255;3;0;14;Gateway startup complete.
    0;255;3;0;11;Humidity, Pressure
    0;255;3;0;12;1.0
    0;0;0;0;7;Raum 1 H
    0;1;0;0;6;Raum 1 T
    0;2;0;0;8;Raum 1 P
    0;1;1;0;0;20.3
    T: 20.30
    0;0;1;0;1;57.7
    H: 57.70
    0;2;1;0;4;100988.0
    P: 100988
    

    From the domoticz log :

    2016-02-27 16:10:19.090 MySensors: Using serial port: /dev/ttyUSB0
    2016-02-27 16:10:19.710 Incoming connection from: 192.168.2.100
    2016-02-27 16:10:20.695 MySensors: Node: 0, Sketch Name: Humidity, Pressure
    2016-02-27 16:10:20.696 MySensors: Node: 0, Sketch Version: 1.0
    2016-02-27 16:10:23.697 (Gateway_1) Temp (Raum 1 T)
    2016-02-27 16:10:24.696 (Gateway_1) Temp + Humidity (Raum 1 H) 
    

    And here is my sketch:

    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    // Flash leds on rx/tx/err
    #define MY_LEDS_BLINKING_FEATURE
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // 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  3 
    
    #define DHTPIN A0
    #include <SPI.h>
    #include <MySensor.h>  
    #include <DHT.h>
    #include <Adafruit_BMP085.h>
    #include <Wire.h>
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_BARO 2
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
    DHT dht;
    Adafruit_BMP085 bmp;
    float lastTemp = -1;
    float lastHum = -1;
    float lastBaro = -1;
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgBaro(CHILD_ID_BARO, V_PRESSURE);
    
    void setup() { 
      dht.setup(DHTPIN);
      bmp.begin();
    }
    
    void presentation() {
     sendSketchInfo("Humidity, Pressure", "1.0");
     present(CHILD_ID_HUM, S_HUM, "Raum 1 H");
     present(CHILD_ID_TEMP, S_TEMP, "Raum 1 T");
     present(CHILD_ID_BARO, S_BARO, "Raum 1 P");
    }
    
    void loop() { 
      delay(dht.getMinimumSamplingPeriod());
    
      // Fetch temperatures from DHT sensor
      float temperature = dht.getTemperature();
      if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT22");
      } else if (temperature != lastTemp) {
        lastTemp = temperature;
        send(msgTemp.set(temperature, 1));
        Serial.print("T: ");
        Serial.println(temperature);
      }
      
      // Fetch humidity from DHT sensor
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT22");
      } else if (humidity != lastHum) {
          lastHum = humidity;
          send(msgHum.set(humidity, 1));
          Serial.print("H: ");
          Serial.println(humidity);
     }
    
     //Fetch Pressure
     long pressure = bmp.readPressure();
     pressure = pressure / pow((1.0 - ( 106 / 44330.0)),5.255);
     if (isnan(pressure)) {
        Serial.println("Failed reading pressure from BMP180");
        } else if (abs(pressure - lastBaro) > 10) { 
        send(msgBaro.set(pressure, 1));
        lastBaro = pressure;
        Serial.print("P: ");
        Serial.println(pressure);
        }
    }
    

  • Mod

    Interesting that "Raum 1 T" is received before "Raum 1 H" even though "Raum 1 H" is presented first in your code.

    Adding delay(250) between each gw.present has helped other people. Try that.


  • Hardware Contributor

    I looked quickly through the code and cant find anything obvious.
    I made something similar: http://forum.mysensors.org/topic/1548/my-outdoor-weather-sensor-5v-powered-combined-temp-hum-pressure-and-light/2 check it out if there is something different because my code works fine for me in domoticz.

    Temp, Hum and Baro are presented togehter as one device but are shown as two in the tabs. Temp/Hum are in "temperature" and baro is under weather,



  • @mfalkvidd thank you, I added a delay before every present(), but that didn't change anything.

    @sundberg84 your example is mostly the same as mine. I think I used this or a copy of it as basis for mine.
    What I do not understand is, that I can't define a MySensor variable (" MySensor gw; "). Maybe it is not needed within a gateway. So I can not use the begin() command.


  • Hardware Contributor

    @lorimo I have had to add 500ms between each sensor presentation.

    I now put this in my code:

    #define MESSAGEWAIT 500

    and after sending something to Domoticz I do either wait(MESSAGEWAIT); for AC based nodes, or sleep(MESSAGEWAIT); for battery based nodes (I'm using the DEV version of the library, you may need to do gw.wait(MESSAGEWAIT)). Seems to resolve my problems.

    I'm hoping the gateway software for Raspberry will include the use of the interrupt capability of the NRF24L01+ at some point, then these intervals are no longer needed.



  • @GertSanders Thanks, I tested with 500ms and now also added a wait(500) before each send() but without success.
    I found an additional interesting point: On the hardware setup page for the nodes the "last seen" time stamp for the childs changes with each send (blinking LED on Arduino) but on the dashboard the "last seen" stays at the time when I plugged the Arduino in. And the sensor value does also not change within domoticz.


  • Hardware Contributor

    Aaaaaah!? I dont think Domoticz updates the value if its the same as before - could it be?
    Have a look at your gateway log - there you will see if thats the issue. You will recieve the baro value there.


  • Mod

    Well spotted! Yes, "last seen" in Domoticz has nothing to do with when the sensor was last seen, unfortunately. Sometimes the logic behind Domoticz isn't very logical.



  • @sundberg84 that's right, domoticz updates only after changes, because only then the mysensor node sends data. AFAIK domoticz does not compress the incoming data. In the gateway log there are value changes every few seconds, so there should something happen.

    @mfalkvidd I experimented with the DHT sensor directly connected to the raspberri Pi running domoticz. Then the "last seen" changed with every updated value. So I expected this to happen with the MySensor node also.

    After waiting some more time the values of temperature and humidity are still unchanged but that can not be correct.


  • Hardware Contributor

    Ok, but the logic here must then be that if you see the traffic in your gateway log, but nothing in domoticz - there must be something wrong with your connection gateway - domoticz - no?



  • @sundberg84 the connection is a regular USB cable which works fine on other devices too.
    But I am one step ahead: I changed the sketch for only using the humidity sensor and it worked as expected. The values come in and I see them in the domoticz log, also the "last seen" in the dashboard updates.
    Then I did the same for the pressure sensor and it didn't work. For this the solution was really easy: a type mismatch. I defined "pressure" as "long" and "lastBaro" as "float". After changing both to "float" the single sensor gateway woks fine. I see the pressure sensor in the devices list and the values are collected.

    But when I connect both sensors, still nothing works.


  • Hardware Contributor

    Really strange... as i said it works great with my sketch and it looks similar.



  • @sundberg84 still searching for a solution.
    I tried to rewrite the sketch, starting from the working single sensor gateway with the humidity sensor. In the domoticz log I can see the messages from the sensor come in and the value is updated. Then I added line by line the necessary code for the pressure sensor.
    The "present(ID, S_BARO);" did not have any results, but the humidity still updates. After adding the "send(msgBaro.set(pressure, 0));" the data delivery stopped (does it make any difference here to have a "0" instead of "1" for the ack? It's the only difference to your script I found.)
    It's the same the other way around: starting from the gateway only with the pressure sensor. As soon as I add the send command the function stops.

    This led me to the idea, that there must be something wrong with the present() or the library. I searched for another library for the BMP180 sensor and fond https://github.com/sparkfun/BMP180_Breakout. And it worked directly. The only problem is, that now the values are incorrect. I get 867hPa instead of 1018hPa.

    Thanks for your help!



  • @sundberg84 So I found the error while using the SFE_BMP180 library: there is a need for a short delay before the getPressure(). So now it works.

    But why not with the Adafruit_BMP085 library I do not understand.

    Thanks a lot.



  • @lorimo Good you worked it out - sometimes it can be a combination of several libraries. I have been really struggling to combine DS18B20, DHT22, water and gas sensor though separately all sketches were working just fine.

    In your case, the simple solution would be having BME280 instead of both DHT22 and BMP180



  • @alexsh1 yes, that's what I found out after buying those two devices. But for some early tests and freshen up my rusty programming skills it is good. Maybe I change the hardware for the final installation.
    But it is still curious, that those two libraries won't work together. I tried to understand the code, but up to now did not find a clue, what could be the reason.



  • @lorimo it is a low level programming you have to look at. Also from my experience having one sensor is always better than having two. You may park your sensors and go for BME280. It is more expensive, but very small and handy.



  • Do you love curiosity?
    After nearly a week of running, my gateway stopped working out of the blue.
    I found out, that I am where I began. The same effects as described in the original post, but with the SFE library.

    So I tried it again with the original Adafruit_BMP library and --- it worked !

    Maybe there is something with my hardware. I'll go and get me another Arduino Board from a different manufacturer and try it again.



  • @lorimo said:

    Do you love curiosity?
    After nearly a week of running, my gateway stopped working out of the blue.

    Are you sure this is not a node and 100% the gateway stopped working?



  • @alexsh1 yes, I'm sure. Up to now it is only a serial gateway with direct connected sensors.


Log in to reply
 

Suggested Topics

  • 5
  • 4
  • 5
  • 4
  • 1
  • 2

71
Online

11.4k
Users

11.1k
Topics

112.7k
Posts