The temperature and humidity sensor sends only humidity. Please help me understand.
-
Hello! I'm trying to connect a temperature and humidity sensor to Openhab 2.2.
The sensor is detected automatically as "Humidity Sensor".
But it displays the following:
Please help me understand and solve the problem. What am I doing wrong?
Sensor code:
#define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 //#define MY_RS485 #include <SPI.h> #include <MySensors.h> #include <DHT.h> // Set this to the pin you connected the DHT's data pin to #define DHT_DATA_PIN 3 // Set this offset if the sensor has a permanent small offset to the real temperatures #define SENSOR_TEMP_OFFSET 0 // Sleep time between sensor updates (in milliseconds) // Must be >1000ms for DHT22 and >2000ms for DHT11 static const uint64_t UPDATE_INTERVAL = 10000; // Force sending an update of the temperature after n sensor reads, so a controller showing the // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that // the value didn't change since; // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms] static const uint8_t FORCE_UPDATE_N_READS = 10; #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 float lastTemp; float lastHum; uint8_t nNoUpdatesTemp; uint8_t nNoUpdatesHum; bool metric = true; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); DHT dht; void presentation() { // Send the sketch version information to the gateway sendSketchInfo("TemperatureAndHumidity", "1.1"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_TEMP, S_TEMP); metric = getControllerConfig().isMetric; } void setup() { dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) { Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!"); } // Sleep for the time of the minimum sampling period to give the sensor time to power up // (otherwise, timeout errors might occure for the first reading) sleep(dht.getMinimumSamplingPeriod()); } void loop() { // Force reading sensor, so it works also after sleep() dht.readSensor(true); // Get temperature from DHT library float temperature = dht.getTemperature(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT!"); } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) { // Only send temperature if it changed since the last measurement or if we didn't send an update for n times lastTemp = temperature; if (!metric) { temperature = dht.toFahrenheit(temperature); } // Reset no updates counter nNoUpdatesTemp = 0; temperature += SENSOR_TEMP_OFFSET; send(msgTemp.set(temperature, 1)); #ifdef MY_DEBUG Serial.print("T: "); Serial.println(temperature); #endif } else { // Increase no update counter if the temperature stayed the same nNoUpdatesTemp++; } // Get humidity from DHT library float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) { // Only send humidity if it changed since the last measurement or if we didn't send an update for n times lastHum = humidity; // Reset no updates counter nNoUpdatesHum = 0; send(msgHum.set(humidity, 1)); #ifdef MY_DEBUG Serial.print("H: "); Serial.println(humidity); #endif } else { // Increase no update counter if the humidity stayed the same nNoUpdatesHum++; } // Sleep for a while to save energy sleep(UPDATE_INTERVAL); }
Debug information from the sensor:
16 MCO:BGN:INIT NODE,CP=RNNNA---,VER=2.2.0 25 TSM:INIT 26 TSF:WUR:MS=0 33 TSM:INIT:TSP OK 35 TSF:SID:OK,ID=24 37 TSM:FPAR 73 TSF:MSG:SEND,24-24-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 627 TSF:MSG:READ,0-0-24,s=255,c=3,t=8,pt=1,l=1,sg=0:0 632 TSF:MSG:FPAR OK,ID=0,D=1 2081 TSM:FPAR:OK 2082 TSM:ID 2083 TSM:ID:OK 2085 TSM:UPL 2088 TSF:MSG:SEND,24-24-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1 2191 TSF:MSG:READ,0-0-24,s=255,c=3,t=25,pt=1,l=1,sg=0:1 2196 TSF:MSG:PONG RECV,HP=1 2198 TSM:UPL:OK 2200 TSM:READY:ID=24,PAR=0,DIS=1 2204 TSF:MSG:SEND,24-24-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100 2332 TSF:MSG:READ,0-0-24,s=255,c=3,t=15,pt=6,l=2,sg=0:0100 2340 TSF:MSG:SEND,24-24-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.2.0 2349 TSF:MSG:SEND,24-24-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0 2586 TSF:MSG:READ,0-0-24,s=255,c=3,t=6,pt=0,l=1,sg=0:M 2593 TSF:MSG:SEND,24-24-0-0,s=255,c=3,t=11,pt=0,l=22,sg=0,ft=0,st=OK:TemperatureAndHumidity 2604 TSF:MSG:SEND,24-24-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.1 2612 TSF:MSG:SEND,24-24-0-0,s=0,c=0,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 2653 !TSF:MSG:SEND,24-24-0-0,s=1,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=NACK: 2660 MCO:REG:REQ 2663 TSF:MSG:SEND,24-24-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=1,st=OK:2 2938 TSF:MSG:READ,0-0-24,s=255,c=3,t=27,pt=1,l=1,sg=0:1 2944 MCO:PIM:NODE REG=1 2946 MCO:BGN:STP 2952 MCO:SLP:MS=2000,SMS=0,I1=255,M1=255,I2=255,M2=255 2957 TSF:TDI:TSL 2959 MCO:SLP:WUP=-1 2961 TSF:TRI:TSB 2963 MCO:BGN:INIT OK,TSP=1 2972 TSF:MSG:SEND,24-24-0-0,s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:26.8 T: 26.80 2980 TSF:MSG:SEND,24-24-0-0,s=0,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:14.2 H: 14.20 2988 MCO:SLP:MS=10000,SMS=0,I1=255,M1=255,I2=255,M2=255 2993 TSF:TDI:TSL 2995 MCO:SLP:WUP=-1 2997 TSF:TRI:TSB 3005 TSF:MSG:SEND,24-24-0-0,s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:26.5 T: 26.50 3014 TSF:MSG:SEND,24-24-0-0,s=0,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:14.3 H: 14.30 3021 MCO:SLP:MS=10000,SMS=0,I1=255,M1=255,I2=255,M2=255 3026 TSF:TDI:TSL
My node is built on Arduino Nano + NRF24L01+
My gateway node is built on NodeMcu + NRF24L01+
Controller Openhab 2.2 (Openhabian + Raspberry Pi 3)
MySensors library 2.2
-
@vladimir the presentation message for temperature failed (indicated by st=NACK in the log)
Add wait(200); before the presentation line, that usually helps
-
This post is deleted!
-
@mfalkvidd Thank you! Everything worked!
-
@vladimir great! Thanks for reporting back.
-
@mfalkvidd Tell me please, can I somehow unite them in one device? Now this sensor is displayed as two separate devices. But this is one physical device.
-
@vladimir I have no experience with OpenHab. Sorry.
-
@mfalkvidd I assumed that this change is made in the code of the sensor itself. For example, during its presentation.
-
@vladimir in my experience, it is not. Domoticz unites some of my sensors even when I don't want them united. My guess is that OpenHab is equally annoying, but in the other direction.
-
I agree with @mfalkvidd. This is not due to the sensor code but this is the way OH handles the data.
I'm using OH but the MQTT 1.x binding that does not support discovery. I manually define three logical devices, temp, hum and batt in the .items file. I think this is the expected behaviour of OH.
If you want them presented as one device you could combine the measurements into one string by using a rule and do some string manipulation. I do this to combine wind speed and direction into one string.