can't get DHT22 sensor to work with home assistant via mqtt gateway
-
pi@bereskapi-ha:~/MySensors $ sudo ./bin/mysgw Nov 04 06:26:41 INFO Starting gateway... Nov 04 06:26:41 INFO Protocol version - 2.3.1-beta Nov 04 06:26:41 DEBUG MCO:BGN:INIT GW,CP=RNNGL---,VER=2.3.1-beta Nov 04 06:26:41 DEBUG TSF:LRT:OK Nov 04 06:26:41 DEBUG TSM:INIT Nov 04 06:26:41 DEBUG TSF:WUR:MS=0 Nov 04 06:26:41 DEBUG TSM:INIT:TSP OK Nov 04 06:26:41 DEBUG TSM:INIT:GW MODE Nov 04 06:26:41 DEBUG TSM:READY:ID=0,PAR=0,DIS=0 Nov 04 06:26:41 DEBUG MCO:REG:NOT NEEDED Nov 04 06:26:41 DEBUG MCO:BGN:STP Nov 04 06:26:41 DEBUG MCO:BGN:INIT OK,TSP=1 Nov 04 06:26:41 DEBUG GWT:RMQ:MQTT RECONNECT Nov 04 06:26:41 DEBUG connected to 127.0.0.1 Nov 04 06:26:41 DEBUG GWT:RMQ:MQTT CONNECTED Nov 04 06:26:41 DEBUG GWT:TPS:TOPIC=mygateway1-out/0/255/0/0/18,MSG SENT Nov 04 06:26:41 DEBUG TSM:READY:NWD REQ Nov 04 06:26:41 DEBUG TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK: Nov 04 06:27:16 DEBUG TSF:MSG:READ,1-1-255,s=255,c=3,t=7,pt=0,l=0,sg=0: Nov 04 06:27:16 DEBUG TSF:MSG:BC Nov 04 06:27:16 DEBUG TSF:MSG:FPAR REQ,ID=1 Nov 04 06:27:16 DEBUG TSF:PNG:SEND,TO=0 Nov 04 06:27:16 DEBUG TSF:CKU:OK Nov 04 06:27:16 DEBUG TSF:MSG:GWL OK Nov 04 06:27:16 DEBUG !TSF:MSG:SEND,0-0-1-1,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=NACK:0 Nov 04 06:27:18 DEBUG TSF:MSG:READ,1-1-255,s=255,c=3,t=7,pt=0,l=0,sg=0: Nov 04 06:27:18 DEBUG TSF:MSG:BC Nov 04 06:27:18 DEBUG TSF:MSG:FPAR REQ,ID=1 Nov 04 06:27:18 DEBUG TSF:CKU:OK,FCTRL Nov 04 06:27:18 DEBUG TSF:MSG:GWL OK Nov 04 06:27:18 DEBUG !TSF:MSG:SEND,0-0-1-1,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=NACK:0 Nov 04 06:27:20 DEBUG TSF:MSG:READ,1-1-255,s=255,c=3,t=7,pt=0,l=0,sg=0: Nov 04 06:27:20 DEBUG TSF:MSG:BC Nov 04 06:27:20 DEBUG TSF:MSG:FPAR REQ,ID=1 Nov 04 06:27:20 DEBUG TSF:CKU:OK,FCTRL Nov 04 06:27:20 DEBUG TSF:MSG:GWL OK Nov 04 06:27:20 DEBUG !TSF:MSG:SEND,0-0-1-1,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=NACK:0 Nov 04 06:27:22 DEBUG TSF:MSG:READ,1-1-255,s=255,c=3,t=7,pt=0,l=0,sg=0: Nov 04 06:27:22 DEBUG TSF:MSG:BC Nov 04 06:27:22 DEBUG TSF:MSG:FPAR REQ,ID=1 Nov 04 06:27:22 DEBUG TSF:CKU:OK,FCTRL Nov 04 06:27:22 DEBUG TSF:MSG:GWL OK Nov 04 06:27:22 DEBUG !TSF:MSG:SEND,0-0-1-1,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=NACK:0
my DHT22 sketch:
#include <DHT.h> #include <SPI.h> #define MY_DEBUG #define MY_RADIO_NRF24 #define MY_NODE_ID 22 #define CHILD_ID_TEMP 0 #define CHILD_ID_HUM 1 #define DHT_DATA_PIN 3 #define SENSOR_TEMP_OFFSET 0 #include <MySensors.h> /**************************************************/ /****************** CONSTANTS *********************/ /**************************************************/ static const uint64_t UPDATE_INTERVAL = 10000; static const uint8_t FORCE_UPDATE_N_READS = 10; /**************************************************/ /****************** VARIABLES *********************/ /**************************************************/ float lastTemp; float lastHum; float temperature; float humidity; uint8_t nNoUpdatesTemp; uint8_t nNoUpdatesHum; /**************************************************/ /****************** MESSAGES **********************/ /**************************************************/ MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); DHT dht; void presentation() { sendSketchInfo("DHT22", "1.0"); present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_TEMP, S_TEMP); } void setup() { delay(2000); //Wait 2 seconds before starting sequence if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) { Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!"); } sleep(dht.getMinimumSamplingPeriod()); dht.setup(DHT_DATA_PIN); } void loop() { sendTemperatureHumiditySensor(); wait(UPDATE_INTERVAL); } /**************************************************/ /**************** AUX. FUNCTIONS ******************/ /**************************************************/ void sendTemperatureHumiditySensor() { dht.readSensor(true); temperature = dht.getTemperature(); humidity = dht.getHumidity(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT!"); } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) { lastTemp = temperature; nNoUpdatesTemp = 0; temperature += SENSOR_TEMP_OFFSET; send(msgTemp.set(temperature, 1)); #ifdef MY_DEBUG Serial.print("T: "); Serial.println(temperature); #endif } else { nNoUpdatesTemp++; } if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) { lastHum = humidity; nNoUpdatesHum = 0; send(msgHum.set(humidity, 1)); #ifdef MY_DEBUG Serial.print("H: "); Serial.println(humidity); #endif } else { nNoUpdatesHum++; } }
-
Hi @bereska, welcome to the MySensors community
For next time, could you put the code in a code box? Instructions are available here. I took the liberty to fix it for you this time. Please also use the Auto format (ctrl/cmd+T) feature in the Arduino IDE, which makes it much easier to read the code.
https://forum.mysensors.org/topic/666/debug-faq-and-how-ask-for-help/ has information on the most common problems, and how to troubleshoot them.
The log parser can help understand the log messages.
The log you posted shows that the gateway is receiving messages from node 1, but there is nothing from node 22. The deubg log from node22 will probably give information on why it is having trouble.
-
Hi @mfalkvidd
thank you for your prompt reply
I promise i will follow the rules
i'm very new to this, please bear with me)
I've spent all this time studying logs and trying different nrf24 radios (standard & LNA), but no dice(
please help
here is the last log from the Arduino serial read:14:57:02.641 -> __ __ ____ 14:57:02.641 -> | \/ |_ _/ ___| ___ _ __ ___ ___ _ __ ___ 14:57:02.641 -> | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __| 14:57:02.641 -> | | | | |_| |___| | __/ | | \__ \ _ | | \__ \ 14:57:02.674 -> |_| |_|\__, |____/ \___|_| |_|___/\___/|_| |___/ 14:57:02.674 -> |___/ 2.3.0 14:57:02.674 -> 14:57:02.674 -> 16 MCO:BGN:INIT NODE,CP=RNNNA---,VER=2.3.0 14:57:02.674 -> 25 TSM:INIT 14:57:02.674 -> 26 TSF:WUR:MS=0 14:57:02.674 -> 33 TSM:INIT:TSP OK 14:57:02.674 -> 35 TSM:INIT:STATID=22 14:57:02.674 -> 37 TSF:SID:OK,ID=22 14:57:02.674 -> 39 TSM:FPAR 75 TSF:MSG:SEND,22-22-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 2082 !TSM:FPAR:NO REPLY 14:57:04.710 -> 2084 TSM:FPAR 2120 TSF:MSG:SEND,22-22-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 4128 !TSM:FPAR:NO REPLY 14:57:06.751 -> 4130 TSM:FPAR 4166 TSF:MSG:SEND,22-22-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 6174 !TSM:FPAR:NO REPLY 14:57:08.807 -> 6176 TSM:FPAR 6212 TSF:MSG:SEND,22-22-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 8220 !TSM:FPAR:FAIL 14:57:10.863 -> 8221 TSM:FAIL:CNT=1 14:57:10.863 -> 8223 TSM:FAIL:DIS 14:57:10.863 -> 8225 TSF:TDI:TSL 18227 TSM:FAIL:RE-INIT 14:57:20.837 -> 18229 TSM:INIT 14:57:20.837 -> 18236 TSM:INIT:TSP OK 14:57:20.837 -> 18238 TSM:INIT:STATID=22 14:57:20.871 -> 18240 TSF:SID:OK,ID=22 14:57:20.871 -> 18242 TSM:FPAR```
-
hi again
I got it workingInsex00|⸮⸮E⸮V⸮U⸮ 23:24:18.693 -> __ __ ____ 23:24:18.693 -> | \/ |_ _/ ___| ___ _ __ ___ ___ _ __ ___ 23:24:18.693 -> | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __| 23:24:18.693 -> | | | | |_| |___| | __/ | | \__ \ _ | | \__ \ 23:24:18.728 -> |_| |_|\__, |____/ \___|_| |_|___/\___/|_| |___/ 23:24:18.728 -> |___/ 2.3.0 23:24:18.728 -> 23:24:18.728 -> 16 MCO:BGN:INIT NODE,CP=RNNNA---,VER=2.3.0 23:24:18.728 -> 25 TSM:INIT 23:24:18.728 -> 26 TSF:WUR:MS=0 23:24:18.728 -> 33 TSM:INIT:TSP OK 23:24:18.728 -> 35 TSM:INIT:STATID=22 23:24:18.728 -> 37 TSF:SID:OK,ID=22 23:24:18.728 -> 39 TSM:FPAR 75 TSF:MSG:SEND,22-22-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 880 TSF:MSG:READ,0-0-22,s=255,c=3,t=8,pt=1,l=1,sg=0:0 23:24:19.581 -> 885 TSF:MSG:FPAR OK,ID=0,D=1 2082 TSM:FPAR:OK 23:24:20.765 -> 2083 TSM:ID 23:24:20.765 -> 2084 TSM:ID:OK 23:24:20.800 -> 2086 TSM:UPL 23:24:20.800 -> 2089 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1 23:24:20.800 -> 2096 TSF:MSG:READ,0-0-22,s=255,c=3,t=25,pt=1,l=1,sg=0:1 23:24:20.800 -> 2101 TSF:MSG:PONG RECV,HP=1 23:24:20.800 -> 2104 TSM:UPL:OK 23:24:20.800 -> 2105 TSM:READY:ID=22,PAR=0,DIS=1 23:24:20.800 -> 2110 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100 23:24:20.800 -> 2116 TSF:MSG:READ,0-0-22,s=255,c=3,t=15,pt=6,l=2,sg=0:0100 23:24:20.833 -> 2126 TSF:MSG:SEND,22-22-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.0 23:24:20.833 -> 2135 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0 4142 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=11,pt=0,l=5,sg=0,ft=0,st=OK:DHT22 23:24:22.854 -> 4151 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0 23:24:22.854 -> 4159 TSF:MSG:SEND,22-22-0-0,s=1,c=0,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 23:24:22.854 -> 4166 TSF:MSG:SEND,22-22-0-0,s=0,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK: 23:24:22.854 -> 4172 MCO:REG:REQ 23:24:22.854 -> 4176 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2 23:24:22.890 -> 4183 TSF:MSG:READ,0-0-22,s=255,c=3,t=27,pt=1,l=1,sg=0:1 23:24:22.890 -> 4188 MCO:PIM:NODE REG=1 23:24:22.890 -> 4190 MCO:BGN:STP 6192 MCO:SLP:MS=2000,SMS=0,I1=255,M1=255,I2=255,M2=255 23:24:24.891 -> 6197 TSF:TDI:TSL 6199 MCO:SLP:WUP=-1 23:24:27.107 -> 6200 TSF:TRI:TSB 6207 MCO:BGN:INIT OK,TSP=1 23:24:27.142 -> Failed reading temperature from DHT! 23:24:27.142 -> Failed reading humidity from DHT 16218 TSF:MSG:SEND,22-22-0-0,s=0,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:24.9 23:24:37.137 -> T: 24.90 23:24:37.137 -> 16227 TSF:MSG:SEND,22-22-0-0,s=1,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:51.7 23:24:37.137 -> H: 51.70 26242 TSF:MSG:SEND,22-22-0-0,s=0,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:24.8 23:24:47.138 -> T: 24.80 23:24:47.138 -> 26251 TSF:MSG:SEND,22-22-0-0,s=1,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:51.9 23:24:47.138 -> H: 51.90 rt Code Here
but the sensor fails to show up in home assistant dashboard(
afrter restarting homeassistant I found this in homeassistant log:018-11-06 05:40:14 INFO (MainThread) [mysensors] Stopping gateway Config directory: /config starting version 3.2.5 2018-11-06 05:40:34 INFO (MainThread) [homeassistant.loader] Loaded websocket_api from homeassistant.components.websocket_api 2018-11-06 05:40:34 INFO (MainThread) [homeassistant.bootstrap] Home Assistant core initialized 2018-11-06 05:40:34 INFO (MainThread) [homeassistant.loader] Loaded history from homeassistant.components.history 2018-11-06 05:40:34 INFO (MainThread) [homeassistant.loader] Loaded recorder from homeassistant.components.recorder 2018-11-06 05:40:34 INFO (MainThread) [homeassistant.loader] Loaded http from homeassistant.components.http 2018-11-06 05:40:34 INFO (MainThread) [homeassistant.loader] Loaded mqtt from homeassistant.components.mqtt 2018-11-06 05:40:34 INFO (MainThread) [homeassistant.setup] Setting up mqtt 2018-11-06 05:40:34 INFO (MainThread) [homeassistant.setup] Setup of domain mqtt took 0.0 seconds. 2018-11-06 05:40:34 INFO (MainThread) [homeassistant.loader] Loaded logger from homeassistant.components.logger 2018-11-06 05:40:34 INFO (MainThread) [homeassistant.setup] Setting up logger 2018-11-06 05:40:34 ERROR (MainThread) [homeassistant.components.mqtt] Failed to connect due to exception: [Errno 111] Connection refused 2018-11-06 05:40:40 WARNING (MainThread) [homeassistant.components.mysensors] debug option for mysensors is deprecated. Please remove debug from your configuration file 2018-11-06 05:40:40 DEBUG (SyncWorker_0) [mysensors.persistence] Loading sensors from persistence file /config/mysensors1.pickle 2018-11-06 05:40:41 DEBUG (SyncWorker_1) [mysensors.persistence] Saving sensors to persistence file /config/mysensors1.pickle 2018-11-06 05:40:42 INFO (MainThread) [mysensors.gateway_mqtt] Setting up initial MQTT topic subscription 2018-11-06 05:40:42 DEBUG (MainThread) [mysensors.gateway_mqtt] Subscribing to: mygateway1-out/+/+/0/+/+, qos: 0 2018-11-06 05:40:42 DEBUG (MainThread) [mysensors.gateway_mqtt] Subscribing to: mygateway1-out/+/+/3/+/+, qos: 0 2018-11-06 05:40:42 DEBUG (MainThread) [mysensors.gateway_mqtt] Subscribing to: mygateway1-out/0/+/4/+/+, qos: 0 2018-11-06 05:40:42 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to mygateway1-out/+/+/0/+/+ 2018-11-06 05:40:42 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to mygateway1-out/+/+/3/+/+ 2018-11-06 05:40:42 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to mygateway1-out/0/+/4/+/+ 2018-11-06 05:40:43 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 279, in async_subscribe topic, msg_callback, qos, encoding) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 659, in async_subscribe await self._async_perform_subscription(topic, qos) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 694, in _async_perform_subscription _raise_on_error(result) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 779, in _raise_on_error 'Error talking to MQTT: {}'.format(mqtt.error_string(result_code))) homeassistant.exceptions.HomeAssistantError: Error talking to MQTT: The client is not currently connected. 2018-11-06 05:40:43 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 279, in async_subscribe topic, msg_callback, qos, encoding) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 659, in async_subscribe await self._async_perform_subscription(topic, qos) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 694, in _async_perform_subscription _raise_on_error(result) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 779, in _raise_on_error 'Error talking to MQTT: {}'.format(mqtt.error_string(result_code))) homeassistant.exceptions.HomeAssistantError: Error talking to MQTT: The client is not currently connected. 2018-11-06 05:40:43 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 279, in async_subscribe topic, msg_callback, qos, encoding) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 659, in async_subscribe await self._async_perform_subscription(topic, qos) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 694, in _async_perform_subscription _raise_on_error(result) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 779, in _raise_on_error 'Error talking to MQTT: {}'.format(mqtt.error_string(result_code))) homeassistant.exceptions.HomeAssistantError: Error talking to MQTT: The client is not currently connected. 2018-11-06 05:40:50 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting 2018-11-06 05:40:54 WARNING (SyncWorker_9) [netdisco.ssdp] Error fetching description at http://192.168.1.68:49152/wps_device.xml
any help is much appreciated
thank you