DHT22 and DS18b20 on same node: DS shows up with Humidity now.



  • Hey guys,
    I'm new to MySensors but not Arduino in general. I'm using several MySensors nodes with RF24L01+ radios, talking thru a MySensors USB/Serial Gateway to my Domoticz server on a rPi. I can easily add nodes and they auto-register in Domoticz, and all is well.

    One issue I'm still scratching my head on, is I have a node that consists of a DHT22 temp+hum, two OneWire DS18b20/Dallas temp sensors, and a IR motion sensor. They all work fine and report good data, but the Dallas temp sensors show up in Domoticz as temp+hum. Reading the graphs over time, the data is real, and it is actually just pairing up its' temp with the humidity reading from the DHT22, on all three of the temp sensors. Now, in some regard, I suppose it's handy that it combines that data, but since the Dallas temp probes are actually measuring temp in a different area, it's not desirable for me to report the humidity on those sensors, since the reading is not actually "at" the sensor location for those particular Dallas sensors.

    When looking at the logic of the MySensors code, it makes sense, since all of the data coming from that one node is a child of the overall node. So with that, is there a way to parse off the DHT22 in code so it presents as its' own Node, so its' temp+hum will be child nodes, then the other sensors can present as a Node (two Dallas temps, and motion)? I am thinking that would pass thru the gateway to my Domoticz server, it would think they are separate nodes, and not combine data.

    Here's my sketch in question; it's hacked together from two example sketches. Any advice would be appreciated!

    #include <SPI.h>
    #include <MySensor.h>  
    #include <DHT.h>  
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    #define ONE_WIRE_BUS 5 // Pin where dallase sensor is connected 
    #define MAX_ATTACHED_DS18B20 16
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_MOT 2   // Id of the sensor child
    #define CHILD_ID_DS1 3
    #define HUMIDITY_SENSOR_DIGITAL_PIN 4
    
    #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    
    
    unsigned long SLEEP_TIME = 5000; // Sleep time between reads (in milliseconds)
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    
    MySensor gw;
    DHT dht;
    float lastTemp;
    float lastHum;
    float lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors=0;
    boolean receivedConfig = false;
    boolean metric = false; 
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgMot(CHILD_ID_MOT, V_TRIPPED);
    MyMessage msgOneWire(0, V_TEMP);
    
    void setup()  
    { 
      sensors.begin();
      gw.begin();
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
      // Send the Sketch Version Information to the Gateway
      gw.sendSketchInfo("Temp/Humidity/Motion", "1.0");
    
      // Fetch the number of attached temperature sensors  
      numSensors = sensors.getDeviceCount();
    
     pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
     
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      gw.present(CHILD_ID_MOT, S_MOTION);
      for (int j=CHILD_ID_DS1; j < (numSensors + CHILD_ID_DS1) && j<MAX_ATTACHED_DS18B20; j++) {   
      gw.present(j, S_TEMP);
      }
       
      metric = gw.getConfig().isMetric;
    }
    
    void loop()      
    
    {  
      // Process incoming messages (like config from server)
      gw.process();
      
      // Fetch temperatures from Dallas sensors
      sensors.requestTemperatures();
      
      // Read digital motion value
      boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
      Serial.print("Motion: ");      
      Serial.println(tripped);
      gw.send(msgMot.set(tripped?"1":"0"));  // Send tripped value to gw 
      
      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("DHT Temp: ");
        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("DHT RH: ");
          Serial.println(humidity);
      }
    
      // Read temperatures and send them to controller 
      for (int i=0; i < numSensors && i<MAX_ATTACHED_DS18B20; i++) {
    //int i = 0;
        // Fetch and round temperature to one decimal
        float temp = static_cast<float>(static_cast<int>((sensors.getTempCByIndex(i)) * 10.)) / 10.;
     
        // Only send data if temperature has changed and no error
        if (lastTemperature[i] != temp && temp != -127.00) {
     
          // Send in the new temperature
          Serial.print("DS");
          Serial.print(i);
          Serial.print(": ");
          Serial.println(temp);
          gw.send(msgOneWire.setSensor(i+CHILD_ID_DS1).set(temp, 1));
          lastTemperature[i]=temp;
        }
      }
     
      // Sleep until interrupt comes in on motion sensor. Send update every two minutes. 
      gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
    }
    


  • @jbishop129 Hi I am sorry have the same problem but have not found any solution to it yet.



  • Until Domoticz team doesn't fix it, there's no solution.
    Even registering second ID for arduino didn't solve problem.



  • Seems to be related to the domoticz gateway. Also tried to downgrade to the first version that supported Arduino as serial controller but same problem. Strange thing is that if you restart controller and only present temp in the sketch its working until you present the humidity??



  • Hi ! You can get a partly workaround using V_DUST_LEVEL or something instead of V_HUM.



  • This is a really annoying thing.
    I finally decided to modify the Domoticz sources, and now
    temperature shows up with humidity only if they have
    consecutive ID, otherwise they are shown separated.



  • @zampedro I have exactly the same problem

    Could you please tell me more of how you modified Domoticz source?

    This bug is really annoying!

    Regards,
    Mikael


  • Hero Member

    @miljume Domoticz developers consider this a feature... not a bug 😉


  • Mod

    I get a similar problem on my plant monitoring. The graph always says "Temperature" even though the sensors only report humidity. I need to explain it every time I show the graphs to anyone.



  • I modified MySensorBase.cpp

    void MySensorsBase::SendSensor2Domoticz
    case V_TEMP:

    at lines 595 and 603 (numbers from last git code) for Temperature

    // SendTempHumBaroSensorFloat(cNode, pChild->batValue, Temp, Humidity, Baro, nforecast, (!pChild->childName.empty()) ? pChild->childName : "TempHumBaro");
    if ( (pChildHum->childID+1)== pChild->childID)
    SendTempHumBaroSensorFloat(cNode, pChild->batValue, Temp, Humidity, Baro, nforecast, (!pChild->childName.empty()) ? pChild->childName : "TempHumBaro");
    else
    SendTempSensor(cNode, pChild->batValue, Temp, (!pChild->childName.empty()) ? pChild->childName : "Temp");

    // SendTempHumSensor(cNode, pChild->batValue, Temp, Humidity, (!pChild->childName.empty()) ? pChild->childName : "TempHum");
    if ( (pChildHum->childID+1)== pChild->childID)
    SendTempHumSensor(cNode, pChild->batValue, Temp, Humidity, (!pChild->childName.empty()) ? pChild->childName : "TempHum");
    else
    SendTempSensor(cNode, pChild->batValue, Temp, (!pChild->childName.empty()) ? pChild->childName : "Temp");

    case V_HUM:
    

    at lines 678 and 686 for Humidity

    // SendTempHumBaroSensorFloat(cNode, pChildTemp->batValue, Temp, Humidity, Baro, nforecast, (!pChild->childName.empty()) ? pChild->childName : "TempHumBaro");
    if ( (pChild->childID+1)== pChildTemp->childID)
    SendTempHumBaroSensorFloat(cNode, pChildTemp->batValue, Temp, Humidity, Baro, nforecast, (!pChild->childName.empty()) ? pChild->childName : "TempHumBaro");
    else
    SendHumiditySensor(cNode, pChild->batValue, Humidity, (!pChild->childName.empty()) ? pChild->childName : "Hum");

    // SendTempHumSensor(cNode, pChildTemp->batValue, Temp, Humidity, (!pChild->childName.empty()) ? pChild->childName : "TempHum");
    if ( (pChild->childID+1)== pChildTemp->childID)
    SendTempHumSensor(cNode, pChildTemp->batValue, Temp, Humidity, (!pChild->childName.empty()) ? pChild->childName : "TempHum");
    else
    SendHumiditySensor(cNode, pChild->batValue, Humidity, (!pChild->childName.empty()) ? pChild->childName : "Hum");

    In this way hum+temp of DHT11 are shown together ( CHILD_ID_HUM +1 == CHILD_ID_TEMP ) and
    temperatures from ds18b20 are alone in separate widgets.

    #define CHILD_ID_HUM 9 // DHT11
    #define CHILD_ID_TEMP 10 // DHT11
    #define DS18B20_STARTID 15 // DS18B20

    Regards



  • @zampedro Sounds perfect, is there any chance this change can be merged into the source of Domoticz?



  • @zampedro said:

    I modified MySensorBase.cpp

    void MySensorsBase::SendSensor2Domoticz
    case V_TEMP:

    at lines 595 and 603 (numbers from last git code) for Temperature

    // SendTempHumBaroSensorFloat(cNode, pChild->batValue, Temp, Humidity, Baro, nforecast, (!pChild->childName.empty()) ? pChild->childName : "TempHumBaro");
    if ( (pChildHum->childID+1)== pChild->childID)
    SendTempHumBaroSensorFloat(cNode, pChild->batValue, Temp, Humidity, Baro, nforecast, (!pChild->childName.empty()) ? pChild->childName : "TempHumBaro");
    else
    SendTempSensor(cNode, pChild->batValue, Temp, (!pChild->childName.empty()) ? pChild->childName : "Temp");

    // SendTempHumSensor(cNode, pChild->batValue, Temp, Humidity, (!pChild->childName.empty()) ? pChild->childName : "TempHum");
    if ( (pChildHum->childID+1)== pChild->childID)
    SendTempHumSensor(cNode, pChild->batValue, Temp, Humidity, (!pChild->childName.empty()) ? pChild->childName : "TempHum");
    else
    SendTempSensor(cNode, pChild->batValue, Temp, (!pChild->childName.empty()) ? pChild->childName : "Temp");

    case V_HUM:

    at lines 678 and 686 for Humidity

    // SendTempHumBaroSensorFloat(cNode, pChildTemp->batValue, Temp, Humidity, Baro, nforecast, (!pChild->childName.empty()) ? pChild->childName : "TempHumBaro");
    if ( (pChild->childID+1)== pChildTemp->childID)
    SendTempHumBaroSensorFloat(cNode, pChildTemp->batValue, Temp, Humidity, Baro, nforecast, (!pChild->childName.empty()) ? pChild->childName : "TempHumBaro");
    else
    SendHumiditySensor(cNode, pChild->batValue, Humidity, (!pChild->childName.empty()) ? pChild->childName : "Hum");

    // SendTempHumSensor(cNode, pChildTemp->batValue, Temp, Humidity, (!pChild->childName.empty()) ? pChild->childName : "TempHum");
    if ( (pChild->childID+1)== pChildTemp->childID)
    SendTempHumSensor(cNode, pChildTemp->batValue, Temp, Humidity, (!pChild->childName.empty()) ? pChild->childName : "TempHum");
    else
    SendHumiditySensor(cNode, pChild->batValue, Humidity, (!pChild->childName.empty()) ? pChild->childName : "Hum");

    In this way hum+temp of DHT11 are shown together ( CHILD_ID_HUM +1 == CHILD_ID_TEMP ) and
    temperatures from ds18b20 are alone in separate widgets.

    #define CHILD_ID_HUM 9 // DHT11
    #define CHILD_ID_TEMP 10 // DHT11
    #define DS18B20_STARTID 15 // DS18B20

    Regards

    Where can I find the MySensorsBase.cpp? I am running domoticz on windows and in the installation folder I can't find the file. I can see the file on GitHub but how do I install domoticz from GitHub?



  • @palande.vaibhav You have to compile domoticz from source, highly recommended if
    you run it on raspberry, orangepi etc...


  • Hero Member

    @zampedro Please have a look at this thread. The "combination issue" is discussed and solved. There is no reason to compile Domoticz yourself when running on Raspberry. I discourage compiling yourself (unless you like the excercise). The precompiled image works out of the box.



  • @AWI Thanks for the hint.
    I thought this wasn't a "issue" but just a "really annoying thing".
    However i run domoticz on a Orange PI PC with WiringOP support and i can't find precompiled images.


Log in to reply
 

Suggested Topics

50
Online

11.4k
Users

11.1k
Topics

112.6k
Posts