mirror of
https://github.com/anklimov/lighthub
synced 2025-12-07 04:09:49 +03:00
hard and soft reset, dht22 support, reset on lan init error, reset on many mqtt errors
This commit is contained in:
@@ -22,7 +22,7 @@ e-mail anklimov@gmail.com
|
||||
#include "item.h"
|
||||
#include <PubSubClient.h>
|
||||
|
||||
#ifndef WITHOUT_DHT
|
||||
#ifndef DHT_DISABLE
|
||||
#include "DHT.h"
|
||||
#endif
|
||||
|
||||
@@ -96,7 +96,7 @@ int Input::poll() {
|
||||
}
|
||||
|
||||
void Input::dht22Poll() {
|
||||
#ifndef WITHOUT_DHT
|
||||
#ifndef DHT_DISABLE
|
||||
if (store->nextPollMillis > millis())
|
||||
return;
|
||||
DHT dht(pin, DHT22);
|
||||
@@ -110,10 +110,10 @@ void Input::dht22Poll() {
|
||||
char addrstr[100] = "";
|
||||
strcat(addrstr, emit->valuestring);
|
||||
strcat(addrstr, "T");
|
||||
sprintf(valstr, "%2.1f", temp);
|
||||
printFloatValueToStr(temp, valstr);
|
||||
mqttClient.publish(addrstr, valstr);
|
||||
addrstr[strlen(addrstr) - 1] = 'H';
|
||||
sprintf(valstr, "%2.1f", humidity);
|
||||
printFloatValueToStr(humidity, valstr);
|
||||
mqttClient.publish(addrstr, valstr);
|
||||
store->nextPollMillis = millis() + DHT_POLL_DELAY_DEFAULT;
|
||||
Serial.print(" NextPollMillis=");Serial.println(store->nextPollMillis);
|
||||
@@ -123,6 +123,23 @@ void Input::dht22Poll() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void Input::printFloatValueToStr(float temp, char *valstr) {
|
||||
#if defined(__ESP__)
|
||||
sprintf(valstr, "%2.1f", temp);
|
||||
#endif
|
||||
#if defined(__AVR__)
|
||||
sprintf(valstr, "%d", (int)temp);
|
||||
int fractional = 10.0*((float)abs(temp)-(float)abs((int)temp));
|
||||
int val_len =strlen(valstr);
|
||||
valstr[val_len]='.';
|
||||
valstr[val_len+1]='0'+fractional;
|
||||
valstr[val_len+2]='\0';
|
||||
#endif
|
||||
#if defined(__SAM3X8E__)
|
||||
sprintf(valstr, "%2.1f", temp);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Input::contactPoll() {
|
||||
boolean currentInputState;
|
||||
uint8_t inputPinMode, inputOnLevel;
|
||||
|
||||
Reference in New Issue
Block a user