correct pin and unsigned long time with ZsensorDHT

#48
This commit is contained in:
1technophile committed 2017-05-19 20:15:25 +02:00
1 parent 3b2b740f29
commit 2ea2576d8d
2 files changed
+15 -11

No files matched your search

+3 -3
View File
@@ -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); SoftwareSerial softserial(BT_RX, BT_TX);
unsigned long time1 = 0; unsigned long timebt = 0;
void setupBT() { void setupBT() {
softserial.begin(9600); softserial.begin(9600);
@@ -79,8 +79,8 @@ boolean BTtoMQTT() {
trc(F("Connection OK to HM-10")); trc(F("Connection OK to HM-10"));
} }
} }
if (millis() > (time1 + TimeBtw_Read)) {//retriving value of adresses and rssi if (millis() > (timebt + TimeBtw_Read)) {//retriving value of adresses and rssi
time1 = millis(); timebt = millis();
softserial.print(F(QUESTION_MSG)); softserial.print(F(QUESTION_MSG));
} }
return false; return false;
+12 -8
View File
@@ -26,8 +26,8 @@ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT
#ifdef ZsensorDHT #ifdef ZsensorDHT
#include <DHT.h> #include <DHT.h>
#include <DHT_U.h> #include <DHT_U.h>
#define TimeBetweenReading 60000 #define TimeBetweenReading 30000
DHT dht(6,DHT11); DHT dht(10,DHT22); //on nodeMCU this is SD3
/*----------------------------USER PARAMETERS-----------------------------*/ /*----------------------------USER PARAMETERS-----------------------------*/
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/ /*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
@@ -35,11 +35,11 @@ DHT dht(6,DHT11);
#define TEMP1 "home/433toMQTT/dht1/temp" #define TEMP1 "home/433toMQTT/dht1/temp"
//Time used to wait for an interval before resending temp and hum //Time used to wait for an interval before resending temp and hum
unsigned long time1 = 0; unsigned long timedht = 0;
void MeasureTempAndHum(){ void MeasureTempAndHum(){
if (millis() > (time1 + TimeBetweenReading)) {//retriving value of temperature and humidity of the box from DHT every xUL if (millis() > (timedht + TimeBetweenReading)) {//retriving value of temperature and humidity of the box from DHT every xUL
time1 = millis(); timedht = millis();
float h = dht.readHumidity(); float h = dht.readHumidity();
// Read temperature as Celsius (the default) // Read temperature as Celsius (the default)
float t = dht.readTemperature(); float t = dht.readTemperature();
@@ -47,12 +47,16 @@ void MeasureTempAndHum(){
if (isnan(h) || isnan(t)) { if (isnan(h) || isnan(t)) {
trc(F("Failed to read from DHT sensor!")); trc(F("Failed to read from DHT sensor!"));
}else{ }else{
char temp[5]; char temp[6];
char hum[5]; char hum[6];
dtostrf(t,4,2,temp); dtostrf(t,4,2,temp);
dtostrf(h,4,2,hum); 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(TEMP1,temp);
client.publish(HUM1,hum);
} }
} }
} }