2 or more DHT22 on 1 node with Domoticz



  • I wonder if any one can help with my (hacked and borrowed) sketch that inlcudes x2 DHT22 sensors on one node. Before I start I think my problem is the way Domoticz handles the data so this post probably shouldn't even be on here.
    My sketch below works in the Mysensors serial monitor and i even have a version with a TFT lcd display, all correct. The problem is when it appears in domoticz the humidity from one sensor appears on the other and the 2nd hum is ignored.... for a few seconds it then randomly appears on the correct sensor. There seems to be a few posts problems but with no solution. Can anyone help?

    Mysensors 2.3.1
    Domoticz 4.11506
    Tested on Arduino nano and NodeMcu (same results)

    #define MY_RADIO_RF24
    #define MY_RF24_PA_LEVEL (RF24_PA_MIN)
    #define MY_NODE_ID 114
    
    //taken from the original and mysensors forum
    //http://forum.mysensors.org/topic/1393/2-or-more-dht11-sensors-on-one-arduino-nano-mysensor/8
    //http://forum.mysensors.org/topic/1462/getting-node-id-0-after-erasing-eeprom
    
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <DHT.h>           //dht22 
    
    
    //Definition of sensor
    #define CHILD_ID1_HUM 1
    #define CHILD_ID1_TEMP 3
    #define CHILD_ID2_HUM 2
    #define CHILD_ID2_TEMP 4
    
    const int HUMIDITY_SENSOR1_DIGITAL_PIN = D0;
    const int HUMIDITY_SENSOR2_DIGITAL_PIN = D1;
    
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
    //MySensor;
    DHT dht1;
    DHT dht2;
    float lastTemp1;
    float lastHum1;
    float lastTemp2;
    float lastHum2;
    
    boolean metric = true; 
    MyMessage msgHum1(CHILD_ID1_HUM, V_HUM);
    MyMessage msgTemp1(CHILD_ID1_TEMP, V_TEMP);
    MyMessage msgHum2(CHILD_ID2_HUM, V_HUM);
    MyMessage msgTemp2(CHILD_ID2_TEMP, V_TEMP);
    
    void setup()  
    { 
      
     // begin();
      dht1.setup(HUMIDITY_SENSOR1_DIGITAL_PIN); 
      dht2.setup(HUMIDITY_SENSOR2_DIGITAL_PIN);
    
      // Send the Sketch Version Information to the Gateway
      sendSketchInfo("2DHT22_ESP8266", "V2");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID1_HUM, S_HUM);
      present(CHILD_ID1_TEMP, S_TEMP);
      present(CHILD_ID2_HUM, S_HUM);
      present(CHILD_ID2_TEMP, S_TEMP);
    
    
     // metric = getConfig().isMetric;
        
    }
    
    void loop()      
      {
        
    //DHT 11 Sensor 1
    
      delay(dht1.getMinimumSamplingPeriod());
    
      float temperature1 = dht1.getTemperature();
      if (isnan(temperature1)) {
        Serial.println("Failed reading temperature from DHT 1");
      } else if (temperature1 != lastTemp1) {
        lastTemp1 = temperature1;
        if (!metric) {
        temperature1 = dht1.toFahrenheit(temperature1);
        }
        send(msgTemp1.set(temperature1, 1));
        Serial.print("T1: ");
        Serial.println(temperature1);
      
      }
      float humidity1 = dht1.getHumidity();
      if (isnan(humidity1)) {
        Serial.println("Failed reading humidity from DHT 1");
      } else if (humidity1 != lastHum1) {
        lastHum1 = humidity1;
        send(msgHum1.set(humidity1, 1));
        Serial.print("H1: ");
        Serial.println(humidity1);
    
      }
    
    delay(500);
    
    // DHT11 Sensor 2
    {
      delay(dht2.getMinimumSamplingPeriod());
    
      float temperature2 = dht2.getTemperature();
      if (isnan(temperature2)) {
        Serial.println("Failed reading temperature from DHT 2");
      } else if (temperature2 != lastTemp2) {
        lastTemp2 = temperature2;
        if (!metric) {
        temperature2 = dht2.toFahrenheit(temperature2);
        }
        send(msgTemp2.set(temperature2, 1));
        Serial.print("T2: ");
        Serial.println(temperature2);
    
      }
      float humidity2 = dht2.getHumidity();
      if (isnan(humidity2)) {
        Serial.println("Failed reading humidity from DHT 2");
      } else if (humidity2 != lastHum2) {
        lastHum2 = humidity2;
        send(msgHum2.set(humidity2, 1));
        Serial.print("H2: ");
        Serial.println(humidity2);
    
        }
      
       
      sleep(SLEEP_TIME); //sleep a bit
    
      delay (2000);
    }
    }
    




  • A bit of a late reply but some time ago I also asked about this in the domoticz forum. "They" don't see the problem although I clearly see in the domoticz sources that this stupid behavior is intentionally put in there. I compiled domoticz with a few changed lines and then it works. Unfortunately I have tons of Mysensors issues, mainly with the NRF2401 (yes, from multiple sources, good psu, capacitors etc.) so I am forcefully have to abandon Mysensors and migrate to ESP8266 nodes to finally get a stable sensor network. Therefore I'm also more flexible with domoticz.
    --Gerard


Log in to reply
 

Suggested Topics

  • 4
  • 7
  • 5
  • 9
  • 7
  • 5
  • 1
  • 4

197
Online

9.6k
Users

10.2k
Topics

106.2k
Posts