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_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_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";
|
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_SOUTH "S"
|
||||||
#define D_TX20_WEST "W"
|
#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
|
// 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_NONE "None"
|
||||||
#define D_SENSOR_USER "User"
|
#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 read_counter = 0; // number of bytes in the current read
|
||||||
static int parity_errors = 0; // Number of parity errors in 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 buff[46]; // 8 char and a term
|
||||||
static char aux[46]; // 8 char and a term
|
|
||||||
|
|
||||||
static char ch;
|
static char ch;
|
||||||
static size_t i;
|
static size_t i;
|
||||||
|
@ -144,8 +143,7 @@ void hreEvery50ms(void)
|
||||||
sync_run = 0;
|
sync_run = 0;
|
||||||
sync_counter = 0;
|
sync_counter = 0;
|
||||||
hre_state = hre_syncing;
|
hre_state = hre_syncing;
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR("HRE: state:syncing"));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HRE "hre_state:hre_syncing"));
|
||||||
AddLog(LOG_LEVEL_DEBUG);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case hre_syncing:
|
case hre_syncing:
|
||||||
|
@ -169,40 +167,34 @@ void hreEvery50ms(void)
|
||||||
if (sync_counter > 1000)
|
if (sync_counter > 1000)
|
||||||
{
|
{
|
||||||
hre_state = hre_sleep;
|
hre_state = hre_sleep;
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR("HRE: sync error"));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HRE D_ERROR));
|
||||||
AddLog(LOG_LEVEL_DEBUG);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Start reading the data block
|
// Start reading the data block
|
||||||
case hre_read:
|
case hre_read:
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR("HRE: sync_run:%d, sync_counter:%d"), sync_run, sync_counter);
|
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_HRE " sync_run:%d, sync_counter:%d"), sync_run, sync_counter);
|
||||||
AddLog(LOG_LEVEL_DEBUG);
|
|
||||||
read_counter = 0;
|
read_counter = 0;
|
||||||
parity_errors = 0;
|
parity_errors = 0;
|
||||||
curr_start = uptime;
|
curr_start = uptime;
|
||||||
memset(buff, 0, sizeof(buff));
|
memset(buff, 0, sizeof(buff));
|
||||||
hre_state = hre_reading;
|
hre_state = hre_reading;
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR("HRE: state:reading"));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HRE "hre_state:hre_reading"));
|
||||||
AddLog(LOG_LEVEL_DEBUG);
|
|
||||||
// So this is intended to fall through to the hre_reading section.
|
// 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
|
// 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
|
// bits and starting the read, the HRE won't output the message we
|
||||||
// are looking for...
|
// are looking for...
|
||||||
|
|
||||||
case hre_reading:
|
case hre_reading:
|
||||||
//ch = hreReadChar(parity_errors);
|
//KG44?Q45484=0444444V;RB000000022;IB018435683
|
||||||
//i = read_counter - 24; // The water usage reading starts 24 bytes into the block
|
// RB003119173;IB018435683
|
||||||
//if (i>=0 && i<sizeof(buff))
|
|
||||||
// buff[i] = ch;
|
|
||||||
|
|
||||||
buff[read_counter] = hreReadChar(parity_errors);
|
buff[read_counter] = hreReadChar(parity_errors);
|
||||||
|
|
||||||
read_counter++;
|
read_counter++;
|
||||||
if (read_counter == 46)
|
if (read_counter == 46)
|
||||||
{
|
{
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR("HRE: pe:%d, buff:%s"), parity_errors, buff);
|
//buff[33]='\0';
|
||||||
AddLog(LOG_LEVEL_DEBUG);
|
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_HRE " pe:%d, buff:%s"), parity_errors, buff);
|
||||||
if (parity_errors == 0)
|
if (parity_errors == 0)
|
||||||
{
|
{
|
||||||
float curr_usage;
|
float curr_usage;
|
||||||
|
@ -215,8 +207,7 @@ void hreEvery50ms(void)
|
||||||
hre_usage = curr_usage;
|
hre_usage = curr_usage;
|
||||||
hre_usage_time = curr_start;
|
hre_usage_time = curr_start;
|
||||||
hre_good = true;
|
hre_good = true;
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR("HRE: usage:%.2f, rate:%.3f"), hre_usage, hre_rate);
|
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_HRE " usage:%d, rate:%d"), int(100*hre_usage), int(100*hre_rate));
|
||||||
AddLog(LOG_LEVEL_DEBUG);
|
|
||||||
hre_state = hre_sleep;
|
hre_state = hre_sleep;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -230,8 +221,7 @@ void hreEvery50ms(void)
|
||||||
case hre_sleep:
|
case hre_sleep:
|
||||||
hre_usage_time = curr_start;
|
hre_usage_time = curr_start;
|
||||||
hre_state = hre_sleeping;
|
hre_state = hre_sleeping;
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR("HRE: state:sleeping"));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HRE "hre_state:hre_sleeping"));
|
||||||
AddLog(LOG_LEVEL_DEBUG);
|
|
||||||
|
|
||||||
case hre_sleeping:
|
case hre_sleeping:
|
||||||
if (uptime - hre_usage_time > 27)
|
if (uptime - hre_usage_time > 27)
|
||||||
|
@ -243,8 +233,8 @@ void hreShow(boolean json)
|
||||||
{
|
{
|
||||||
if (!hre_good)
|
if (!hre_good)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const char hre_types[] = "HRE";
|
const char *id = "HRE";
|
||||||
|
|
||||||
char usage[33];
|
char usage[33];
|
||||||
char rate[33];
|
char rate[33];
|
||||||
|
@ -253,13 +243,13 @@ void hreShow(boolean json)
|
||||||
|
|
||||||
if (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
|
#ifdef USE_WEBSERVER
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_GALLONS, mqtt_data, hre_types, usage);
|
WSContentSend_PD(HTTP_SNS_GALLONS, id, usage);
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_GPM, mqtt_data, hre_types, rate);
|
WSContentSend_PD(HTTP_SNS_GPM, id, rate);
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue