Add raw data to MS01 JSON

This commit is contained in:
Theo Arends 2022-04-12 16:28:32 +02:00
parent 727b207ccc
commit b8cf5eee7c
2 changed files with 10 additions and 7 deletions

View File

@ -649,8 +649,8 @@ void CmndStatus(void)
(uint32_t)WiFi.localIP(), Settings->ipv4_address[1], Settings->ipv4_address[2], (uint32_t)WiFi.localIP(), Settings->ipv4_address[1], Settings->ipv4_address[2],
Settings->ipv4_address[3], Settings->ipv4_address[4], Settings->ipv4_address[3], Settings->ipv4_address[4],
WiFi.macAddress().c_str()); WiFi.macAddress().c_str());
#if defined USE_TASMESH #ifdef USE_TASMESH
ResponseAppend_P(PSTR(",\"Soft AP Mac\":\"%s\""), WiFi.softAPmacAddress().c_str()); ResponseAppend_P(PSTR(",\"SoftAPMac\":\"%s\""), WiFi.softAPmacAddress().c_str());
#endif // USE_TASMESH #endif // USE_TASMESH
#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) #if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET)
ResponseAppend_P(PSTR(",\"Ethernet\":{\"" D_CMND_HOSTNAME "\":\"%s\",\"" ResponseAppend_P(PSTR(",\"Ethernet\":{\"" D_CMND_HOSTNAME "\":\"%s\",\""

View File

@ -45,12 +45,13 @@ bool dht_active = true; // DHT configured
bool dht_dual_mode = false; // Single pin mode bool dht_dual_mode = false; // Single pin mode
struct DHTSTRUCT { struct DHTSTRUCT {
float t = NAN;
float h = NAN;
int16_t raw;
char stype[12];
int8_t pin; int8_t pin;
uint8_t type; uint8_t type;
uint8_t lastresult; uint8_t lastresult;
char stype[12];
float t = NAN;
float h = NAN;
} Dht[DHT_MAX_SENSORS]; } Dht[DHT_MAX_SENSORS];
bool DhtWaitState(uint32_t sensor, uint32_t level) { bool DhtWaitState(uint32_t sensor, uint32_t level) {
@ -167,7 +168,7 @@ bool DhtRead(uint32_t sensor) {
break; break;
} }
case GPIO_MS01: { // Sonoff MS01 case GPIO_MS01: { // Sonoff MS01
int32_t voltage = ((dht_data[0] << 8) | dht_data[1]); int16_t voltage = ((dht_data[0] << 8) | dht_data[1]);
// AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("DHT: MS01 %d"), voltage); // AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("DHT: MS01 %d"), voltage);
@ -187,6 +188,7 @@ bool DhtRead(uint32_t sensor) {
humidity = - FastPrecisePowf(0.00046 * x, 3) - 0.0004 * x + 15; humidity = - FastPrecisePowf(0.00046 * x, 3) - 0.0004 * x + 15;
} }
temperature = 0; temperature = 0;
Dht[sensor].raw = voltage;
break; break;
} }
} }
@ -264,7 +266,8 @@ void DhtShow(bool json) {
for (uint32_t i = 0; i < dht_sensors; i++) { for (uint32_t i = 0; i < dht_sensors; i++) {
if (GPIO_MS01 == Dht[i].type) { if (GPIO_MS01 == Dht[i].type) {
if (json) { if (json) {
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_HUMIDITY "\":%*_f}"), Dht[i].stype, Settings->flag2.humidity_resolution, &Dht[i].h); ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_HUMIDITY "\":%*_f,\"Raw\":%d}"),
Dht[i].stype, Settings->flag2.humidity_resolution, &Dht[i].h, Dht[i].raw);
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
} else { } else {
char parameter[FLOATSZ]; char parameter[FLOATSZ];