Merge branch 'arendst/development' into development

This commit is contained in:
reloxx13 2018-02-15 01:54:05 +01:00
commit 7d5d01575a
11 changed files with 115 additions and 59 deletions

View File

@ -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.12.0a** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
Current version is **5.12.0b** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
### ATTENTION All versions

View File

@ -1,4 +1,11 @@
/* 5.12.0a
/* 5.12.0b
* Add serial debug info
* Add optional usage of %d or %X suffices in MQTT client to append chipid (#1871)
* Add optional usage of %d or %X suffices in MQTT topic to append chipid (#1871)
* Add optional usage of %d or %04d in ota url to be replaced with chipid (#1871)
* Add user configurable serial GPIOs to MagicHome and Arilux modules (#1887)
*
* 5.12.0a
* Change platformio option sonoff-ds18x20 to sonoff-xxl enabling ds18x20 and all other sensors in one image
* Fix providing web page configuratin option for Friendly Name when no device (relay or light) is configured (#1850)
* Change default paremeters in user_config.h to undefined for easy installation (#1851)

View File

@ -25,7 +25,7 @@
- Select IDE Tools - Flash Size: "1M (no SPIFFS)"
====================================================*/
#define VERSION 0x050C0001 // 5.12.0a
#define VERSION 0x050C0002 // 5.12.0b
// Location specific includes
#include <core_version.h> // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0)
@ -193,6 +193,7 @@ boolean mdns_begun = false;
char my_version[33]; // Composed version string
char my_hostname[33]; // Composed Wifi hostname
char mqtt_client[33]; // Composed MQTT Clientname
char mqtt_topic[33]; // Composed MQTT topic
char serial_in_buffer[INPUT_BUFFER_SIZE]; // Receive buffer
char mqtt_data[MESSZ]; // MQTT publish buffer and web page ajax buffer
char log_data[LOGSZ]; // Logging
@ -201,7 +202,7 @@ String backlog[MAX_BACKLOG]; // Command backlog
/********************************************************************************************/
void GetMqttClient(char* output, const char* input, byte size)
char* GetMqttClient(char* output, const char* input, int size)
{
char *token;
uint8_t digits = 0;
@ -217,14 +218,39 @@ void GetMqttClient(char* output, const char* input, byte size)
if (token != NULL) {
digits = atoi(token);
if (digits) {
snprintf_P(output, size, PSTR("%s%c0%dX"), output, '%', digits);
snprintf_P(output, size, output, ESP.getChipId());
if (strchr(token, 'd')) {
snprintf_P(output, size, PSTR("%s%c0%dd"), output, '%', digits);
snprintf_P(output, size, output, ESP.getChipId() & 0x1fff); // %04d - short chip ID in dec, like in hostname
} else {
snprintf_P(output, size, PSTR("%s%c0%dX"), output, '%', digits);
snprintf_P(output, size, output, ESP.getChipId()); // %06X - full chip ID in hex
}
} else {
if (strchr(token, 'd')) {
snprintf_P(output, size, PSTR("%s%d"), output, ESP.getChipId()); // %d - full chip ID in dec
digits = 8;
}
}
}
}
if (!digits) {
strlcpy(output, input, size);
}
return output;
}
char* GetOtaUrl(char *otaurl, size_t otaurl_size)
{
if (strstr(Settings.ota_url, "%04d") != NULL) { // OTA url contains placeholder for chip ID
snprintf(otaurl, otaurl_size, Settings.ota_url, ESP.getChipId() & 0x1fff);
}
else if (strstr(Settings.ota_url, "%d") != NULL) { // OTA url contains placeholder for chip ID
snprintf_P(otaurl, otaurl_size, Settings.ota_url, ESP.getChipId());
}
else {
snprintf(otaurl, otaurl_size, Settings.ota_url);
}
return otaurl;
}
void GetTopic_P(char *stopic, byte prefix, char *topic, const char* subtopic)
@ -419,7 +445,7 @@ void MqttPublishPrefixTopic_P(uint8_t prefix, const char* subtopic, boolean reta
romram[i] = toupper(romram[i]);
}
prefix &= 3;
GetTopic_P(stopic, prefix, Settings.mqtt_topic, romram);
GetTopic_P(stopic, prefix, mqtt_topic, romram);
MqttPublish(stopic, retained);
}
@ -437,11 +463,11 @@ void MqttPublishPowerState(byte device)
device = 1;
}
GetPowerDevice(scommand, device, sizeof(scommand));
GetTopic_P(stopic, STAT, Settings.mqtt_topic, (Settings.flag.mqtt_response) ? scommand : S_RSLT_RESULT);
GetTopic_P(stopic, STAT, mqtt_topic, (Settings.flag.mqtt_response) ? scommand : S_RSLT_RESULT);
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, scommand, GetStateText(bitRead(power, device -1)));
MqttPublish(stopic);
GetTopic_P(stopic, STAT, Settings.mqtt_topic, scommand);
GetTopic_P(stopic, STAT, mqtt_topic, scommand);
snprintf_P(mqtt_data, sizeof(mqtt_data), GetStateText(bitRead(power, device -1)));
MqttPublish(stopic, Settings.flag.mqtt_power_retain);
}
@ -469,7 +495,7 @@ void MqttConnected()
mqtt_data[0] = '\0';
MqttPublishPrefixTopic_P(CMND, S_RSLT_POWER);
GetTopic_P(stopic, CMND, Settings.mqtt_topic, PSTR("#"));
GetTopic_P(stopic, CMND, mqtt_topic, PSTR("#"));
MqttSubscribe(stopic);
if (strstr(Settings.mqtt_fulltopic, MQTT_TOKEN_TOPIC) != NULL) {
GetTopic_P(stopic, CMND, Settings.mqtt_grptopic, PSTR("#"));
@ -555,7 +581,7 @@ void MqttReconnect()
#endif // USE_MQTT_TLS
MqttClient.setServer(Settings.mqtt_host, Settings.mqtt_port);
GetTopic_P(stopic, TELE, Settings.mqtt_topic, S_LWT);
GetTopic_P(stopic, TELE, mqtt_topic, S_LWT);
snprintf_P(mqtt_data, sizeof(mqtt_data), S_OFFLINE);
char *mqtt_user = NULL;
@ -710,7 +736,7 @@ boolean MqttCommand(boolean grpflg, char *type, uint16_t index, char *dataBuf, u
if (!strcmp(dataBuf, mqtt_client)) {
payload = 1;
}
strlcpy(Settings.button_topic, (!strcmp(dataBuf,"0")) ? "" : (1 == payload) ? Settings.mqtt_topic : dataBuf, sizeof(Settings.button_topic));
strlcpy(Settings.button_topic, (!strcmp(dataBuf,"0")) ? "" : (1 == payload) ? mqtt_topic : dataBuf, sizeof(Settings.button_topic));
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, Settings.button_topic);
}
@ -720,13 +746,13 @@ boolean MqttCommand(boolean grpflg, char *type, uint16_t index, char *dataBuf, u
if (!strcmp(dataBuf, mqtt_client)) {
payload = 1;
}
strlcpy(Settings.switch_topic, (!strcmp(dataBuf,"0")) ? "" : (1 == payload) ? Settings.mqtt_topic : dataBuf, sizeof(Settings.switch_topic));
strlcpy(Settings.switch_topic, (!strcmp(dataBuf,"0")) ? "" : (1 == payload) ? mqtt_topic : dataBuf, sizeof(Settings.switch_topic));
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, Settings.switch_topic);
}
else if (CMND_BUTTONRETAIN == command_code) {
if ((payload >= 0) && (payload <= 1)) {
strlcpy(Settings.button_topic, Settings.mqtt_topic, sizeof(Settings.button_topic));
strlcpy(Settings.button_topic, mqtt_topic, sizeof(Settings.button_topic));
if (!payload) {
for(i = 1; i <= MAX_KEYS; i++) {
send_button_power(0, i, 9); // Clear MQTT retain in broker
@ -738,7 +764,7 @@ boolean MqttCommand(boolean grpflg, char *type, uint16_t index, char *dataBuf, u
}
else if (CMND_SWITCHRETAIN == command_code) {
if ((payload >= 0) && (payload <= 1)) {
strlcpy(Settings.button_topic, Settings.mqtt_topic, sizeof(Settings.button_topic));
strlcpy(Settings.button_topic, mqtt_topic, sizeof(Settings.button_topic));
if (!payload) {
for(i = 1; i <= MAX_SWITCHES; i++) {
send_button_power(1, i, 9); // Clear MQTT retain in broker
@ -752,7 +778,7 @@ boolean MqttCommand(boolean grpflg, char *type, uint16_t index, char *dataBuf, u
if ((payload >= 0) && (payload <= 1)) {
if (!payload) {
for(i = 1; i <= devices_present; i++) { // Clear MQTT retain in broker
GetTopic_P(stemp1, STAT, Settings.mqtt_topic, GetPowerDevice(scommand, i, sizeof(scommand)));
GetTopic_P(stemp1, STAT, mqtt_topic, GetPowerDevice(scommand, i, sizeof(scommand)));
mqtt_data[0] = '\0';
MqttPublish(stemp1, Settings.flag.mqtt_power_retain);
}
@ -1253,7 +1279,8 @@ void MqttDataCallback(char* topic, byte* data, unsigned int data_len)
// We also need at least 3 chars to make a valid version number string.
if (((1 == data_len) && (1 == payload)) || ((data_len >= 3) && NewerVersion(dataBuf))) {
ota_state_flag = 3;
snprintf_P(mqtt_data, sizeof(mqtt_data), "{\"%s\":\"" D_JSON_VERSION " %s " D_JSON_FROM " %s\"}", command, my_version, Settings.ota_url);
// snprintf_P(mqtt_data, sizeof(mqtt_data), "{\"%s\":\"" D_JSON_VERSION " %s " D_JSON_FROM " %s\"}", command, my_version, Settings.ota_url);
snprintf_P(mqtt_data, sizeof(mqtt_data), "{\"%s\":\"" D_JSON_VERSION " %s " D_JSON_FROM " %s\"}", command, my_version, GetOtaUrl(stemp1, sizeof(stemp1)));
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), "{\"%s\":\"" D_JSON_ONE_OR_GT "\"}", command, my_version);
}
@ -1557,7 +1584,7 @@ boolean send_button_power(byte key, byte device, byte state)
if (9 == state) {
mqtt_data[0] = '\0';
} else {
if ((!strcmp(Settings.mqtt_topic, key_topic) || !strcmp(Settings.mqtt_grptopic, key_topic)) && (2 == state)) {
if ((!strcmp(mqtt_topic, key_topic) || !strcmp(Settings.mqtt_grptopic, key_topic)) && (2 == state)) {
state = ~(power >> (device -1)) &1;
}
snprintf_P(mqtt_data, sizeof(mqtt_data), GetStateText(state));
@ -1710,7 +1737,7 @@ void PublishStatus(uint8_t payload)
if ((0 == payload) || (99 == payload)) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_STATUS "\":{\"" D_CMND_MODULE "\":%d,\"" D_CMND_FRIENDLYNAME "\":\"%s\",\"" D_CMND_TOPIC "\":\"%s\",\"" D_CMND_BUTTONTOPIC "\":\"%s\",\"" D_CMND_POWER "\":%d,\"" D_CMND_POWERONSTATE "\":%d,\"" D_CMND_LEDSTATE "\":%d,\"" D_CMND_SAVEDATA "\":%d,\"" D_JSON_SAVESTATE "\":%d,\"" D_CMND_BUTTONRETAIN "\":%d,\"" D_CMND_POWERRETAIN "\":%d}}"),
Settings.module +1, Settings.friendlyname[0], Settings.mqtt_topic, Settings.button_topic, power, Settings.poweronstate, Settings.ledstate, Settings.save_data, Settings.flag.save_state, Settings.flag.mqtt_button_retain, Settings.flag.mqtt_power_retain);
Settings.module +1, Settings.friendlyname[0], mqtt_topic, Settings.button_topic, power, Settings.poweronstate, Settings.ledstate, Settings.save_data, Settings.flag.save_state, Settings.flag.mqtt_button_retain, Settings.flag.mqtt_power_retain);
MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS));
}
@ -2274,23 +2301,24 @@ void StateLoop()
ota_result = 0;
ota_retry_counter--;
if (ota_retry_counter) {
strlcpy(mqtt_data, GetOtaUrl(log_data, sizeof(log_data)), sizeof(mqtt_data));
#ifndef BE_MINIMAL
if (RtcSettings.ota_loader) {
char *pch = strrchr(Settings.ota_url, '-'); // Change from filename-DE.bin into filename-minimal.bin
char *ech = strrchr(Settings.ota_url, '.'); // Change from filename.bin into filename-minimal.bin
char *pch = strrchr(mqtt_data, '-'); // Change from filename-DE.bin into filename-minimal.bin
char *ech = strrchr(mqtt_data, '.'); // Change from filename.bin into filename-minimal.bin
if (!pch) {
pch = ech;
}
if (pch) {
strlcpy(mqtt_data, Settings.ota_url, pch - Settings.ota_url +1);
mqtt_data[pch - mqtt_data] = '\0';
char *ech = strrchr(Settings.ota_url, '.'); // Change from filename.bin into filename-minimal.bin
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s-" D_JSON_MINIMAL "%s"), mqtt_data, ech); // Minimal filename must be filename-minimal
ota_url = mqtt_data; // Try minimal image
}
}
#endif // BE_MINIMAL
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPLOAD "%s"), ota_url);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPLOAD "%s"), mqtt_data);
AddLog(LOG_LEVEL_DEBUG);
ota_result = (HTTP_UPDATE_FAILED != ESPhttpUpdate.update(ota_url));
ota_result = (HTTP_UPDATE_FAILED != ESPhttpUpdate.update(mqtt_data));
if (!ota_result) {
#ifndef BE_MINIMAL
int ota_error = ESPhttpUpdate.getLastError();
@ -2707,16 +2735,17 @@ void setup()
SetSerialBaudrate(baudrate);
GetMqttClient(mqtt_client, Settings.mqtt_client, sizeof(mqtt_client));
GetMqttClient(mqtt_topic, Settings.mqtt_topic, sizeof(mqtt_topic));
if (strstr(Settings.hostname, "%")) {
strlcpy(Settings.hostname, WIFI_HOSTNAME, sizeof(Settings.hostname));
snprintf_P(my_hostname, sizeof(my_hostname)-1, Settings.hostname, Settings.mqtt_topic, ESP.getChipId() & 0x1FFF);
snprintf_P(my_hostname, sizeof(my_hostname)-1, Settings.hostname, mqtt_topic, ESP.getChipId() & 0x1FFF);
} else {
snprintf_P(my_hostname, sizeof(my_hostname)-1, Settings.hostname);
}
WifiConnect();
GetMqttClient(mqtt_client, Settings.mqtt_client, sizeof(mqtt_client));
if (MOTOR == Settings.module) {
Settings.poweronstate = POWER_ALL_ON; // Needs always on else in limbo!
}
@ -2768,7 +2797,7 @@ void setup()
blink_powersave = power;
snprintf_P(log_data, sizeof(log_data), PSTR(D_PROJECT " %s %s (" D_CMND_TOPIC " %s, " D_FALLBACK " %s, " D_CMND_GROUPTOPIC " %s) " D_VERSION " %s"),
PROJECT, Settings.friendlyname[0], Settings.mqtt_topic, mqtt_client, Settings.mqtt_grptopic, my_version);
PROJECT, Settings.friendlyname[0], mqtt_topic, mqtt_client, Settings.mqtt_grptopic, my_version);
AddLog(LOG_LEVEL_INFO);
#ifdef BE_MINIMAL
snprintf_P(log_data, sizeof(log_data), PSTR(D_WARNING_MINIMAL_VERSION));

View File

@ -679,9 +679,10 @@ const mytmplt kModules[MAXMODULE] PROGMEM = {
0, 0, 0, 0, 0
},
{ "MagicHome", // Magic Home (aka Flux-light) (ESP8266) - https://www.aliexpress.com/item/Magic-Home-Mini-RGB-RGBW-Wifi-Controller-For-Led-Strip-Panel-light-Timing-Function-16million-colors/32686853650.html
0, 0,
GPIO_LED1_INV, // GPIO02 Blue onboard LED
0,
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
GPIO_LED1_INV, // GPIO02 Blue onboard LED
GPIO_USER, // GPIO03 Serial TXD and Optional sensor
GPIO_USER, // GPIO04 IR receiver (optional)
GPIO_PWM2, // GPIO05 RGB LED Green
0, 0, 0, 0, 0, 0, // Flash connection
@ -719,9 +720,9 @@ const mytmplt kModules[MAXMODULE] PROGMEM = {
{ "Arilux LC01", // Arilux AL-LC01 (ESP8285) - https://www.banggood.com/nl/ARILUX-AL-LC01-Super-Mini-LED-WIFI-Smart-RGB-Controller-For-RGB-LED-Strip-Light-DC-9-12V-p-1058603.html
// (PwmFrequency 1111Hz)
GPIO_KEY1, // GPIO00 Optional Button
0,
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
GPIO_LED2_INV, // GPIO02 RF receiver control
0,
GPIO_USER, // GPIO03 Serial TXD and Optional sensor
GPIO_ARIRFRCV, // GPIO04 IR or RF receiver (optional)
GPIO_PWM1, // GPIO05 RGB LED Red
0, 0, 0, 0, 0, 0, // Flash connection
@ -733,9 +734,9 @@ const mytmplt kModules[MAXMODULE] PROGMEM = {
{ "Arilux LC11", // Arilux AL-LC11 (ESP8266) - https://www.banggood.com/nl/ARILUX-AL-LC11-Super-Mini-LED-WIFI-APP-Controller-RF-Remote-Control-For-RGBWW-LED-Strip-DC9-28V-p-1085112.html
// (PwmFrequency 540Hz)
GPIO_KEY1, // GPIO00 Optional Button
0,
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
GPIO_LED2_INV, // GPIO02 RF receiver control
0,
GPIO_USER, // GPIO03 Serial TXD and Optional sensor
GPIO_PWM2, // GPIO04 RGB LED Green
GPIO_PWM1, // GPIO05 RGB LED Red
0, 0, 0, 0, 0, 0, // Flash connection
@ -762,9 +763,9 @@ const mytmplt kModules[MAXMODULE] PROGMEM = {
},
{ "Arilux LC06", // Arilux AL-LC06 (ESP8285) - https://www.banggood.com/ARILUX-AL-LC06-LED-WIFI-Smartphone-Controller-Romote-5-Channels-DC12-24V-For-RGBWW-Strip-light-p-1061476.html
GPIO_KEY1, // GPIO00 Optional Button
0,
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
GPIO_USER, // GPIO02 Empty pad
0,
GPIO_USER, // GPIO03 Serial TXD and Optional sensor
GPIO_USER, // GPIO04 W2 - PWM5
0,
0, 0, 0, 0, 0, 0, // Flash connection

View File

@ -1436,15 +1436,20 @@ void AddLog_P(byte loglevel, const char *formatP, const char *formatP2)
AddLog(loglevel);
}
void AddLogSerial(byte loglevel)
void AddLogSerial(byte loglevel, uint8_t *buffer, byte count)
{
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_SERIAL D_RECEIVED));
for (byte i = 0; i < serial_in_byte_counter; i++) {
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, serial_in_buffer[i]);
for (byte i = 0; i < count; i++) {
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, *(buffer++));
}
AddLog(loglevel);
}
void AddLogSerial(byte loglevel)
{
AddLogSerial(loglevel, (uint8_t*)serial_in_buffer, serial_in_byte_counter);
}
/*********************************************************************************************\
*
\*********************************************************************************************/

View File

@ -865,8 +865,8 @@ void HandleMqttConfiguration()
page += FPSTR(HTTP_HEAD_STYLE);
page += FPSTR(HTTP_FORM_MQTT);
char str[sizeof(Settings.mqtt_client)];
GetMqttClient(str, MQTT_CLIENT_ID, sizeof(Settings.mqtt_client));
page.replace(F("{m0"), str);
page.replace(F("{m0"), GetMqttClient(str, MQTT_CLIENT_ID, sizeof(Settings.mqtt_client)));
// page.replace(F("{m0"), str);
page.replace(F("{m1"), Settings.mqtt_host);
page.replace(F("{m2"), String(Settings.mqtt_port));
page.replace(F("{m3"), Settings.mqtt_client);
@ -1625,7 +1625,7 @@ void HandleInformation()
func += F("}1" D_MQTT_USER "}2"); func += Settings.mqtt_user;
func += F("}1" D_MQTT_TOPIC "}2"); func += Settings.mqtt_topic;
func += F("}1" D_MQTT_GROUP_TOPIC "}2"); func += Settings.mqtt_grptopic;
GetTopic_P(stopic, CMND, Settings.mqtt_topic, "");
GetTopic_P(stopic, CMND, mqtt_topic, "");
func += F("}1" D_MQTT_FULL_TOPIC "}2"); func += stopic;
} else {

View File

@ -469,6 +469,8 @@ bool PzemRecieve(uint8_t resp, float *data)
}
}
AddLogSerial(LOG_LEVEL_DEBUG_MORE, buffer, len);
if (len != sizeof(PZEMCommand)) {
// AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "Pzem comms timeout"));
return false;
@ -978,25 +980,29 @@ boolean EnergyCommand()
void EnergyDrvInit()
{
energy_flg = ENERGY_NONE;
if ((pin[GPIO_HLW_SEL] < 99) && (pin[GPIO_HLW_CF1] < 99) && (pin[GPIO_HLW_CF] < 99)) {
if ((pin[GPIO_HLW_SEL] < 99) && (pin[GPIO_HLW_CF1] < 99) && (pin[GPIO_HLW_CF] < 99)) { // Sonoff Pow
energy_flg = ENERGY_HLW8012;
} else if (SONOFF_S31 == Settings.module) {
} else if (SONOFF_S31 == Settings.module) { // Sonoff S31
baudrate = 4800;
serial_config = SERIAL_8E1;
energy_flg = ENERGY_CSE7766;
#ifdef USE_PZEM004T
} else if ((pin[GPIO_PZEM_RX] < 99) && (pin[GPIO_PZEM_TX])) {
if (PzemInit()) {
energy_flg = ENERGY_PZEM004T;
}
} else if ((pin[GPIO_PZEM_RX] < 99) && (pin[GPIO_PZEM_TX])) { // Any device with a Pzem004T
energy_flg = ENERGY_PZEM004T;
#endif // USE_PZEM004T
}
}
void EnergyInit()
void EnergySnsInit()
{
if (ENERGY_HLW8012 == energy_flg) HlwInit();
#ifdef USE_PZEM004T
if ((ENERGY_PZEM004T == energy_flg) && !PzemInit()) { // PzemInit needs to be done here as earlier (serial) interrupts may lead to Exceptions
energy_flg = ENERGY_NONE;
}
#endif // USE_PZEM004T
if (energy_flg) {
energy_kWhtoday = (RtcSettingsValid()) ? RtcSettings.energy_kWhtoday : (RtcTime.day_of_year == Settings.energy_kWhdoy) ? Settings.energy_kWhtoday : 0;
energy_period = energy_kWhtoday;
@ -1099,7 +1105,7 @@ boolean Xsns03(byte function)
if (energy_flg) {
switch (function) {
case FUNC_INIT:
EnergyInit();
EnergySnsInit();
break;
case FUNC_EVERY_SECOND:
EnergyMarginCheck();

View File

@ -90,7 +90,7 @@ void HAssDiscovery()
is_light = ((i == devices_present) && (light_type));
snprintf_P(sidx, sizeof(sidx), PSTR("_%d"), i);
snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/%s/%s%s/config"), (is_light) ? "light" : "switch", Settings.mqtt_topic, (1 == devices_present) ? "" : sidx);
snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/%s/%s%s/config"), (is_light) ? "light" : "switch", mqtt_topic, (1 == devices_present) ? "" : sidx);
mqtt_data[0] = '\0';
if (Settings.flag.hass_discovery) {
@ -106,33 +106,33 @@ void HAssDiscovery()
snprintf_P(name, sizeof(name), Settings.friendlyname[i -1]);
}
GetPowerDevice(value_template, i, sizeof(value_template));
GetTopic_P(command_topic, CMND, Settings.mqtt_topic, value_template);
GetTopic_P(state_topic, STAT, Settings.mqtt_topic, S_RSLT_RESULT);
GetTopic_P(availability_topic, TELE, Settings.mqtt_topic, S_LWT);
GetTopic_P(command_topic, CMND, mqtt_topic, value_template);
GetTopic_P(state_topic, STAT, mqtt_topic, S_RSLT_RESULT);
GetTopic_P(availability_topic, TELE, mqtt_topic, S_LWT);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SWITCH, name, command_topic, state_topic, value_template, Settings.state_text[0], Settings.state_text[1], availability_topic);
if (is_light) {
char brightness_command_topic[TOPSZ];
GetTopic_P(brightness_command_topic, CMND, Settings.mqtt_topic, D_CMND_DIMMER);
GetTopic_P(brightness_command_topic, CMND, mqtt_topic, D_CMND_DIMMER);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_DIMMER, mqtt_data, brightness_command_topic, state_topic);
if (light_subtype >= LST_RGB) {
char rgb_command_topic[TOPSZ];
GetTopic_P(rgb_command_topic, CMND, Settings.mqtt_topic, D_CMND_COLOR);
GetTopic_P(rgb_command_topic, CMND, mqtt_topic, D_CMND_COLOR);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_COLOR, mqtt_data, rgb_command_topic, state_topic);
/*
char effect_command_topic[TOPSZ];
GetTopic_P(effect_command_topic, CMND, Settings.mqtt_topic, D_CMND_SCHEME);
GetTopic_P(effect_command_topic, CMND, mqtt_topic, D_CMND_SCHEME);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_SCHEME, mqtt_data, effect_command_topic, state_topic);
*/
}
if ((LST_COLDWARM == light_subtype) || (LST_RGBWC == light_subtype)) {
char color_temp_command_topic[TOPSZ];
GetTopic_P(color_temp_command_topic, CMND, Settings.mqtt_topic, D_CMND_COLORTEMPERATURE);
GetTopic_P(color_temp_command_topic, CMND, mqtt_topic, D_CMND_COLORTEMPERATURE);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_CT, mqtt_data, color_temp_command_topic, state_topic);
}
}

View File

@ -158,6 +158,9 @@ void Mhz50ms()
mhz_response[counter++] = MhzSerial->read();
}
}
AddLogSerial(LOG_LEVEL_DEBUG_MORE, mhz_response, counter);
if (counter < 9) {
// AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "MH-Z19 comms timeout"));
return;

View File

@ -96,6 +96,9 @@ uint8_t ModbusReceive(uint16_t *value)
}
}
}
AddLogSerial(LOG_LEVEL_DEBUG_MORE, buffer, len);
if (len != sizeof(buffer)) {
return 9; // 9 = Unexpected result
}

View File

@ -56,6 +56,8 @@ boolean PmsReadData()
PmsSerial->readBytes(buffer, 32);
PmsSerial->flush(); // Make room for another burst
AddLogSerial(LOG_LEVEL_DEBUG_MORE, buffer, 32);
// get checksum ready
for (uint8_t i = 0; i < 30; i++) {
sum += buffer[i];