mirror of https://github.com/arendst/Tasmota.git
Updating to work with new web/mqtt api
This commit is contained in:
parent
17a5e90e86
commit
d375d95529
|
@ -517,7 +517,7 @@ const char S_JSON_DRIVER_INDEX_SVALUE[] PROGMEM = "{\"" D_CMND_DRIVE
|
|||
const char JSON_SNS_TEMP[] PROGMEM = ",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s}";
|
||||
const char JSON_SNS_TEMPHUM[] PROGMEM = ",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_HUMIDITY "\":%s}";
|
||||
|
||||
const char JSON_SNS_GNGPM[] PROGMEM = "%s,\"%s\":{\"" D_JSON_TOTAL_USAGE "\":%s,\"" D_JSON_FLOWRATE "\":%s}";
|
||||
const char JSON_SNS_GNGPM[] PROGMEM = ",\"%s\":{\"" D_JSON_TOTAL_USAGE "\":%s,\"" D_JSON_FLOWRATE "\":%s}";
|
||||
|
||||
const char S_LOG_I2C_FOUND_AT[] PROGMEM = D_LOG_I2C "%s " D_FOUND_AT " 0x%x";
|
||||
|
||||
|
|
|
@ -494,6 +494,9 @@
|
|||
#define D_TX20_SOUTH "S"
|
||||
#define D_TX20_WEST "W"
|
||||
|
||||
//xsns_91_hre.ino
|
||||
#define D_LOG_HRE "HRE: "
|
||||
|
||||
// sonoff_template.h - keep them as short as possible to be able to fit them in GUI drop down box
|
||||
#define D_SENSOR_NONE "None"
|
||||
#define D_SENSOR_USER "User"
|
||||
|
|
|
@ -131,7 +131,6 @@ void hreEvery50ms(void)
|
|||
static int read_counter = 0; // number of bytes in the current read
|
||||
static int parity_errors = 0; // Number of parity errors in current read
|
||||
static char buff[46]; // 8 char and a term
|
||||
static char aux[46]; // 8 char and a term
|
||||
|
||||
static char ch;
|
||||
static size_t i;
|
||||
|
@ -144,8 +143,7 @@ void hreEvery50ms(void)
|
|||
sync_run = 0;
|
||||
sync_counter = 0;
|
||||
hre_state = hre_syncing;
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("HRE: state:syncing"));
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HRE "hre_state:hre_syncing"));
|
||||
break;
|
||||
|
||||
case hre_syncing:
|
||||
|
@ -169,40 +167,34 @@ void hreEvery50ms(void)
|
|||
if (sync_counter > 1000)
|
||||
{
|
||||
hre_state = hre_sleep;
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("HRE: sync error"));
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HRE D_ERROR));
|
||||
}
|
||||
break;
|
||||
|
||||
// Start reading the data block
|
||||
case hre_read:
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("HRE: sync_run:%d, sync_counter:%d"), sync_run, sync_counter);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_HRE " sync_run:%d, sync_counter:%d"), sync_run, sync_counter);
|
||||
read_counter = 0;
|
||||
parity_errors = 0;
|
||||
curr_start = uptime;
|
||||
memset(buff, 0, sizeof(buff));
|
||||
hre_state = hre_reading;
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("HRE: state:reading"));
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HRE "hre_state:hre_reading"));
|
||||
// So this is intended to fall through to the hre_reading section.
|
||||
// it seems that if there is much of a delay between getting the sync
|
||||
// bits and starting the read, the HRE won't output the message we
|
||||
// are looking for...
|
||||
|
||||
case hre_reading:
|
||||
//ch = hreReadChar(parity_errors);
|
||||
//i = read_counter - 24; // The water usage reading starts 24 bytes into the block
|
||||
//if (i>=0 && i<sizeof(buff))
|
||||
// buff[i] = ch;
|
||||
|
||||
//KG44?Q45484=0444444V;RB000000022;IB018435683
|
||||
// RB003119173;IB018435683
|
||||
buff[read_counter] = hreReadChar(parity_errors);
|
||||
|
||||
read_counter++;
|
||||
if (read_counter == 46)
|
||||
{
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("HRE: pe:%d, buff:%s"), parity_errors, buff);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
//buff[33]='\0';
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_HRE " pe:%d, buff:%s"), parity_errors, buff);
|
||||
if (parity_errors == 0)
|
||||
{
|
||||
float curr_usage;
|
||||
|
@ -215,8 +207,7 @@ void hreEvery50ms(void)
|
|||
hre_usage = curr_usage;
|
||||
hre_usage_time = curr_start;
|
||||
hre_good = true;
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("HRE: usage:%.2f, rate:%.3f"), hre_usage, hre_rate);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_HRE " usage:%d, rate:%d"), int(100*hre_usage), int(100*hre_rate));
|
||||
hre_state = hre_sleep;
|
||||
}
|
||||
else
|
||||
|
@ -230,8 +221,7 @@ void hreEvery50ms(void)
|
|||
case hre_sleep:
|
||||
hre_usage_time = curr_start;
|
||||
hre_state = hre_sleeping;
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("HRE: state:sleeping"));
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HRE "hre_state:hre_sleeping"));
|
||||
|
||||
case hre_sleeping:
|
||||
if (uptime - hre_usage_time > 27)
|
||||
|
@ -244,7 +234,7 @@ void hreShow(boolean json)
|
|||
if (!hre_good)
|
||||
return;
|
||||
|
||||
const char hre_types[] = "HRE";
|
||||
const char *id = "HRE";
|
||||
|
||||
char usage[33];
|
||||
char rate[33];
|
||||
|
@ -253,13 +243,13 @@ void hreShow(boolean json)
|
|||
|
||||
if (json)
|
||||
{
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_GNGPM, mqtt_data, hre_types, usage, rate);
|
||||
ResponseAppend_P(JSON_SNS_GNGPM, id, usage, rate);
|
||||
#ifdef USE_WEBSERVER
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_GALLONS, mqtt_data, hre_types, usage);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_GPM, mqtt_data, hre_types, rate);
|
||||
WSContentSend_PD(HTTP_SNS_GALLONS, id, usage);
|
||||
WSContentSend_PD(HTTP_SNS_GPM, id, rate);
|
||||
#endif // USE_WEBSERVER
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue