Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. 2 or more DHT22 on 1 node with Domoticz

2 or more DHT22 on 1 node with Domoticz

Scheduled Pinned Locked Moved Troubleshooting
3 Posts 3 Posters 319 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    palmerfarmer
    wrote on last edited by
    #1

    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);
    }
    }
    
    1 Reply Last reply
    0
    • P Offline
      P Offline
      pjr
      wrote on last edited by pjr
      #2

      Perhaps this could help?
      https://github.com/domoticz/domoticz/issues/276

      or this:
      https://github.com/domoticz/domoticz/pull/847

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Gerard van Seventer
        wrote on last edited by Gerard van Seventer
        #3

        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

        1 Reply Last reply
        0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        63

        Online

        12.0k

        Users

        11.2k

        Topics

        113.4k

        Posts


        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • MySensors
        • OpenHardware.io
        • Categories
        • Recent
        • Tags
        • Popular