mirror of https://github.com/arendst/Tasmota.git
v5.7.1b - Add timeout to some sensors
5.7.1b * Add timeout to DHT and DS18B20 sensors (#852)
This commit is contained in:
parent
0151188652
commit
105c5d7129
|
@ -1,7 +1,7 @@
|
|||
## Sonoff-Tasmota
|
||||
Provide ESP8266 based Sonoff by [iTead Studio](https://www.itead.cc/) and ElectroDragon IoT Relay with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE.
|
||||
|
||||
Current version is **5.7.1a** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
|
||||
Current version is **5.7.1b** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
|
||||
|
||||
### ATTENTION All versions
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
/* 5.7.1a
|
||||
/* 5.7.1b
|
||||
* Add timeout to DHT and DS18B20 sensors (#852)
|
||||
*
|
||||
* 5.7.1a
|
||||
* Fix Domoticz loop when Emulation is selected
|
||||
* Add GPIO14 to Sonoff Dual (#797, #839)
|
||||
* Add support for Witty Cloud (#794)
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
- Select IDE Tools - Flash Size: "1M (no SPIFFS)"
|
||||
====================================================*/
|
||||
|
||||
#define VERSION 0x05070101 // 5.7.1a
|
||||
#define VERSION 0x05070102 // 5.7.1b
|
||||
|
||||
enum log_t {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL};
|
||||
enum week_t {Last, First, Second, Third, Fourth};
|
||||
|
|
|
@ -38,7 +38,7 @@ struct DHTSTRUCT {
|
|||
byte type;
|
||||
char stype[10];
|
||||
uint32_t lastreadtime;
|
||||
bool lastresult;
|
||||
uint16_t lastresult;
|
||||
float t;
|
||||
float h = 0;
|
||||
} dht[DHT_MAX_SENSORS];
|
||||
|
@ -62,14 +62,14 @@ uint32_t dht_expectPulse(byte sensor, bool level)
|
|||
return count;
|
||||
}
|
||||
|
||||
boolean dht_read(byte sensor)
|
||||
void dht_read(byte sensor)
|
||||
{
|
||||
char log[LOGSZ];
|
||||
uint32_t cycles[80];
|
||||
uint32_t currenttime = millis();
|
||||
|
||||
if ((currenttime - dht[sensor].lastreadtime) < 2000) {
|
||||
return dht[sensor].lastresult;
|
||||
return;
|
||||
}
|
||||
dht[sensor].lastreadtime = currenttime;
|
||||
|
||||
|
@ -89,13 +89,13 @@ boolean dht_read(byte sensor)
|
|||
delayMicroseconds(10);
|
||||
if (0 == dht_expectPulse(sensor, LOW)) {
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_START_SIGNAL_LOW " " D_PULSE));
|
||||
dht[sensor].lastresult = false;
|
||||
return dht[sensor].lastresult;
|
||||
dht[sensor].lastresult++;
|
||||
return;
|
||||
}
|
||||
if (0 == dht_expectPulse(sensor, HIGH)) {
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_START_SIGNAL_HIGH " " D_PULSE));
|
||||
dht[sensor].lastresult = false;
|
||||
return dht[sensor].lastresult;
|
||||
dht[sensor].lastresult++;
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < 80; i += 2) {
|
||||
cycles[i] = dht_expectPulse(sensor, LOW);
|
||||
|
@ -108,8 +108,8 @@ boolean dht_read(byte sensor)
|
|||
uint32_t highCycles = cycles[2*i+1];
|
||||
if ((0 == lowCycles) || (0 == highCycles)) {
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_PULSE));
|
||||
dht[sensor].lastresult = false;
|
||||
return dht[sensor].lastresult;
|
||||
dht[sensor].lastresult++;
|
||||
return;
|
||||
}
|
||||
dht_data[i/8] <<= 1;
|
||||
if (highCycles > lowCycles) {
|
||||
|
@ -122,12 +122,11 @@ boolean dht_read(byte sensor)
|
|||
addLog(LOG_LEVEL_DEBUG, log);
|
||||
|
||||
if (dht_data[4] == ((dht_data[0] + dht_data[1] + dht_data[2] + dht_data[3]) & 0xFF)) {
|
||||
dht[sensor].lastresult = true;
|
||||
dht[sensor].lastresult = 0;
|
||||
} else {
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_CHECKSUM_FAILURE));
|
||||
dht[sensor].lastresult = false;
|
||||
dht[sensor].lastresult++;
|
||||
}
|
||||
return dht[sensor].lastresult;
|
||||
}
|
||||
|
||||
boolean dht_readTempHum(byte sensor, float &t, float &h)
|
||||
|
@ -136,11 +135,16 @@ boolean dht_readTempHum(byte sensor, float &t, float &h)
|
|||
t = NAN;
|
||||
h = NAN;
|
||||
} else {
|
||||
if (dht[sensor].lastresult > 8) { // Reset after 8 misses
|
||||
dht[sensor].t = NAN;
|
||||
dht[sensor].h = NAN;
|
||||
}
|
||||
t = dht[sensor].t;
|
||||
h = dht[sensor].h;
|
||||
}
|
||||
|
||||
if (dht_read(sensor)) {
|
||||
dht_read(sensor);
|
||||
if (!dht[sensor].lastresult) {
|
||||
switch (dht[sensor].type) {
|
||||
case GPIO_DHT11:
|
||||
h = dht_data[0];
|
||||
|
@ -193,7 +197,8 @@ void dht_init()
|
|||
|
||||
for (byte i = 0; i < dht_sensors; i++) {
|
||||
pinMode(dht[i].pin, INPUT_PULLUP);
|
||||
dht[i].lastreadtime = -MIN_INTERVAL;
|
||||
dht[i].lastreadtime -= MIN_INTERVAL;
|
||||
dht[i].lastresult = 0;
|
||||
switch (dht[i].type) {
|
||||
case GPIO_DHT11:
|
||||
strcpy_P(dht[i].stype, PSTR("DHT11"));
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
\*********************************************************************************************/
|
||||
|
||||
float dsb_mt = 0;
|
||||
uint16_t dsb_lastresult = 0;
|
||||
|
||||
uint8_t dsb_reset()
|
||||
{
|
||||
|
@ -131,6 +132,10 @@ boolean dsb_readTemp(float &t)
|
|||
if (!dsb_mt) {
|
||||
t = NAN;
|
||||
} else {
|
||||
dsb_lastresult++;
|
||||
if (dsb_lastresult > 8) { // Reset after 8 misses
|
||||
dsb_mt = NAN;
|
||||
}
|
||||
t = dsb_mt;
|
||||
}
|
||||
|
||||
|
@ -168,8 +173,11 @@ boolean dsb_readTemp(float &t)
|
|||
sign = -1;
|
||||
}
|
||||
t = convertTemp((float)sign * DSTemp * 0.0625);
|
||||
dsb_lastresult = 0;
|
||||
}
|
||||
if (!isnan(t)) {
|
||||
dsb_mt = t;
|
||||
}
|
||||
if (!isnan(t)) dsb_mt = t;
|
||||
return !isnan(t);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue