From 2ea2576d8d620a95658f3140ff080ab52f2bc05b Mon Sep 17 00:00:00 2001 From: 1technophile Date: Fri, 19 May 2017 20:15:25 +0200 Subject: [PATCH] correct pin and unsigned long time with ZsensorDHT #48 --- ZgatewayBT.ino | 6 +++--- ZsensorDHT.ino | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/ZgatewayBT.ino b/ZgatewayBT.ino index c2f9c02..1faefa0 100644 --- a/ZgatewayBT.ino +++ b/ZgatewayBT.ino @@ -33,7 +33,7 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht SoftwareSerial softserial(BT_RX, BT_TX); -unsigned long time1 = 0; +unsigned long timebt = 0; void setupBT() { softserial.begin(9600); @@ -79,8 +79,8 @@ boolean BTtoMQTT() { trc(F("Connection OK to HM-10")); } } - if (millis() > (time1 + TimeBtw_Read)) {//retriving value of adresses and rssi - time1 = millis(); + if (millis() > (timebt + TimeBtw_Read)) {//retriving value of adresses and rssi + timebt = millis(); softserial.print(F(QUESTION_MSG)); } return false; diff --git a/ZsensorDHT.ino b/ZsensorDHT.ino index 904c083..4275a90 100644 --- a/ZsensorDHT.ino +++ b/ZsensorDHT.ino @@ -26,8 +26,8 @@ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT #ifdef ZsensorDHT #include #include -#define TimeBetweenReading 60000 -DHT dht(6,DHT11); +#define TimeBetweenReading 30000 +DHT dht(10,DHT22); //on nodeMCU this is SD3 /*----------------------------USER PARAMETERS-----------------------------*/ /*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/ @@ -35,11 +35,11 @@ DHT dht(6,DHT11); #define TEMP1 "home/433toMQTT/dht1/temp" //Time used to wait for an interval before resending temp and hum -unsigned long time1 = 0; +unsigned long timedht = 0; void MeasureTempAndHum(){ - if (millis() > (time1 + TimeBetweenReading)) {//retriving value of temperature and humidity of the box from DHT every xUL - time1 = millis(); + if (millis() > (timedht + TimeBetweenReading)) {//retriving value of temperature and humidity of the box from DHT every xUL + timedht = millis(); float h = dht.readHumidity(); // Read temperature as Celsius (the default) float t = dht.readTemperature(); @@ -47,12 +47,16 @@ void MeasureTempAndHum(){ if (isnan(h) || isnan(t)) { trc(F("Failed to read from DHT sensor!")); }else{ - char temp[5]; - char hum[5]; + char temp[6]; + char hum[6]; dtostrf(t,4,2,temp); dtostrf(h,4,2,hum); - client.publish(HUM1,hum); + trc(F("Sending Temp and Hum to MQTT")); + trc(String(hum)); + trc(String(temp)); client.publish(TEMP1,temp); + client.publish(HUM1,hum); + } } }