<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[2 or more DHT22 on 1 node with Domoticz]]></title><description><![CDATA[<p dir="auto">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.<br />
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?</p>
<p dir="auto">Mysensors 2.3.1<br />
Domoticz 4.11506<br />
Tested on Arduino nano and NodeMcu (same results)</p>
<pre><code>#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 &lt;SPI.h&gt;
#include &lt;MySensors.h&gt;  
#include &lt;DHT.h&gt;           //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);
}
}
</code></pre>
]]></description><link>https://forum.mysensors.org/topic/10931/2-or-more-dht22-on-1-node-with-domoticz</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 07:55:10 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/10931.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 06 Feb 2020 20:30:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to 2 or more DHT22 on 1 node with Domoticz on Sat, 28 Mar 2020 23:37:08 GMT]]></title><description><![CDATA[<p dir="auto">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.<br />
--Gerard</p>
]]></description><link>https://forum.mysensors.org/post/104628</link><guid isPermaLink="true">https://forum.mysensors.org/post/104628</guid><dc:creator><![CDATA[Gerard van Seventer]]></dc:creator><pubDate>Sat, 28 Mar 2020 23:37:08 GMT</pubDate></item><item><title><![CDATA[Reply to 2 or more DHT22 on 1 node with Domoticz on Fri, 07 Feb 2020 12:21:54 GMT]]></title><description><![CDATA[<p dir="auto">Perhaps this could help?<br />
<a href="https://github.com/domoticz/domoticz/issues/276" rel="nofollow ugc">https://github.com/domoticz/domoticz/issues/276</a></p>
<p dir="auto">or this:<br />
<a href="https://github.com/domoticz/domoticz/pull/847" rel="nofollow ugc">https://github.com/domoticz/domoticz/pull/847</a></p>
]]></description><link>https://forum.mysensors.org/post/103663</link><guid isPermaLink="true">https://forum.mysensors.org/post/103663</guid><dc:creator><![CDATA[pjr]]></dc:creator><pubDate>Fri, 07 Feb 2020 12:21:54 GMT</pubDate></item></channel></rss>