Merge branch 'development' into development

This commit is contained in:
polarduck-dev 2021-01-19 16:39:31 +00:00 committed by GitHub
commit 6ab6708c34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 668 additions and 595 deletions

View File

@ -7,7 +7,7 @@
- [ ] Only relevant files were touched - [ ] Only relevant files were touched
- [ ] Only one feature/fix was added per PR and the code change compiles without warnings - [ ] Only one feature/fix was added per PR and the code change compiles without warnings
- [ ] The code change is tested and works on Tasmota core ESP8266 V.2.7.4.9 - [ ] The code change is tested and works on Tasmota core ESP8266 V.2.7.4.9
- [ ] The code change is tested and works on Tasmota core ESP32 V.1.0.5-rc4 - [ ] The code change is tested and works on Tasmota core ESP32 V.1.0.5-rc6
- [ ] I accept the [CLA](https://github.com/arendst/Tasmota/blob/development/CONTRIBUTING.md#contributor-license-agreement-cla). - [ ] I accept the [CLA](https://github.com/arendst/Tasmota/blob/development/CONTRIBUTING.md#contributor-license-agreement-cla).
_NOTE: The code change must pass CI tests. **Your PR cannot be merged unless tests pass**_ _NOTE: The code change must pass CI tests. **Your PR cannot be merged unless tests pass**_

View File

@ -1603,8 +1603,6 @@ jobs:
[ ! -f ./mv_firmware/tasmota32-knx.* ] || mv ./mv_firmware/tasmota32-knx.* ./firmware/tasmota32/ [ ! -f ./mv_firmware/tasmota32-knx.* ] || mv ./mv_firmware/tasmota32-knx.* ./firmware/tasmota32/
[ ! -f ./mv_firmware/tasmota32* ] || mv ./mv_firmware/tasmota32* ./firmware/tasmota32/languages/ [ ! -f ./mv_firmware/tasmota32* ] || mv ./mv_firmware/tasmota32* ./firmware/tasmota32/languages/
[ ! -f ./mv_firmware/* ] || mv ./mv_firmware/* ./firmware/tasmota/languages/ [ ! -f ./mv_firmware/* ] || mv ./mv_firmware/* ./firmware/tasmota/languages/
rm ./firmware/tasmota32/*.gz
rm ./firmware/tasmota32/languages/*.gz
[ ! -f ./tools/Esptool/ESP32/*.* ] || mv ./tools/Esptool/ESP32/*.* ./firmware/tasmota32/ESP32_needed_files/ [ ! -f ./tools/Esptool/ESP32/*.* ] || mv ./tools/Esptool/ESP32/*.* ./firmware/tasmota32/ESP32_needed_files/
[ ! -f ./tools/Esptool/Odroid_go/*.* ] || mv ./tools/Esptool/Odroid_go/*.* ./firmware/tasmota32/Odroid_go_needed_files/ [ ! -f ./tools/Esptool/Odroid_go/*.* ] || mv ./tools/Esptool/Odroid_go/*.* ./firmware/tasmota32/Odroid_go_needed_files/
[ ! -f ./FIRMWARE.md ] || mv -f ./FIRMWARE.md ./README.md [ ! -f ./FIRMWARE.md ] || mv -f ./FIRMWARE.md ./README.md

View File

@ -1603,8 +1603,6 @@ jobs:
[ ! -f ./mv_firmware/tasmota32-knx.* ] || mv ./mv_firmware/tasmota32-knx.* ./firmware/tasmota32/ [ ! -f ./mv_firmware/tasmota32-knx.* ] || mv ./mv_firmware/tasmota32-knx.* ./firmware/tasmota32/
[ ! -f ./mv_firmware/tasmota32* ] || mv ./mv_firmware/tasmota32* ./firmware/tasmota32/languages/ [ ! -f ./mv_firmware/tasmota32* ] || mv ./mv_firmware/tasmota32* ./firmware/tasmota32/languages/
[ ! -f ./mv_firmware/* ] || mv ./mv_firmware/* ./firmware/tasmota/languages/ [ ! -f ./mv_firmware/* ] || mv ./mv_firmware/* ./firmware/tasmota/languages/
rm ./firmware/tasmota32/*.gz
rm ./firmware/tasmota32/languages/*.gz
[ ! -f ./tools/Esptool/ESP32/*.* ] || mv ./tools/Esptool/ESP32/*.* ./firmware/tasmota32/ESP32_needed_files/ [ ! -f ./tools/Esptool/ESP32/*.* ] || mv ./tools/Esptool/ESP32/*.* ./firmware/tasmota32/ESP32_needed_files/
[ ! -f ./tools/Esptool/Odroid_go/*.* ] || mv ./tools/Esptool/Odroid_go/*.* ./firmware/tasmota32/Odroid_go_needed_files/ [ ! -f ./tools/Esptool/Odroid_go/*.* ] || mv ./tools/Esptool/Odroid_go/*.* ./firmware/tasmota32/Odroid_go_needed_files/
[ ! -f ./FIRMWARE.md ] || mv -f ./RELEASENOTES.md ./README.md [ ! -f ./FIRMWARE.md ] || mv -f ./RELEASENOTES.md ./README.md

View File

@ -32,7 +32,7 @@ extern String EscapeJSONString(const char *str);
class JsonGeneratorArray { class JsonGeneratorArray {
public: public:
JsonGeneratorArray(): val("[]") {} // start with empty array JsonGeneratorArray(): val(F("[]")) {} // start with empty array
void add(uint32_t uval32); void add(uint32_t uval32);
void add(int32_t uval32); void add(int32_t uval32);
@ -53,7 +53,7 @@ protected:
class JsonGeneratorObject { class JsonGeneratorObject {
public: public:
JsonGeneratorObject(): val("{}") {} // start with empty object JsonGeneratorObject(): val(F("{}")) {} // start with empty object
void add(const char* key, uint32_t uval32); void add(const char* key, uint32_t uval32);
void add(const char* key, int32_t uval32); void add(const char* key, int32_t uval32);

View File

@ -3,6 +3,12 @@ import os
import shutil import shutil
import gzip import gzip
platform = env.PioPlatform()
board = env.BoardConfig()
mcu = board.get("build.mcu", "esp32")
# gzip only for ESP8266
if env["PIOPLATFORM"] != "espressif32":
OUTPUT_DIR = "build_output{}".format(os.path.sep) OUTPUT_DIR = "build_output{}".format(os.path.sep)
def bin_gzip(source, target, env): def bin_gzip(source, target, env):

View File

@ -165,7 +165,7 @@ lib_extra_dirs =
; *** EXPERIMENTAL Tasmota version for ESP32solo1 (used in some Xiaomi devices) ; *** EXPERIMENTAL Tasmota version for ESP32solo1 (used in some Xiaomi devices)
[env:tasmota32solo1] [env:tasmota32solo1]
extends = env:tasmota32 extends = env:tasmota32
platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/raw/framework-arduinoespressif32/framework-arduinoespressif32-release_v3.3-solo1-4b325f52e.tar.gz platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/raw/framework-arduinoespressif32/framework-arduinoespressif32-solo1-release_v3.3-7e63061fa.tar.gz
platformio/tool-mklittlefs @ ~1.203.200522 platformio/tool-mklittlefs @ ~1.203.200522
platformio/tool-esptoolpy @ ~1.30000.0 platformio/tool-esptoolpy @ ~1.30000.0
build_unflags = ${esp32_defaults.build_unflags} build_unflags = ${esp32_defaults.build_unflags}

View File

@ -92,7 +92,7 @@ build_flags = ${esp_defaults.build_flags}
[core32] [core32]
platform = espressif32 @ 2.1.0 platform = espressif32 @ 2.1.0
platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/arduino-esp32/releases/download/1.0.5-rc4/esp32-1.0.5-rc4.zip platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/arduino-esp32/releases/download/1.0.5-rc6/esp32-1.0.5-rc6.zip
platformio/tool-mklittlefs @ ~1.203.200522 platformio/tool-mklittlefs @ ~1.203.200522
build_unflags = ${esp32_defaults.build_unflags} build_unflags = ${esp32_defaults.build_unflags}
build_flags = ${esp32_defaults.build_flags} build_flags = ${esp32_defaults.build_flags}

View File

@ -812,10 +812,10 @@ void SettingsDefaultSet2(void)
flag3.use_wifi_rescan |= WIFI_SCAN_REGULARLY; flag3.use_wifi_rescan |= WIFI_SCAN_REGULARLY;
Settings.wifi_output_power = 170; Settings.wifi_output_power = 170;
Settings.param[P_ARP_GRATUITOUS] = WIFI_ARP_INTERVAL; Settings.param[P_ARP_GRATUITOUS] = WIFI_ARP_INTERVAL;
ParseIPv4(&Settings.ipv4_address[0], WIFI_IP_ADDRESS); ParseIPv4(&Settings.ipv4_address[0], PSTR(WIFI_IP_ADDRESS));
ParseIPv4(&Settings.ipv4_address[1], WIFI_GATEWAY); ParseIPv4(&Settings.ipv4_address[1], PSTR(WIFI_GATEWAY));
ParseIPv4(&Settings.ipv4_address[2], WIFI_SUBNETMASK); ParseIPv4(&Settings.ipv4_address[2], PSTR(WIFI_SUBNETMASK));
ParseIPv4(&Settings.ipv4_address[3], WIFI_DNS); ParseIPv4(&Settings.ipv4_address[3], PSTR(WIFI_DNS));
Settings.sta_config = WIFI_CONFIG_TOOL; Settings.sta_config = WIFI_CONFIG_TOOL;
// Settings.sta_active = 0; // Settings.sta_active = 0;
SettingsUpdateText(SET_STASSID1, PSTR(STA_SSID1)); SettingsUpdateText(SET_STASSID1, PSTR(STA_SSID1));
@ -865,22 +865,22 @@ void SettingsDefaultSet2(void)
flag3.grouptopic_mode |= MQTT_GROUPTOPIC_FORMAT; flag3.grouptopic_mode |= MQTT_GROUPTOPIC_FORMAT;
SettingsUpdateText(SET_MQTT_HOST, MQTT_HOST); SettingsUpdateText(SET_MQTT_HOST, MQTT_HOST);
Settings.mqtt_port = MQTT_PORT; Settings.mqtt_port = MQTT_PORT;
SettingsUpdateText(SET_MQTT_CLIENT, MQTT_CLIENT_ID); SettingsUpdateText(SET_MQTT_CLIENT, PSTR(MQTT_CLIENT_ID));
SettingsUpdateText(SET_MQTT_USER, MQTT_USER); SettingsUpdateText(SET_MQTT_USER, PSTR(MQTT_USER));
SettingsUpdateText(SET_MQTT_PWD, MQTT_PASS); SettingsUpdateText(SET_MQTT_PWD, PSTR(MQTT_PASS));
SettingsUpdateText(SET_MQTT_TOPIC, MQTT_TOPIC); SettingsUpdateText(SET_MQTT_TOPIC, PSTR(MQTT_TOPIC));
SettingsUpdateText(SET_MQTT_BUTTON_TOPIC, MQTT_BUTTON_TOPIC); SettingsUpdateText(SET_MQTT_BUTTON_TOPIC, PSTR(MQTT_BUTTON_TOPIC));
SettingsUpdateText(SET_MQTT_SWITCH_TOPIC, MQTT_SWITCH_TOPIC); SettingsUpdateText(SET_MQTT_SWITCH_TOPIC, PSTR(MQTT_SWITCH_TOPIC));
SettingsUpdateText(SET_MQTT_GRP_TOPIC, MQTT_GRPTOPIC); SettingsUpdateText(SET_MQTT_GRP_TOPIC, PSTR(MQTT_GRPTOPIC));
SettingsUpdateText(SET_MQTT_FULLTOPIC, MQTT_FULLTOPIC); SettingsUpdateText(SET_MQTT_FULLTOPIC, PSTR(MQTT_FULLTOPIC));
Settings.mqtt_retry = MQTT_RETRY_SECS; Settings.mqtt_retry = MQTT_RETRY_SECS;
SettingsUpdateText(SET_MQTTPREFIX1, SUB_PREFIX); SettingsUpdateText(SET_MQTTPREFIX1, PSTR(SUB_PREFIX));
SettingsUpdateText(SET_MQTTPREFIX2, PUB_PREFIX); SettingsUpdateText(SET_MQTTPREFIX2, PSTR(PUB_PREFIX));
SettingsUpdateText(SET_MQTTPREFIX3, PUB_PREFIX2); SettingsUpdateText(SET_MQTTPREFIX3, PSTR(PUB_PREFIX2));
SettingsUpdateText(SET_STATE_TXT1, MQTT_STATUS_OFF); SettingsUpdateText(SET_STATE_TXT1, PSTR(MQTT_STATUS_OFF));
SettingsUpdateText(SET_STATE_TXT2, MQTT_STATUS_ON); SettingsUpdateText(SET_STATE_TXT2, PSTR(MQTT_STATUS_ON));
SettingsUpdateText(SET_STATE_TXT3, MQTT_CMND_TOGGLE); SettingsUpdateText(SET_STATE_TXT3, PSTR(MQTT_CMND_TOGGLE));
SettingsUpdateText(SET_STATE_TXT4, MQTT_CMND_HOLD); SettingsUpdateText(SET_STATE_TXT4, PSTR(MQTT_CMND_HOLD));
memcpy_P(Settings.mqtt_fingerprint[0], default_fingerprint1, sizeof(default_fingerprint1)); memcpy_P(Settings.mqtt_fingerprint[0], default_fingerprint1, sizeof(default_fingerprint1));
memcpy_P(Settings.mqtt_fingerprint[1], default_fingerprint2, sizeof(default_fingerprint2)); memcpy_P(Settings.mqtt_fingerprint[1], default_fingerprint2, sizeof(default_fingerprint2));
Settings.tele_period = TELE_PERIOD; Settings.tele_period = TELE_PERIOD;

View File

@ -384,7 +384,7 @@ char* Uint64toHex(uint64_t value, char *str, uint16_t bits)
char* dtostrfd(double number, unsigned char prec, char *s) char* dtostrfd(double number, unsigned char prec, char *s)
{ {
if ((isnan(number)) || (isinf(number))) { // Fix for JSON output (https://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript) if ((isnan(number)) || (isinf(number))) { // Fix for JSON output (https://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript)
strcpy(s, "null"); strcpy_P(s, PSTR("null"));
return s; return s;
} else { } else {
return dtostrf(number, 1, prec, s); return dtostrf(number, 1, prec, s);
@ -659,10 +659,14 @@ bool ValidIpAddress(const char* str)
return ip_address.fromString(str); return ip_address.fromString(str);
} }
bool ParseIPv4(uint32_t* addr, const char* str)
bool ParseIPv4(uint32_t* addr, const char* str_p)
{ {
uint8_t *part = (uint8_t*)addr; uint8_t *part = (uint8_t*)addr;
uint8_t i; uint8_t i;
char str_r[strlen_P(str_p)+1];
char * str = &str_r[0];
strcpy_P(str, str_p);
*addr = 0; *addr = 0;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
@ -859,7 +863,7 @@ float ConvertPressureForSeaLevel(float pressure)
String PressureUnit(void) String PressureUnit(void)
{ {
return (Settings.flag.pressure_conversion) ? String(D_UNIT_MILLIMETER_MERCURY) : String(D_UNIT_PRESSURE); return (Settings.flag.pressure_conversion) ? String(F(D_UNIT_MILLIMETER_MERCURY)) : String(F(D_UNIT_PRESSURE));
} }
float ConvertSpeed(float s) float ConvertSpeed(float s)
@ -1022,11 +1026,11 @@ String GetSerialConfig(void) {
// b00000x00 - 1 or 2 stop bits // b00000x00 - 1 or 2 stop bits
// b000xx000 - None, Even or Odd parity // b000xx000 - None, Even or Odd parity
const char kParity[] = "NEOI"; const static char kParity[] PROGMEM = "NEOI";
char config[4]; char config[4];
config[0] = '5' + (Settings.serial_config & 0x3); config[0] = '5' + (Settings.serial_config & 0x3);
config[1] = kParity[(Settings.serial_config >> 3) & 0x3]; config[1] = pgm_read_byte(&kParity[(Settings.serial_config >> 3) & 0x3]);
config[2] = '1' + ((Settings.serial_config >> 2) & 0x1); config[2] = '1' + ((Settings.serial_config >> 2) & 0x1);
config[3] = '\0'; config[3] = '\0';
return String(config); return String(config);

View File

@ -110,7 +110,7 @@ void ResponseCmndStateText(uint32_t value)
void ResponseCmndDone(void) void ResponseCmndDone(void)
{ {
ResponseCmndChar(D_JSON_DONE); ResponseCmndChar(PSTR(D_JSON_DONE));
} }
void ResponseCmndIdxChar(const char* value) void ResponseCmndIdxChar(const char* value)
@ -352,7 +352,7 @@ void CmndBacklog(void)
#else #else
TasmotaGlobal.backlog_pointer = TasmotaGlobal.backlog_index; TasmotaGlobal.backlog_pointer = TasmotaGlobal.backlog_index;
#endif #endif
ResponseCmndChar(blflag ? D_JSON_EMPTY : D_JSON_ABORTED); ResponseCmndChar(blflag ? PSTR(D_JSON_EMPTY) : PSTR(D_JSON_ABORTED));
} }
} }
@ -1282,7 +1282,7 @@ void CmndTemplate(void)
if (Settings.module != USER_MODULE) { if (Settings.module != USER_MODULE) {
ModuleDefault(Settings.module); ModuleDefault(Settings.module);
} }
SettingsUpdateText(SET_TEMPLATE_NAME, "Merged"); SettingsUpdateText(SET_TEMPLATE_NAME, PSTR("Merged"));
uint32_t j = 0; uint32_t j = 0;
for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) {
if (6 == i) { j = 9; } if (6 == i) { j = 9; }

View File

@ -38,7 +38,7 @@ void StartMdns(void) {
// mdns_delayed_start = Settings.param[P_MDNS_DELAYED_START]; // mdns_delayed_start = Settings.param[P_MDNS_DELAYED_START];
MDNS.end(); // close existing or MDNS.begin will fail MDNS.end(); // close existing or MDNS.begin will fail
Mdns.begun = (uint8_t)MDNS.begin(TasmotaGlobal.hostname); Mdns.begun = (uint8_t)MDNS.begin(TasmotaGlobal.hostname);
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_MDNS "%s"), (Mdns.begun) ? D_INITIALIZED : D_FAILED); AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_MDNS "%s"), (Mdns.begun) ? PSTR(D_INITIALIZED) : PSTR(D_FAILED));
// } // }
} }
} }

View File

@ -33,8 +33,8 @@ const uint32_t MINS_PER_HOUR = 60UL;
Ticker TickerRtc; Ticker TickerRtc;
static const uint8_t kDaysInMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // API starts months from 1, this array starts from 0 static const uint8_t kDaysInMonth[] PROGMEM = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // API starts months from 1, this array starts from 0
static const char kMonthNamesEnglish[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; static const char kMonthNamesEnglish[] PROGMEM = "JanFebMarAprMayJunJulAugSepOctNovDec";
struct RTC { struct RTC {
uint32_t utc_time = 0; uint32_t utc_time = 0;
@ -88,7 +88,9 @@ String GetBuildDateAndTime(void)
// "2017-03-07T11:08:02" - ISO8601:2004 // "2017-03-07T11:08:02" - ISO8601:2004
char bdt[21]; char bdt[21];
char *p; char *p;
char mdate[] = __DATE__; // "Mar 7 2017" static const char mdate_P[] PROGMEM = __DATE__; // "Mar 7 2017"
char mdate[strlen_P(mdate_P)+1]; // copy on stack first
strcpy_P(mdate, mdate_P);
char *smonth = mdate; char *smonth = mdate;
int day = 0; int day = 0;
int year = 0; int year = 0;
@ -107,8 +109,10 @@ String GetBuildDateAndTime(void)
year = atoi(str); year = atoi(str);
} }
} }
int month = (strstr(kMonthNamesEnglish, smonth) -kMonthNamesEnglish) /3 +1; char MonthNamesEnglish[sizeof(kMonthNamesEnglish)];
snprintf_P(bdt, sizeof(bdt), PSTR("%d" D_YEAR_MONTH_SEPARATOR "%02d" D_MONTH_DAY_SEPARATOR "%02d" D_DATE_TIME_SEPARATOR "%s"), year, month, day, __TIME__); strcpy_P(MonthNamesEnglish, kMonthNamesEnglish);
int month = (strstr(MonthNamesEnglish, smonth) -MonthNamesEnglish) /3 +1;
snprintf_P(bdt, sizeof(bdt), PSTR("%d" D_YEAR_MONTH_SEPARATOR "%02d" D_MONTH_DAY_SEPARATOR "%02d" D_DATE_TIME_SEPARATOR "%s"), year, month, day, PSTR(__TIME__));
return String(bdt); // 2017-03-07T11:08:02 return String(bdt); // 2017-03-07T11:08:02
} }
@ -290,7 +294,7 @@ void BreakTime(uint32_t time_input, TIME_T &tm)
month_length = 28; month_length = 28;
} }
} else { } else {
month_length = kDaysInMonth[month]; month_length = pgm_read_byte(&kDaysInMonth[month]);
} }
if (time >= month_length) { if (time >= month_length) {
@ -326,7 +330,7 @@ uint32_t MakeTime(TIME_T &tm)
if ((2 == i) && LEAP_YEAR(tm.year)) { if ((2 == i) && LEAP_YEAR(tm.year)) {
seconds += SECS_PER_DAY * 29; seconds += SECS_PER_DAY * 29;
} else { } else {
seconds += SECS_PER_DAY * kDaysInMonth[i-1]; // monthDay array starts from 0 seconds += SECS_PER_DAY * pgm_read_byte(&kDaysInMonth[i-1]); // monthDay array starts from 0
} }
} }
seconds+= (tm.day_of_month - 1) * SECS_PER_DAY; seconds+= (tm.day_of_month - 1) * SECS_PER_DAY;

View File

@ -20,10 +20,12 @@
const char kSleepMode[] PROGMEM = "Dynamic|Normal"; const char kSleepMode[] PROGMEM = "Dynamic|Normal";
const char kPrefixes[] PROGMEM = D_CMND "|" D_STAT "|" D_TELE; const char kPrefixes[] PROGMEM = D_CMND "|" D_STAT "|" D_TELE;
char* Format(char* output, const char* input, int size) char* Format(char* output, const char* input_p, int size)
{ {
char *token; char *token;
uint32_t digits = 0; uint32_t digits = 0;
char input[strlen_P(input_p)+1]; // copy from PMEM to RAM
strcpy_P(input, input_p);
if (strchr(input, '%') != nullptr) { if (strchr(input, '%') != nullptr) {
strlcpy(output, input, size); strlcpy(output, input, size);
@ -102,7 +104,7 @@ char* GetTopic_P(char *stopic, uint32_t prefix, char *topic, const char* subtopi
fulltopic += TasmotaGlobal.mqtt_client; fulltopic += TasmotaGlobal.mqtt_client;
fulltopic += F("_fb"); // cmnd/<mqttclient>_fb fulltopic += F("_fb"); // cmnd/<mqttclient>_fb
} else { } else {
fulltopic += topic; // cmnd/<grouptopic> fulltopic += (const __FlashStringHelper *)topic; // cmnd/<grouptopic>
} }
} else { } else {
fulltopic = SettingsText(SET_MQTT_FULLTOPIC); fulltopic = SettingsText(SET_MQTT_FULLTOPIC);
@ -118,7 +120,7 @@ char* GetTopic_P(char *stopic, uint32_t prefix, char *topic, const char* subtopi
} }
fulltopic.replace(FPSTR(MQTT_TOKEN_PREFIX), SettingsText(SET_MQTTPREFIX1 + prefix)); fulltopic.replace(FPSTR(MQTT_TOKEN_PREFIX), SettingsText(SET_MQTTPREFIX1 + prefix));
fulltopic.replace(FPSTR(MQTT_TOKEN_TOPIC), topic); fulltopic.replace(FPSTR(MQTT_TOKEN_TOPIC), (const __FlashStringHelper *)topic);
fulltopic.replace(F("%hostname%"), TasmotaGlobal.hostname); fulltopic.replace(F("%hostname%"), TasmotaGlobal.hostname);
String token_id = WiFi.macAddress(); String token_id = WiFi.macAddress();
token_id.replace(":", ""); token_id.replace(":", "");
@ -486,7 +488,7 @@ bool SendKey(uint32_t key, uint32_t device, uint32_t state)
#endif // USE_DOMOTICZ #endif // USE_DOMOTICZ
result = !Settings.flag3.button_switch_force_local; // SetOption61 - Force local operation when button/switch topic is set result = !Settings.flag3.button_switch_force_local; // SetOption61 - Force local operation when button/switch topic is set
} else { } else {
Response_P(PSTR("{\"%s%d\":{\"State\":%d}}"), (key) ? "Switch" : "Button", device, state); Response_P(PSTR("{\"%s%d\":{\"State\":%d}}"), (key) ? PSTR("Switch") : PSTR("Button"), device, state);
result = XdrvRulesProcess(); result = XdrvRulesProcess();
} }
#ifdef USE_PWM_DIMMER #ifdef USE_PWM_DIMMER
@ -742,7 +744,8 @@ void TempHumDewShow(bool json, bool pass_on, const char *types, float f_temperat
String GetSwitchText(uint32_t i) { String GetSwitchText(uint32_t i) {
String switch_text = SettingsText(SET_SWITCH_TXT1 + i); String switch_text = SettingsText(SET_SWITCH_TXT1 + i);
if ('\0' == switch_text[0]) { if ('\0' == switch_text[0]) {
switch_text = D_JSON_SWITCH + String(i +1); switch_text = F(D_JSON_SWITCH);
switch_text += String(i+1);
} }
return switch_text; return switch_text;
} }

View File

@ -176,7 +176,7 @@ void WiFiSetSleepMode(void)
void WifiBegin(uint8_t flag, uint8_t channel) void WifiBegin(uint8_t flag, uint8_t channel)
{ {
const char kWifiPhyMode[] = " bgnl"; const static char kWifiPhyMode[] PROGMEM = " bgnl";
#ifdef USE_EMULATION #ifdef USE_EMULATION
UdpDisconnect(); UdpDisconnect();
@ -218,7 +218,7 @@ void WifiBegin(uint8_t flag, uint8_t channel)
WiFi.begin(SettingsText(SET_STASSID1 + Settings.sta_active), SettingsText(SET_STAPWD1 + Settings.sta_active)); WiFi.begin(SettingsText(SET_STASSID1 + Settings.sta_active), SettingsText(SET_STAPWD1 + Settings.sta_active));
} }
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_WIFI D_CONNECTING_TO_AP "%d %s%s " D_IN_MODE " 11%c " D_AS " %s..."), AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_WIFI D_CONNECTING_TO_AP "%d %s%s " D_IN_MODE " 11%c " D_AS " %s..."),
Settings.sta_active +1, SettingsText(SET_STASSID1 + Settings.sta_active), stemp, kWifiPhyMode[WiFi.getPhyMode() & 0x3], TasmotaGlobal.hostname); Settings.sta_active +1, SettingsText(SET_STASSID1 + Settings.sta_active), stemp, pgm_read_byte(&kWifiPhyMode[WiFi.getPhyMode() & 0x3]), TasmotaGlobal.hostname);
#if LWIP_IPV6 #if LWIP_IPV6
for (bool configured = false; !configured;) { for (bool configured = false; !configured;) {

View File

@ -302,7 +302,7 @@ void setup(void) {
snprintf_P(TasmotaGlobal.version, sizeof(TasmotaGlobal.version), PSTR("%s.%d"), TasmotaGlobal.version, VERSION & 0xff); snprintf_P(TasmotaGlobal.version, sizeof(TasmotaGlobal.version), PSTR("%s.%d"), TasmotaGlobal.version, VERSION & 0xff);
} }
// Thehackbox inserts "release" or "commit number" before compiling using sed -i -e 's/PSTR("(%s)")/PSTR("(85cff52-%s)")/g' tasmota.ino // Thehackbox inserts "release" or "commit number" before compiling using sed -i -e 's/PSTR("(%s)")/PSTR("(85cff52-%s)")/g' tasmota.ino
snprintf_P(TasmotaGlobal.image_name, sizeof(TasmotaGlobal.image_name), PSTR("(%s)"), CODE_IMAGE_STR); // Results in (85cff52-tasmota) or (release-tasmota) snprintf_P(TasmotaGlobal.image_name, sizeof(TasmotaGlobal.image_name), PSTR("(%s)"), PSTR(CODE_IMAGE_STR)); // Results in (85cff52-tasmota) or (release-tasmota)
Format(TasmotaGlobal.mqtt_client, SettingsText(SET_MQTT_CLIENT), sizeof(TasmotaGlobal.mqtt_client)); Format(TasmotaGlobal.mqtt_client, SettingsText(SET_MQTT_CLIENT), sizeof(TasmotaGlobal.mqtt_client));
Format(TasmotaGlobal.mqtt_topic, SettingsText(SET_MQTT_TOPIC), sizeof(TasmotaGlobal.mqtt_topic)); Format(TasmotaGlobal.mqtt_topic, SettingsText(SET_MQTT_TOPIC), sizeof(TasmotaGlobal.mqtt_topic));
@ -321,7 +321,7 @@ void setup(void) {
SetPowerOnState(); SetPowerOnState();
AddLog_P(LOG_LEVEL_INFO, PSTR(D_PROJECT " %s %s " D_VERSION " %s%s-" ARDUINO_CORE_RELEASE "(%s)"), AddLog_P(LOG_LEVEL_INFO, PSTR(D_PROJECT " %s %s " D_VERSION " %s%s-" ARDUINO_CORE_RELEASE "(%s)"),
PROJECT, SettingsText(SET_DEVICENAME), TasmotaGlobal.version, TasmotaGlobal.image_name, GetBuildDateAndTime().c_str()); PSTR(PROJECT), SettingsText(SET_DEVICENAME), TasmotaGlobal.version, TasmotaGlobal.image_name, GetBuildDateAndTime().c_str());
#ifdef FIRMWARE_MINIMAL #ifdef FIRMWARE_MINIMAL
AddLog_P(LOG_LEVEL_INFO, PSTR(D_WARNING_MINIMAL_VERSION)); AddLog_P(LOG_LEVEL_INFO, PSTR(D_WARNING_MINIMAL_VERSION));
#endif // FIRMWARE_MINIMAL #endif // FIRMWARE_MINIMAL

View File

@ -57,6 +57,7 @@
#define USE_SPI #define USE_SPI
#define USE_DISPLAY // Add SPI Display Support (+2k code) #define USE_DISPLAY // Add SPI Display Support (+2k code)
#define USE_DISPLAY_ILI9341 // [DisplayModel 4] Enable ILI9341 Tft 480x320 display (+19k code) #define USE_DISPLAY_ILI9341 // [DisplayModel 4] Enable ILI9341 Tft 480x320 display (+19k code)
#define USE_BLE_ESP32 // Enable new BLE driver
#define USE_MI_ESP32 // (ESP32 only) Add support for ESP32 as a BLE-bridge (+9k2 mem, +292k flash) #define USE_MI_ESP32 // (ESP32 only) Add support for ESP32 as a BLE-bridge (+9k2 mem, +292k flash)
#endif // FIRMWARE_ODROID_GO #endif // FIRMWARE_ODROID_GO

View File

@ -376,9 +376,10 @@ struct WEB {
} Web; } Web;
// Helper function to avoid code duplication (saves 4k Flash) // Helper function to avoid code duplication (saves 4k Flash)
// arg can be in PROGMEM
static void WebGetArg(const char* arg, char* out, size_t max) static void WebGetArg(const char* arg, char* out, size_t max)
{ {
String s = Webserver->arg(arg); String s = Webserver->arg((const __FlashStringHelper *)arg);
strlcpy(out, s.c_str(), max); strlcpy(out, s.c_str(), max);
// out[max-1] = '\0'; // Ensure terminating NUL // out[max-1] = '\0'; // Ensure terminating NUL
} }
@ -460,7 +461,7 @@ void StartWebserver(int type, IPAddress ipweb)
WebServer_on(uri, line.handler, pgm_read_byte(&line.method)); WebServer_on(uri, line.handler, pgm_read_byte(&line.method));
} }
Webserver->onNotFound(HandleNotFound); Webserver->onNotFound(HandleNotFound);
Webserver->on("/u2", HTTP_POST, HandleUploadDone, HandleUploadLoop); // this call requires 2 functions so we keep a direct call Webserver->on(F("/u2"), HTTP_POST, HandleUploadDone, HandleUploadLoop); // this call requires 2 functions so we keep a direct call
#ifndef FIRMWARE_MINIMAL #ifndef FIRMWARE_MINIMAL
XdrvCall(FUNC_WEB_ADD_HANDLER); XdrvCall(FUNC_WEB_ADD_HANDLER);
XsnsCall(FUNC_WEB_ADD_HANDLER); XsnsCall(FUNC_WEB_ADD_HANDLER);
@ -691,7 +692,7 @@ void WSContentStart_P(const char* title, bool auth)
WSContentBegin(200, CT_HTML); WSContentBegin(200, CT_HTML);
if (title != nullptr) { if (title != nullptr) {
WSContentSend_P(HTTP_HEADER1, D_HTML_LANGUAGE, SettingsText(SET_DEVICENAME), title); WSContentSend_P(HTTP_HEADER1, PSTR(D_HTML_LANGUAGE), SettingsText(SET_DEVICENAME), title);
} }
} }
@ -767,7 +768,7 @@ void WSContentButton(uint32_t title_index)
WSContentSend_P(PSTR("<p><form action='%s' method='get' onsubmit='return confirm(\"%s\");'><button name='%s' class='button bred'>%s</button></form></p>"), WSContentSend_P(PSTR("<p><form action='%s' method='get' onsubmit='return confirm(\"%s\");'><button name='%s' class='button bred'>%s</button></form></p>"),
GetTextIndexed(action, sizeof(action), title_index, kButtonAction), GetTextIndexed(action, sizeof(action), title_index, kButtonAction),
GetTextIndexed(confirm, sizeof(confirm), title_index, kButtonConfirm), GetTextIndexed(confirm, sizeof(confirm), title_index, kButtonConfirm),
(!title_index) ? "rst" : "non", (!title_index) ? PSTR("rst") : PSTR("non"),
GetTextIndexed(title, sizeof(title), title_index, kButtonTitle)); GetTextIndexed(title, sizeof(title), title_index, kButtonTitle));
} else { } else {
WSContentSend_P(PSTR("<p><form action='%s' method='get'><button>%s</button></form></p>"), WSContentSend_P(PSTR("<p><form action='%s' method='get'><button>%s</button></form></p>"),
@ -866,8 +867,8 @@ void HandleWifiLogin(void)
void WebSliderColdWarm(void) void WebSliderColdWarm(void)
{ {
WSContentSend_P(HTTP_MSG_SLIDER_GRADIENT, // Cold Warm WSContentSend_P(HTTP_MSG_SLIDER_GRADIENT, // Cold Warm
"a", // a - Unique HTML id PSTR("a"), // a - Unique HTML id
"#eff", "#f81", // 6500k in RGB (White) to 2500k in RGB (Warm Yellow) PSTR("#eff"), PSTR("#f81"), // 6500k in RGB (White) to 2500k in RGB (Warm Yellow)
1, // sl1 1, // sl1
153, 500, // Range color temperature 153, 500, // Range color temperature
LightGetColorTemp(), LightGetColorTemp(),
@ -879,17 +880,17 @@ void HandleRoot(void)
{ {
if (CaptivePortal()) { return; } // If captive portal redirect instead of displaying the page. if (CaptivePortal()) { return; } // If captive portal redirect instead of displaying the page.
if (Webserver->hasArg("rst")) { if (Webserver->hasArg(F("rst"))) {
WebRestart(0); WebRestart(0);
return; return;
} }
if (WifiIsInManagerMode()) { if (WifiIsInManagerMode()) {
#ifndef FIRMWARE_MINIMAL #ifndef FIRMWARE_MINIMAL
if (strlen(SettingsText(SET_WEBPWD)) && !(Webserver->hasArg("USER1")) && !(Webserver->hasArg("PASS1")) && HTTP_MANAGER_RESET_ONLY != Web.state) { if (strlen(SettingsText(SET_WEBPWD)) && !(Webserver->hasArg(F("USER1"))) && !(Webserver->hasArg(F("PASS1"))) && HTTP_MANAGER_RESET_ONLY != Web.state) {
HandleWifiLogin(); HandleWifiLogin();
} else { } else {
if (!strlen(SettingsText(SET_WEBPWD)) || (((Webserver->arg("USER1") == WEB_USERNAME ) && (Webserver->arg("PASS1") == SettingsText(SET_WEBPWD) )) || HTTP_MANAGER_RESET_ONLY == Web.state)) { if (!strlen(SettingsText(SET_WEBPWD)) || (((Webserver->arg(F("USER1")) == WEB_USERNAME ) && (Webserver->arg(F("PASS1")) == SettingsText(SET_WEBPWD) )) || HTTP_MANAGER_RESET_ONLY == Web.state)) {
HandleWifiConfiguration(); HandleWifiConfiguration();
} else { } else {
// wrong user and pass // wrong user and pass
@ -936,8 +937,8 @@ void HandleRoot(void)
LightGetHSB(&hue, &sat, nullptr); LightGetHSB(&hue, &sat, nullptr);
WSContentSend_P(HTTP_MSG_SLIDER_GRADIENT, // Hue WSContentSend_P(HTTP_MSG_SLIDER_GRADIENT, // Hue
"b", // b - Unique HTML id PSTR("b"), // b - Unique HTML id
"#800", PSTR("#f00 5%,#ff0 20%,#0f0 35%,#0ff 50%,#00f 65%,#f0f 80%,#f00 95%,#800"), // Hue colors PSTR("#800"), PSTR("#f00 5%,#ff0 20%,#0f0 35%,#0ff 50%,#00f 65%,#f0f 80%,#f00 95%,#800"), // Hue colors
2, // sl2 - Unique range HTML id - Used as source for Saturation end color 2, // sl2 - Unique range HTML id - Used as source for Saturation end color
1, 359, // Range valid Hue 1, 359, // Range valid Hue
hue, hue,
@ -951,7 +952,7 @@ void HandleRoot(void)
snprintf_P(stemp, sizeof(stemp), PSTR("#%02X%02X%02X"), red, green, blue); // Saturation end color snprintf_P(stemp, sizeof(stemp), PSTR("#%02X%02X%02X"), red, green, blue); // Saturation end color
WSContentSend_P(HTTP_MSG_SLIDER_GRADIENT, // Saturation WSContentSend_P(HTTP_MSG_SLIDER_GRADIENT, // Saturation
"s", // s - Unique HTML id related to eb('s').style.background='linear-gradient(to right,rgb('+sl+'%%,'+sl+'%%,'+sl+'%%),hsl('+eb('sl2').value+',100%%,50%%))'; PSTR("s"), // s - Unique HTML id related to eb('s').style.background='linear-gradient(to right,rgb('+sl+'%%,'+sl+'%%,'+sl+'%%),hsl('+eb('sl2').value+',100%%,50%%))';
scolor, stemp, // Brightness to max current color scolor, stemp, // Brightness to max current color
3, // sl3 - Unique range HTML id - Not used 3, // sl3 - Unique range HTML id - Not used
0, 100, // Range 0 to 100% 0, 100, // Range 0 to 100%
@ -960,8 +961,8 @@ void HandleRoot(void)
} }
WSContentSend_P(HTTP_MSG_SLIDER_GRADIENT, // Brightness - Black to White WSContentSend_P(HTTP_MSG_SLIDER_GRADIENT, // Brightness - Black to White
"c", // c - Unique HTML id PSTR("c"), // c - Unique HTML id
"#000", "#fff", // Black to White PSTR("#000"), PSTR("#fff"), // Black to White
4, // sl4 - Unique range HTML id - Used as source for Saturation begin color 4, // sl4 - Unique range HTML id - Used as source for Saturation begin color
Settings.flag3.slider_dimmer_stay_on, 100, // Range 0/1 to 100% (SetOption77 - Do not power off if slider moved to far left) Settings.flag3.slider_dimmer_stay_on, 100, // Range 0/1 to 100% (SetOption77 - Do not power off if slider moved to far left)
Settings.light_dimmer, Settings.light_dimmer,
@ -972,8 +973,8 @@ void HandleRoot(void)
WebSliderColdWarm(); WebSliderColdWarm();
} }
WSContentSend_P(HTTP_MSG_SLIDER_GRADIENT, // White brightness - Black to White WSContentSend_P(HTTP_MSG_SLIDER_GRADIENT, // White brightness - Black to White
"f", // f - Unique HTML id PSTR("f"), // f - Unique HTML id
"#000", "#fff", // Black to White PSTR("#000"), PSTR("#fff"), // Black to White
5, // sl5 - Unique range HTML id - Not used 5, // sl5 - Unique range HTML id - Not used
Settings.flag3.slider_dimmer_stay_on, 100, // Range 0/1 to 100% (SetOption77 - Do not power off if slider moved to far left) Settings.flag3.slider_dimmer_stay_on, 100, // Range 0/1 to 100% (SetOption77 - Do not power off if slider moved to far left)
LightGetDimmer(2), LightGetDimmer(2),
@ -987,7 +988,7 @@ void HandleRoot(void)
WSContentSend_P(HTTP_MSG_SLIDER_GRADIENT, // Channel brightness - Black to White WSContentSend_P(HTTP_MSG_SLIDER_GRADIENT, // Channel brightness - Black to White
stemp, // e1 to e5 - Unique HTML id stemp, // e1 to e5 - Unique HTML id
"#000", "#fff", // Black to White PSTR("#000"), PSTR("#fff"), // Black to White
i+1, // sl1 to sl5 - Unique range HTML id - Not used i+1, // sl1 to sl5 - Unique range HTML id - Not used
1, 100, // Range 1 to 100% 1, 100, // Range 1 to 100%
changeUIntScale(Settings.light_color[i], 0, 255, 0, 100), changeUIntScale(Settings.light_color[i], 0, 255, 0, 100),
@ -1008,7 +1009,7 @@ void HandleRoot(void)
#ifdef USE_SONOFF_IFAN #ifdef USE_SONOFF_IFAN
if (IsModuleIfan()) { if (IsModuleIfan()) {
WSContentSend_P(HTTP_DEVICE_CONTROL, 36, 1, WSContentSend_P(HTTP_DEVICE_CONTROL, 36, 1,
(strlen(SettingsText(SET_BUTTON1))) ? SettingsText(SET_BUTTON1) : D_BUTTON_TOGGLE, (strlen(SettingsText(SET_BUTTON1))) ? SettingsText(SET_BUTTON1) : PSTR(D_BUTTON_TOGGLE),
""); "");
for (uint32_t i = 0; i < MaxFanspeed(); i++) { for (uint32_t i = 0; i < MaxFanspeed(); i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("%d"), i); snprintf_P(stemp, sizeof(stemp), PSTR("%d"), i);
@ -1031,7 +1032,7 @@ void HandleRoot(void)
#endif // USE_SHUTTER #endif // USE_SHUTTER
snprintf_P(stemp, sizeof(stemp), PSTR(" %d"), idx); snprintf_P(stemp, sizeof(stemp), PSTR(" %d"), idx);
WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / TasmotaGlobal.devices_present, idx, WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / TasmotaGlobal.devices_present, idx,
(set_button) ? SettingsText(SET_BUTTON1 + idx -1) : (TasmotaGlobal.devices_present < 5) ? D_BUTTON_TOGGLE : "", (set_button) ? SettingsText(SET_BUTTON1 + idx -1) : (TasmotaGlobal.devices_present < 5) ? PSTR(D_BUTTON_TOGGLE) : "",
(set_button) ? "" : (TasmotaGlobal.devices_present > 1) ? stemp : ""); (set_button) ? "" : (TasmotaGlobal.devices_present > 1) ? stemp : "");
} }
#ifdef USE_SONOFF_IFAN #ifdef USE_SONOFF_IFAN
@ -1107,7 +1108,7 @@ bool HandleRootStatusRefresh(void)
char svalue[32]; // Command and number parameter char svalue[32]; // Command and number parameter
char webindex[5]; // WebGetArg name char webindex[5]; // WebGetArg name
WebGetArg("o", tmp, sizeof(tmp)); // 1 - 16 Device number for button Toggle or Fanspeed WebGetArg(PSTR("o"), tmp, sizeof(tmp)); // 1 - 16 Device number for button Toggle or Fanspeed
if (strlen(tmp)) { if (strlen(tmp)) {
ShowWebSource(SRC_WEBGUI); ShowWebSource(SRC_WEBGUI);
uint32_t device = atoi(tmp); uint32_t device = atoi(tmp);
@ -1153,12 +1154,12 @@ bool HandleRootStatusRefresh(void)
#endif // USE_TUYA_MCU #endif // USE_TUYA_MCU
} }
#ifdef USE_LIGHT #ifdef USE_LIGHT
WebGetArg("d0", tmp, sizeof(tmp)); // 0 - 100 Dimmer value WebGetArg(PSTR("d0"), tmp, sizeof(tmp)); // 0 - 100 Dimmer value
if (strlen(tmp)) { if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_DIMMER " %s"), tmp); snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_DIMMER " %s"), tmp);
ExecuteWebCommand(svalue, SRC_WEBGUI); ExecuteWebCommand(svalue, SRC_WEBGUI);
} }
WebGetArg("w0", tmp, sizeof(tmp)); // 0 - 100 White value WebGetArg(PSTR("w0"), tmp, sizeof(tmp)); // 0 - 100 White value
if (strlen(tmp)) { if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_WHITE " %s"), tmp); snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_WHITE " %s"), tmp);
ExecuteWebCommand(svalue, SRC_WEBGUI); ExecuteWebCommand(svalue, SRC_WEBGUI);
@ -1173,17 +1174,17 @@ bool HandleRootStatusRefresh(void)
ExecuteWebCommand(svalue, SRC_WEBGUI); ExecuteWebCommand(svalue, SRC_WEBGUI);
} }
} }
WebGetArg("t0", tmp, sizeof(tmp)); // 153 - 500 Color temperature WebGetArg(PSTR("t0"), tmp, sizeof(tmp)); // 153 - 500 Color temperature
if (strlen(tmp)) { if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_COLORTEMPERATURE " %s"), tmp); snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_COLORTEMPERATURE " %s"), tmp);
ExecuteWebCommand(svalue, SRC_WEBGUI); ExecuteWebCommand(svalue, SRC_WEBGUI);
} }
WebGetArg("h0", tmp, sizeof(tmp)); // 0 - 359 Hue value WebGetArg(PSTR("h0"), tmp, sizeof(tmp)); // 0 - 359 Hue value
if (strlen(tmp)) { if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_HSBCOLOR "1 %s"), tmp); snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_HSBCOLOR "1 %s"), tmp);
ExecuteWebCommand(svalue, SRC_WEBGUI); ExecuteWebCommand(svalue, SRC_WEBGUI);
} }
WebGetArg("n0", tmp, sizeof(tmp)); // 0 - 99 Saturation value WebGetArg(PSTR("n0"), tmp, sizeof(tmp)); // 0 - 99 Saturation value
if (strlen(tmp)) { if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_HSBCOLOR "2 %s"), tmp); snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_HSBCOLOR "2 %s"), tmp);
ExecuteWebCommand(svalue, SRC_WEBGUI); ExecuteWebCommand(svalue, SRC_WEBGUI);
@ -1200,19 +1201,19 @@ bool HandleRootStatusRefresh(void)
} }
#endif // USE_SHUTTER #endif // USE_SHUTTER
#ifdef USE_SONOFF_RF #ifdef USE_SONOFF_RF
WebGetArg("k", tmp, sizeof(tmp)); // 1 - 16 Pre defined RF keys WebGetArg(PSTR("k"), tmp, sizeof(tmp)); // 1 - 16 Pre defined RF keys
if (strlen(tmp)) { if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_RFKEY "%s"), tmp); snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_RFKEY "%s"), tmp);
ExecuteWebCommand(svalue, SRC_WEBGUI); ExecuteWebCommand(svalue, SRC_WEBGUI);
} }
#endif // USE_SONOFF_RF #endif // USE_SONOFF_RF
#ifdef USE_ZIGBEE #ifdef USE_ZIGBEE
WebGetArg("zbj", tmp, sizeof(tmp)); WebGetArg(PSTR("zbj"), tmp, sizeof(tmp));
if (strlen(tmp)) { if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR("ZbPermitJoin")); snprintf_P(svalue, sizeof(svalue), PSTR("ZbPermitJoin"));
ExecuteWebCommand(svalue, SRC_WEBGUI); ExecuteWebCommand(svalue, SRC_WEBGUI);
} }
WebGetArg("zbr", tmp, sizeof(tmp)); WebGetArg(PSTR("zbr"), tmp, sizeof(tmp));
if (strlen(tmp)) { if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR("ZbMap")); snprintf_P(svalue, sizeof(svalue), PSTR("ZbMap"));
ExecuteWebCommand(svalue, SRC_WEBGUI); ExecuteWebCommand(svalue, SRC_WEBGUI);
@ -1315,7 +1316,7 @@ void WSContentSendNiceLists(uint32_t option) {
char stemp[30]; // Template number and Sensor name char stemp[30]; // Template number and Sensor name
for (uint32_t i = 0; i < ARRAY_SIZE(kGpioNiceList); i++) { // GPIO: }2'0'>None (0)}3}2'17'>Button1 (17)}3... for (uint32_t i = 0; i < ARRAY_SIZE(kGpioNiceList); i++) { // GPIO: }2'0'>None (0)}3}2'17'>Button1 (17)}3...
if (option && (1 == i)) { if (option && (1 == i)) {
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE_NO_INDEX, AGPIO(GPIO_USER), D_SENSOR_USER); // }2'255'>User}3 WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE_NO_INDEX, AGPIO(GPIO_USER), PSTR(D_SENSOR_USER)); // }2'255'>User}3
} }
uint32_t ridx = pgm_read_word(kGpioNiceList + i) & 0xFFE0; uint32_t ridx = pgm_read_word(kGpioNiceList + i) & 0xFFE0;
uint32_t midx = BGPIO(ridx); uint32_t midx = BGPIO(ridx);
@ -1356,7 +1357,7 @@ void WSContentSendAdcNiceList(uint32_t option) {
WSContentSend_P(PSTR("os=\"")); WSContentSend_P(PSTR("os=\""));
for (uint32_t i = 0; i < ARRAY_SIZE(kAdcNiceList); i++) { // GPIO: }2'0'>None}3}2'17'>Analog}3... for (uint32_t i = 0; i < ARRAY_SIZE(kAdcNiceList); i++) { // GPIO: }2'0'>None}3}2'17'>Analog}3...
if (option && (1 == i)) { if (option && (1 == i)) {
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE_NO_INDEX, AGPIO(GPIO_USER), D_SENSOR_USER); // }2'15'>User}3 WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE_NO_INDEX, AGPIO(GPIO_USER), PSTR(D_SENSOR_USER)); // }2'15'>User}3
} }
uint32_t ridx = pgm_read_word(kAdcNiceList + i) & 0xFFE0; uint32_t ridx = pgm_read_word(kAdcNiceList + i) & 0xFFE0;
uint32_t midx = BGPIO(ridx); uint32_t midx = BGPIO(ridx);
@ -1372,7 +1373,7 @@ void HandleTemplateConfiguration(void)
{ {
if (!HttpCheckPriviledgedAccess()) { return; } if (!HttpCheckPriviledgedAccess()) { return; }
if (Webserver->hasArg("save")) { if (Webserver->hasArg(F("save"))) {
TemplateSaveSettings(); TemplateSaveSettings();
WebRestart(1); WebRestart(1);
return; return;
@ -1380,7 +1381,7 @@ void HandleTemplateConfiguration(void)
char stemp[30]; // Template number and Sensor name char stemp[30]; // Template number and Sensor name
WebGetArg("t", stemp, sizeof(stemp)); // 0 - 69 Template number WebGetArg(PSTR("t"), stemp, sizeof(stemp)); // 0 - 69 Template number
if (strlen(stemp)) { if (strlen(stemp)) {
uint32_t module = atoi(stemp); uint32_t module = atoi(stemp);
uint32_t module_save = Settings.module; uint32_t module_save = Settings.module;
@ -1474,7 +1475,7 @@ void TemplateSaveSettings(void)
char tmp[TOPSZ]; // WebGetArg NAME and GPIO/BASE/FLAG byte value char tmp[TOPSZ]; // WebGetArg NAME and GPIO/BASE/FLAG byte value
char svalue[300]; // Template command string char svalue[300]; // Template command string
WebGetArg("s1", tmp, sizeof(tmp)); // NAME WebGetArg(PSTR("s1"), tmp, sizeof(tmp)); // NAME
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_TEMPLATE " {\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), tmp); snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_TEMPLATE " {\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), tmp);
uint32_t j = 0; uint32_t j = 0;
@ -1492,7 +1493,7 @@ void TemplateSaveSettings(void)
uint32_t state = Webserver->hasArg(webindex) << i; // FLAG uint32_t state = Webserver->hasArg(webindex) << i; // FLAG
flag += state; flag += state;
} }
WebGetArg("g99", tmp, sizeof(tmp)); // BASE WebGetArg(PSTR("g99"), tmp, sizeof(tmp)); // BASE
uint32_t base = atoi(tmp) +1; uint32_t base = atoi(tmp) +1;
snprintf_P(svalue, sizeof(svalue), PSTR("%s],\"" D_JSON_FLAG "\":%d,\"" D_JSON_BASE "\":%d}"), svalue, flag, base); snprintf_P(svalue, sizeof(svalue), PSTR("%s],\"" D_JSON_FLAG "\":%d,\"" D_JSON_BASE "\":%d}"), svalue, flag, base);
@ -1505,7 +1506,7 @@ void HandleModuleConfiguration(void)
{ {
if (!HttpCheckPriviledgedAccess()) { return; } if (!HttpCheckPriviledgedAccess()) { return; }
if (Webserver->hasArg("save")) { if (Webserver->hasArg(F("save"))) {
ModuleSaveSettings(); ModuleSaveSettings();
WebRestart(1); WebRestart(1);
return; return;
@ -1572,7 +1573,7 @@ void ModuleSaveSettings(void)
{ {
char tmp[8]; // WebGetArg numbers only char tmp[8]; // WebGetArg numbers only
WebGetArg("g99", tmp, sizeof(tmp)); WebGetArg(PSTR("g99"), tmp, sizeof(tmp));
uint32_t new_module = (!strlen(tmp)) ? MODULE : atoi(tmp); uint32_t new_module = (!strlen(tmp)) ? MODULE : atoi(tmp);
Settings.last_module = Settings.module; Settings.last_module = Settings.module;
Settings.module = new_module; Settings.module = new_module;
@ -1624,7 +1625,7 @@ void HandleWifiConfiguration(void)
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_WIFI)); AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_WIFI));
if (Webserver->hasArg("save") && HTTP_MANAGER_RESET_ONLY != Web.state) { if (Webserver->hasArg(F("save")) && HTTP_MANAGER_RESET_ONLY != Web.state) {
WifiSaveSettings(); WifiSaveSettings();
WebRestart(2); WebRestart(2);
return; return;
@ -1639,7 +1640,7 @@ void HandleWifiConfiguration(void)
#endif // USE_ENHANCED_GUI_WIFI_SCAN #endif // USE_ENHANCED_GUI_WIFI_SCAN
if (HTTP_MANAGER_RESET_ONLY != Web.state) { if (HTTP_MANAGER_RESET_ONLY != Web.state) {
if (Webserver->hasArg("scan")) { if (Webserver->hasArg(F("scan"))) {
#ifdef USE_EMULATION #ifdef USE_EMULATION
UdpDisconnect(); UdpDisconnect();
#endif // USE_EMULATION #endif // USE_EMULATION
@ -1776,20 +1777,20 @@ void WifiSaveSettings(void)
{ {
char tmp[TOPSZ]; // Max length is currently 150 char tmp[TOPSZ]; // Max length is currently 150
WebGetArg("h", tmp, sizeof(tmp)); WebGetArg(PSTR("h"), tmp, sizeof(tmp));
SettingsUpdateText(SET_HOSTNAME, (!strlen(tmp)) ? WIFI_HOSTNAME : tmp); SettingsUpdateText(SET_HOSTNAME, (!strlen(tmp)) ? WIFI_HOSTNAME : tmp);
if (strchr(SettingsText(SET_HOSTNAME), '%') != nullptr) { if (strchr(SettingsText(SET_HOSTNAME), '%') != nullptr) {
SettingsUpdateText(SET_HOSTNAME, WIFI_HOSTNAME); SettingsUpdateText(SET_HOSTNAME, WIFI_HOSTNAME);
} }
WebGetArg("c", tmp, sizeof(tmp)); WebGetArg(PSTR("c"), tmp, sizeof(tmp));
SettingsUpdateText(SET_CORS, (!strlen(tmp)) ? CORS_DOMAIN : tmp); SettingsUpdateText(SET_CORS, (!strlen(tmp)) ? CORS_DOMAIN : tmp);
WebGetArg("s1", tmp, sizeof(tmp)); WebGetArg(PSTR("s1"), tmp, sizeof(tmp));
SettingsUpdateText(SET_STASSID1, (!strlen(tmp)) ? STA_SSID1 : tmp); SettingsUpdateText(SET_STASSID1, (!strlen(tmp)) ? STA_SSID1 : tmp);
WebGetArg("s2", tmp, sizeof(tmp)); WebGetArg(PSTR("s2"), tmp, sizeof(tmp));
SettingsUpdateText(SET_STASSID2, (!strlen(tmp)) ? STA_SSID2 : tmp); SettingsUpdateText(SET_STASSID2, (!strlen(tmp)) ? STA_SSID2 : tmp);
WebGetArg("p1", tmp, sizeof(tmp)); WebGetArg(PSTR("p1"), tmp, sizeof(tmp));
SettingsUpdateText(SET_STAPWD1, (!strlen(tmp)) ? "" : (strlen(tmp) < 5) ? SettingsText(SET_STAPWD1) : tmp); SettingsUpdateText(SET_STAPWD1, (!strlen(tmp)) ? "" : (strlen(tmp) < 5) ? SettingsText(SET_STAPWD1) : tmp);
WebGetArg("p2", tmp, sizeof(tmp)); WebGetArg(PSTR("p2"), tmp, sizeof(tmp));
SettingsUpdateText(SET_STAPWD2, (!strlen(tmp)) ? "" : (strlen(tmp) < 5) ? SettingsText(SET_STAPWD2) : tmp); SettingsUpdateText(SET_STAPWD2, (!strlen(tmp)) ? "" : (strlen(tmp) < 5) ? SettingsText(SET_STAPWD2) : tmp);
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_WIFI D_CMND_HOSTNAME " %s, " D_CMND_SSID "1 %s, " D_CMND_SSID "2 %s, " D_CMND_CORS " %s"), AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_WIFI D_CMND_HOSTNAME " %s, " D_CMND_SSID "1 %s, " D_CMND_SSID "2 %s, " D_CMND_CORS " %s"),
SettingsText(SET_HOSTNAME), SettingsText(SET_STASSID1), SettingsText(SET_STASSID2), SettingsText(SET_CORS)); SettingsText(SET_HOSTNAME), SettingsText(SET_STASSID1), SettingsText(SET_STASSID2), SettingsText(SET_CORS));
@ -1839,19 +1840,19 @@ void LoggingSaveSettings(void)
{ {
char tmp[TOPSZ]; // Max length is currently 33 char tmp[TOPSZ]; // Max length is currently 33
WebGetArg("l0", tmp, sizeof(tmp)); WebGetArg(PSTR("l0"), tmp, sizeof(tmp));
SetSeriallog((!strlen(tmp)) ? SERIAL_LOG_LEVEL : atoi(tmp)); SetSeriallog((!strlen(tmp)) ? SERIAL_LOG_LEVEL : atoi(tmp));
WebGetArg("l1", tmp, sizeof(tmp)); WebGetArg(PSTR("l1"), tmp, sizeof(tmp));
Settings.weblog_level = (!strlen(tmp)) ? WEB_LOG_LEVEL : atoi(tmp); Settings.weblog_level = (!strlen(tmp)) ? WEB_LOG_LEVEL : atoi(tmp);
WebGetArg("l2", tmp, sizeof(tmp)); WebGetArg(PSTR("l2"), tmp, sizeof(tmp));
Settings.mqttlog_level = (!strlen(tmp)) ? MQTT_LOG_LEVEL : atoi(tmp); Settings.mqttlog_level = (!strlen(tmp)) ? MQTT_LOG_LEVEL : atoi(tmp);
WebGetArg("l3", tmp, sizeof(tmp)); WebGetArg(PSTR("l3"), tmp, sizeof(tmp));
SetSyslog((!strlen(tmp)) ? SYS_LOG_LEVEL : atoi(tmp)); SetSyslog((!strlen(tmp)) ? SYS_LOG_LEVEL : atoi(tmp));
WebGetArg("lh", tmp, sizeof(tmp)); WebGetArg(PSTR("lh"), tmp, sizeof(tmp));
SettingsUpdateText(SET_SYSLOG_HOST, (!strlen(tmp)) ? SYS_LOG_HOST : tmp); SettingsUpdateText(SET_SYSLOG_HOST, (!strlen(tmp)) ? SYS_LOG_HOST : tmp);
WebGetArg("lp", tmp, sizeof(tmp)); WebGetArg(PSTR("lp"), tmp, sizeof(tmp));
Settings.syslog_port = (!strlen(tmp)) ? SYS_LOG_PORT : atoi(tmp); Settings.syslog_port = (!strlen(tmp)) ? SYS_LOG_PORT : atoi(tmp);
WebGetArg("lt", tmp, sizeof(tmp)); WebGetArg(PSTR("lt"), tmp, sizeof(tmp));
Settings.tele_period = (!strlen(tmp)) ? TELE_PERIOD : atoi(tmp); Settings.tele_period = (!strlen(tmp)) ? TELE_PERIOD : atoi(tmp);
if ((Settings.tele_period > 0) && (Settings.tele_period < 10)) { if ((Settings.tele_period > 0) && (Settings.tele_period < 10)) {
Settings.tele_period = 10; // Do not allow periods < 10 seconds Settings.tele_period = 10; // Do not allow periods < 10 seconds
@ -1868,7 +1869,7 @@ void HandleOtherConfiguration(void)
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_OTHER)); AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_OTHER));
if (Webserver->hasArg("save")) { if (Webserver->hasArg(F("save"))) {
OtherSaveSettings(); OtherSaveSettings();
WebRestart(1); WebRestart(1);
return; return;
@ -1932,15 +1933,15 @@ void OtherSaveSettings(void)
char friendlyname[TOPSZ]; char friendlyname[TOPSZ];
char message[MAX_LOGSZ]; char message[MAX_LOGSZ];
WebGetArg("dn", tmp, sizeof(tmp)); WebGetArg(PSTR("dn"), tmp, sizeof(tmp));
SettingsUpdateText(SET_DEVICENAME, (!strlen(tmp)) ? "" : (!strcmp(tmp,"1")) ? SettingsText(SET_FRIENDLYNAME1) : tmp); SettingsUpdateText(SET_DEVICENAME, (!strlen(tmp)) ? "" : (!strcmp(tmp,"1")) ? SettingsText(SET_FRIENDLYNAME1) : tmp);
WebGetArg("wp", tmp, sizeof(tmp)); WebGetArg(PSTR("wp"), tmp, sizeof(tmp));
SettingsUpdateText(SET_WEBPWD, (!strlen(tmp)) ? "" : (strchr(tmp,'*')) ? SettingsText(SET_WEBPWD) : tmp); SettingsUpdateText(SET_WEBPWD, (!strlen(tmp)) ? "" : (strchr(tmp,'*')) ? SettingsText(SET_WEBPWD) : tmp);
Settings.flag.mqtt_enabled = Webserver->hasArg("b1"); // SetOption3 - Enable MQTT Settings.flag.mqtt_enabled = Webserver->hasArg(F("b1")); // SetOption3 - Enable MQTT
#ifdef USE_EMULATION #ifdef USE_EMULATION
UdpDisconnect(); UdpDisconnect();
#if defined(USE_EMULATION_WEMO) || defined(USE_EMULATION_HUE) #if defined(USE_EMULATION_WEMO) || defined(USE_EMULATION_HUE)
WebGetArg("b2", tmp, sizeof(tmp)); WebGetArg(PSTR("b2"), tmp, sizeof(tmp));
Settings.flag2.emulation = (!strlen(tmp)) ? 0 : atoi(tmp); Settings.flag2.emulation = (!strlen(tmp)) ? 0 : atoi(tmp);
#endif // USE_EMULATION_WEMO || USE_EMULATION_HUE #endif // USE_EMULATION_WEMO || USE_EMULATION_HUE
#endif // USE_EMULATION #endif // USE_EMULATION
@ -1951,14 +1952,14 @@ void OtherSaveSettings(void)
snprintf_P(webindex, sizeof(webindex), PSTR("a%d"), i); snprintf_P(webindex, sizeof(webindex), PSTR("a%d"), i);
WebGetArg(webindex, tmp, sizeof(tmp)); WebGetArg(webindex, tmp, sizeof(tmp));
snprintf_P(friendlyname, sizeof(friendlyname), PSTR(FRIENDLY_NAME"%d"), i +1); snprintf_P(friendlyname, sizeof(friendlyname), PSTR(FRIENDLY_NAME"%d"), i +1);
SettingsUpdateText(SET_FRIENDLYNAME1 +i, (!strlen(tmp)) ? (i) ? friendlyname : FRIENDLY_NAME : tmp); SettingsUpdateText(SET_FRIENDLYNAME1 +i, (!strlen(tmp)) ? (i) ? friendlyname : PSTR(FRIENDLY_NAME) : tmp);
snprintf_P(message, sizeof(message), PSTR("%s%s %s"), message, (i) ? "," : "", SettingsText(SET_FRIENDLYNAME1 +i)); snprintf_P(message, sizeof(message), PSTR("%s%s %s"), message, (i) ? "," : "", SettingsText(SET_FRIENDLYNAME1 +i));
} }
AddLogData(LOG_LEVEL_INFO, message); AddLogData(LOG_LEVEL_INFO, message);
WebGetArg("t1", tmp, sizeof(tmp)); WebGetArg(PSTR("t1"), tmp, sizeof(tmp));
if (strlen(tmp)) { // {"NAME":"12345678901234","GPIO":[255,255,255,255,255,255,255,255,255,255,255,255,255],"FLAG":255,"BASE":255} if (strlen(tmp)) { // {"NAME":"12345678901234","GPIO":[255,255,255,255,255,255,255,255,255,255,255,255,255],"FLAG":255,"BASE":255}
snprintf_P(message, sizeof(message), PSTR(D_CMND_BACKLOG " " D_CMND_TEMPLATE " %s%s"), tmp, (Webserver->hasArg("t2")) ? "; " D_CMND_MODULE " 0" : ""); snprintf_P(message, sizeof(message), PSTR(D_CMND_BACKLOG " " D_CMND_TEMPLATE " %s%s"), tmp, (Webserver->hasArg(F("t2"))) ? PSTR("; " D_CMND_MODULE " 0") : "");
ExecuteWebCommand(message, SRC_WEBGUI); ExecuteWebCommand(message, SRC_WEBGUI);
} }
} }
@ -2034,7 +2035,7 @@ void HandleRestoreConfiguration(void)
WSContentStart_P(PSTR(D_RESTORE_CONFIGURATION)); WSContentStart_P(PSTR(D_RESTORE_CONFIGURATION));
WSContentSendStyle(); WSContentSendStyle();
WSContentSend_P(HTTP_FORM_RST); WSContentSend_P(HTTP_FORM_RST);
WSContentSend_P(HTTP_FORM_RST_UPG, D_RESTORE); WSContentSend_P(HTTP_FORM_RST_UPG, PSTR(D_RESTORE));
if (WifiIsInManagerMode()) { if (WifiIsInManagerMode()) {
WSContentSpaceButton(BUTTON_MAIN); WSContentSpaceButton(BUTTON_MAIN);
} else { } else {
@ -2143,14 +2144,13 @@ void HandleInformation(void)
} else { } else {
WSContentSend_P(PSTR("}1" D_MQTT "}2" D_DISABLED)); WSContentSend_P(PSTR("}1" D_MQTT "}2" D_DISABLED));
} }
WSContentSend_P(PSTR("}1}2&nbsp;")); // Empty line
#if defined(USE_EMULATION) || defined(USE_DISCOVERY)
WSContentSend_P(PSTR("}1}2&nbsp;")); // Empty line
#endif // USE_EMULATION or USE_DISCOVERY
#ifdef USE_EMULATION #ifdef USE_EMULATION
WSContentSend_P(PSTR("}1" D_EMULATION "}2%s"), GetTextIndexed(stopic, sizeof(stopic), Settings.flag2.emulation, kEmulationOptions)); WSContentSend_P(PSTR("}1" D_EMULATION "}2%s"), GetTextIndexed(stopic, sizeof(stopic), Settings.flag2.emulation, kEmulationOptions));
#else
WSContentSend_P(PSTR("}1" D_EMULATION "}2" D_DISABLED));
#endif // USE_EMULATION #endif // USE_EMULATION
#ifdef USE_DISCOVERY #ifdef USE_DISCOVERY
WSContentSend_P(PSTR("}1" D_MDNS_DISCOVERY "}2%s"), (Settings.flag3.mdns_enabled) ? D_ENABLED : D_DISABLED); // SetOption55 - Control mDNS service WSContentSend_P(PSTR("}1" D_MDNS_DISCOVERY "}2%s"), (Settings.flag3.mdns_enabled) ? D_ENABLED : D_DISABLED); // SetOption55 - Control mDNS service
if (Settings.flag3.mdns_enabled) { // SetOption55 - Control mDNS service if (Settings.flag3.mdns_enabled) { // SetOption55 - Control mDNS service
@ -2160,8 +2160,6 @@ void HandleInformation(void)
WSContentSend_P(PSTR("}1" D_MDNS_ADVERTISE "}2" D_DISABLED)); WSContentSend_P(PSTR("}1" D_MDNS_ADVERTISE "}2" D_DISABLED));
#endif // WEBSERVER_ADVERTISE #endif // WEBSERVER_ADVERTISE
} }
#else
WSContentSend_P(PSTR("}1" D_MDNS_DISCOVERY "}2" D_DISABLED));
#endif // USE_DISCOVERY #endif // USE_DISCOVERY
WSContentSend_P(PSTR("}1}2&nbsp;")); // Empty line WSContentSend_P(PSTR("}1}2&nbsp;")); // Empty line
@ -2249,7 +2247,7 @@ void HandleUpgradeFirmware(void) {
WSContentStart_P(PSTR(D_FIRMWARE_UPGRADE)); WSContentStart_P(PSTR(D_FIRMWARE_UPGRADE));
WSContentSendStyle(); WSContentSendStyle();
WSContentSend_P(HTTP_FORM_UPG, SettingsText(SET_OTAURL)); WSContentSend_P(HTTP_FORM_UPG, SettingsText(SET_OTAURL));
WSContentSend_P(HTTP_FORM_RST_UPG, D_UPGRADE); WSContentSend_P(HTTP_FORM_RST_UPG, PSTR(D_UPGRADE));
WSContentSpaceButton(BUTTON_MAIN); WSContentSpaceButton(BUTTON_MAIN);
WSContentStop(); WSContentStop();
@ -2265,7 +2263,7 @@ void HandleUpgradeFirmwareStart(void) {
WifiConfigCounter(); WifiConfigCounter();
char otaurl[TOPSZ]; char otaurl[TOPSZ];
WebGetArg("o", otaurl, sizeof(otaurl)); WebGetArg(PSTR("o"), otaurl, sizeof(otaurl));
if (strlen(otaurl)) { if (strlen(otaurl)) {
snprintf_P(command, sizeof(command), PSTR(D_CMND_OTAURL " %s"), otaurl); snprintf_P(command, sizeof(command), PSTR(D_CMND_OTAURL " %s"), otaurl);
ExecuteWebCommand(command, SRC_WEBGUI); ExecuteWebCommand(command, SRC_WEBGUI);
@ -2343,7 +2341,6 @@ void UploadServices(uint32_t start_service) {
if (start_service) { if (start_service) {
// AddLog_P(LOG_LEVEL_DEBUG, PSTR("UPL: Services enabled")); // AddLog_P(LOG_LEVEL_DEBUG, PSTR("UPL: Services enabled"));
TasmotaGlobal.restart_flag = 0;
/* /*
MqttRetryCounter(0); MqttRetryCounter(0);
*/ */
@ -2378,7 +2375,6 @@ void UploadServices(uint32_t start_service) {
MqttDisconnect(); MqttDisconnect();
} }
*/ */
TasmotaGlobal.restart_flag = 120; // Set restart watchdog after 2 minutes
} }
} }
@ -2431,7 +2427,6 @@ void HandleUploadLoop(void) {
Web.upload_error = 2; Web.upload_error = 2;
return; return;
} }
TasmotaGlobal.restart_flag = 0;
} }
#endif // USE_UFILESYS #endif // USE_UFILESYS
} }
@ -2668,9 +2663,9 @@ void HandleHttpCommand(void)
if (!WebAuthenticate()) { if (!WebAuthenticate()) {
// Prefer authorization via HTTP header (Basic auth), if it fails, use legacy method via GET parameters // Prefer authorization via HTTP header (Basic auth), if it fails, use legacy method via GET parameters
char tmp1[33]; char tmp1[33];
WebGetArg("user", tmp1, sizeof(tmp1)); WebGetArg(PSTR("user"), tmp1, sizeof(tmp1));
char tmp2[strlen(SettingsText(SET_WEBPWD)) + 1]; char tmp2[strlen(SettingsText(SET_WEBPWD)) + 1];
WebGetArg("password", tmp2, sizeof(tmp2)); WebGetArg(PSTR("password"), tmp2, sizeof(tmp2));
if (!(!strcmp(tmp1, WEB_USERNAME) && !strcmp(tmp2, SettingsText(SET_WEBPWD)))) { if (!(!strcmp(tmp1, WEB_USERNAME) && !strcmp(tmp2, SettingsText(SET_WEBPWD)))) {
WSContentBegin(401, CT_JSON); WSContentBegin(401, CT_JSON);
@ -2681,7 +2676,7 @@ void HandleHttpCommand(void)
} }
WSContentBegin(200, CT_JSON); WSContentBegin(200, CT_JSON);
String svalue = Webserver->arg("cmnd"); String svalue = Webserver->arg(F("cmnd"));
if (svalue.length() && (svalue.length() < MQTT_MAX_PACKET_SIZE)) { if (svalue.length() && (svalue.length() < MQTT_MAX_PACKET_SIZE)) {
uint32_t curridx = TasmotaGlobal.log_buffer_pointer; uint32_t curridx = TasmotaGlobal.log_buffer_pointer;
TasmotaGlobal.templog_level = LOG_LEVEL_INFO; TasmotaGlobal.templog_level = LOG_LEVEL_INFO;
@ -2717,7 +2712,7 @@ void HandleConsole(void)
{ {
if (!HttpCheckPriviledgedAccess()) { return; } if (!HttpCheckPriviledgedAccess()) { return; }
if (Webserver->hasArg("c2")) { // Console refresh requested if (Webserver->hasArg(F("c2"))) { // Console refresh requested
HandleConsoleRefresh(); HandleConsoleRefresh();
return; return;
} }
@ -2734,14 +2729,14 @@ void HandleConsole(void)
void HandleConsoleRefresh(void) void HandleConsoleRefresh(void)
{ {
String svalue = Webserver->arg("c1"); String svalue = Webserver->arg(F("c1"));
if (svalue.length() && (svalue.length() < MQTT_MAX_PACKET_SIZE)) { if (svalue.length() && (svalue.length() < MQTT_MAX_PACKET_SIZE)) {
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_COMMAND "%s"), svalue.c_str()); AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_COMMAND "%s"), svalue.c_str());
ExecuteWebCommand((char*)svalue.c_str(), SRC_WEBCONSOLE); ExecuteWebCommand((char*)svalue.c_str(), SRC_WEBCONSOLE);
} }
char stmp[8]; char stmp[8];
WebGetArg("c2", stmp, sizeof(stmp)); WebGetArg(PSTR("c2"), stmp, sizeof(stmp));
uint32_t index = 0; // Initial start, dump all uint32_t index = 0; // Initial start, dump all
if (strlen(stmp)) { index = atoi(stmp); } if (strlen(stmp)) { index = atoi(stmp); }
@ -2758,7 +2753,7 @@ void HandleConsoleRefresh(void)
if (len > sizeof(TasmotaGlobal.mqtt_data) -2) { len = sizeof(TasmotaGlobal.mqtt_data); } if (len > sizeof(TasmotaGlobal.mqtt_data) -2) { len = sizeof(TasmotaGlobal.mqtt_data); }
char stemp[len +1]; char stemp[len +1];
strlcpy(stemp, line, len); strlcpy(stemp, line, len);
WSContentSend_P(PSTR("%s%s"), (cflg) ? "\n" : "", stemp); WSContentSend_P(PSTR("%s%s"), (cflg) ? PSTR("\n") : "", stemp);
cflg = true; cflg = true;
} }
WSContentSend_P(PSTR("}1")); WSContentSend_P(PSTR("}1"));
@ -2776,14 +2771,14 @@ void HandleNotFound(void)
#ifdef USE_EMULATION #ifdef USE_EMULATION
#ifdef USE_EMULATION_HUE #ifdef USE_EMULATION_HUE
String path = Webserver->uri(); String path = Webserver->uri();
if ((EMUL_HUE == Settings.flag2.emulation) && (path.startsWith("/api"))) { if ((EMUL_HUE == Settings.flag2.emulation) && (path.startsWith(F("/api")))) {
HandleHueApi(&path); HandleHueApi(&path);
} else } else
#endif // USE_EMULATION_HUE #endif // USE_EMULATION_HUE
#endif // USE_EMULATION #endif // USE_EMULATION
{ {
WSContentBegin(404, CT_PLAIN); WSContentBegin(404, CT_PLAIN);
WSContentSend_P(PSTR(D_FILE_NOT_FOUND "\n\nURI: %s\nMethod: %s\nArguments: %d\n"), Webserver->uri().c_str(), (Webserver->method() == HTTP_GET) ? "GET" : "POST", Webserver->args()); WSContentSend_P(PSTR(D_FILE_NOT_FOUND "\n\nURI: %s\nMethod: %s\nArguments: %d\n"), Webserver->uri().c_str(), (Webserver->method() == HTTP_GET) ? PSTR("GET") : PSTR("POST"), Webserver->args());
for (uint32_t i = 0; i < Webserver->args(); i++) { for (uint32_t i = 0; i < Webserver->args(); i++) {
WSContentSend_P(PSTR(" %s: %s\n"), Webserver->argName(i).c_str(), Webserver->arg(i).c_str()); WSContentSend_P(PSTR(" %s: %s\n"), Webserver->argName(i).c_str(), Webserver->arg(i).c_str());
} }
@ -2978,7 +2973,7 @@ void CmndWebServer(void)
} }
if (Settings.webserver) { if (Settings.webserver) {
Response_P(PSTR("{\"" D_CMND_WEBSERVER "\":\"" D_JSON_ACTIVE_FOR " %s " D_JSON_ON_DEVICE " %s " D_JSON_WITH_IP_ADDRESS " %s\"}"), Response_P(PSTR("{\"" D_CMND_WEBSERVER "\":\"" D_JSON_ACTIVE_FOR " %s " D_JSON_ON_DEVICE " %s " D_JSON_WITH_IP_ADDRESS " %s\"}"),
(2 == Settings.webserver) ? D_ADMIN : D_USER, NetworkHostname(), NetworkAddress().toString().c_str()); (2 == Settings.webserver) ? PSTR(D_ADMIN) : PSTR(D_USER), NetworkHostname(), NetworkAddress().toString().c_str());
} else { } else {
ResponseCmndStateText(0); ResponseCmndStateText(0);
} }

View File

@ -156,7 +156,7 @@ void MqttInit(void) {
// Detect AWS IoT and set default parameters // Detect AWS IoT and set default parameters
String host = String(SettingsText(SET_MQTT_HOST)); String host = String(SettingsText(SET_MQTT_HOST));
if (host.indexOf(".iot.") && host.endsWith(".amazonaws.com")) { // look for ".iot." and ".amazonaws.com" in the domain name if (host.indexOf(F(".iot.")) && host.endsWith(F(".amazonaws.com"))) { // look for ".iot." and ".amazonaws.com" in the domain name
Settings.flag4.mqtt_no_retain = true; Settings.flag4.mqtt_no_retain = true;
} }
@ -527,10 +527,10 @@ void MqttConnected(void) {
if (Settings.webserver) { if (Settings.webserver) {
#if LWIP_IPV6 #if LWIP_IPV6
Response_P(PSTR("{\"" D_JSON_WEBSERVER_MODE "\":\"%s\",\"" D_CMND_HOSTNAME "\":\"%s\",\"" D_CMND_IPADDRESS "\":\"%s\",\"IPv6Address\":\"%s\"}"), Response_P(PSTR("{\"" D_JSON_WEBSERVER_MODE "\":\"%s\",\"" D_CMND_HOSTNAME "\":\"%s\",\"" D_CMND_IPADDRESS "\":\"%s\",\"IPv6Address\":\"%s\"}"),
(2 == Settings.webserver) ? D_ADMIN : D_USER, NetworkHostname(), NetworkAddress().toString().c_str(), WifiGetIPv6().c_str()); (2 == Settings.webserver) ? PSTR(D_ADMIN) : PSTR(D_USER), NetworkHostname(), NetworkAddress().toString().c_str(), WifiGetIPv6().c_str());
#else #else
Response_P(PSTR("{\"" D_JSON_WEBSERVER_MODE "\":\"%s\",\"" D_CMND_HOSTNAME "\":\"%s\",\"" D_CMND_IPADDRESS "\":\"%s\"}"), Response_P(PSTR("{\"" D_JSON_WEBSERVER_MODE "\":\"%s\",\"" D_CMND_HOSTNAME "\":\"%s\",\"" D_CMND_IPADDRESS "\":\"%s\"}"),
(2 == Settings.webserver) ? D_ADMIN : D_USER, NetworkHostname(), NetworkAddress().toString().c_str()); (2 == Settings.webserver) ? PSTR(D_ADMIN) : PSTR(D_USER), NetworkHostname(), NetworkAddress().toString().c_str());
#endif // LWIP_IPV6 = 1 #endif // LWIP_IPV6 = 1
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_INFO "2")); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_INFO "2"));
} }
@ -787,7 +787,7 @@ void CmndMqttFingerprint(void) {
void CmndMqttUser(void) { void CmndMqttUser(void) {
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
SettingsUpdateText(SET_MQTT_USER, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? MQTT_USER : XdrvMailbox.data); SettingsUpdateText(SET_MQTT_USER, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? PSTR(MQTT_USER) : XdrvMailbox.data);
TasmotaGlobal.restart_flag = 2; TasmotaGlobal.restart_flag = 2;
} }
ResponseCmndChar(SettingsText(SET_MQTT_USER)); ResponseCmndChar(SettingsText(SET_MQTT_USER));
@ -795,7 +795,7 @@ void CmndMqttUser(void) {
void CmndMqttPassword(void) { void CmndMqttPassword(void) {
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
SettingsUpdateText(SET_MQTT_PWD, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? MQTT_PASS : XdrvMailbox.data); SettingsUpdateText(SET_MQTT_PWD, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? PSTR(MQTT_PASS) : XdrvMailbox.data);
ResponseCmndChar(SettingsText(SET_MQTT_PWD)); ResponseCmndChar(SettingsText(SET_MQTT_PWD));
TasmotaGlobal.restart_flag = 2; TasmotaGlobal.restart_flag = 2;
} else { } else {
@ -852,7 +852,7 @@ void CmndStateText(void) {
void CmndMqttClient(void) { void CmndMqttClient(void) {
if (!XdrvMailbox.grpflg && (XdrvMailbox.data_len > 0)) { if (!XdrvMailbox.grpflg && (XdrvMailbox.data_len > 0)) {
SettingsUpdateText(SET_MQTT_CLIENT, (SC_DEFAULT == Shortcut()) ? MQTT_CLIENT_ID : XdrvMailbox.data); SettingsUpdateText(SET_MQTT_CLIENT, (SC_DEFAULT == Shortcut()) ? PSTR(MQTT_CLIENT_ID) : XdrvMailbox.data);
TasmotaGlobal.restart_flag = 2; TasmotaGlobal.restart_flag = 2;
} }
ResponseCmndChar(SettingsText(SET_MQTT_CLIENT)); ResponseCmndChar(SettingsText(SET_MQTT_CLIENT));
@ -882,7 +882,7 @@ void CmndPrefix(void) {
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
MakeValidMqtt(0, XdrvMailbox.data); MakeValidMqtt(0, XdrvMailbox.data);
SettingsUpdateText(SET_MQTTPREFIX1 + XdrvMailbox.index -1, SettingsUpdateText(SET_MQTTPREFIX1 + XdrvMailbox.index -1,
(SC_DEFAULT == Shortcut()) ? (1==XdrvMailbox.index) ? SUB_PREFIX : (2==XdrvMailbox.index) ? PUB_PREFIX : PUB_PREFIX2 : XdrvMailbox.data); (SC_DEFAULT == Shortcut()) ? (1==XdrvMailbox.index) ? PSTR(SUB_PREFIX) : (2==XdrvMailbox.index) ? PSTR(PUB_PREFIX) : PSTR(PUB_PREFIX2) : XdrvMailbox.data);
TasmotaGlobal.restart_flag = 2; TasmotaGlobal.restart_flag = 2;
} }
ResponseCmndIdxChar(SettingsText(SET_MQTTPREFIX1 + XdrvMailbox.index -1)); ResponseCmndIdxChar(SettingsText(SET_MQTTPREFIX1 + XdrvMailbox.index -1));
@ -918,7 +918,7 @@ void CmndGroupTopic(void) {
uint32_t settings_text_index = (1 == XdrvMailbox.index) ? SET_MQTT_GRP_TOPIC : SET_MQTT_GRP_TOPIC2 + XdrvMailbox.index - 2; uint32_t settings_text_index = (1 == XdrvMailbox.index) ? SET_MQTT_GRP_TOPIC : SET_MQTT_GRP_TOPIC2 + XdrvMailbox.index - 2;
MakeValidMqtt(0, XdrvMailbox.data); MakeValidMqtt(0, XdrvMailbox.data);
if (!strcmp(XdrvMailbox.data, TasmotaGlobal.mqtt_client)) { SetShortcutDefault(); } if (!strcmp(XdrvMailbox.data, TasmotaGlobal.mqtt_client)) { SetShortcutDefault(); }
SettingsUpdateText(settings_text_index, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? MQTT_GRPTOPIC : XdrvMailbox.data); SettingsUpdateText(settings_text_index, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? PSTR(MQTT_GRPTOPIC) : XdrvMailbox.data);
// Eliminate duplicates, have at least one and fill from index 1 // Eliminate duplicates, have at least one and fill from index 1
char stemp[MAX_GROUP_TOPICS][TOPSZ]; char stemp[MAX_GROUP_TOPICS][TOPSZ];
@ -940,7 +940,7 @@ void CmndGroupTopic(void) {
} }
} }
if (0 == read_index) { if (0 == read_index) {
SettingsUpdateText(SET_MQTT_GRP_TOPIC, MQTT_GRPTOPIC); SettingsUpdateText(SET_MQTT_GRP_TOPIC, PSTR(MQTT_GRPTOPIC));
} else { } else {
uint32_t write_index = 0; uint32_t write_index = 0;
uint32_t real_index = SET_MQTT_GRP_TOPIC; uint32_t real_index = SET_MQTT_GRP_TOPIC;
@ -998,7 +998,7 @@ void CmndSwitchTopic(void) {
switch (Shortcut()) { switch (Shortcut()) {
case SC_CLEAR: SettingsUpdateText(SET_MQTT_SWITCH_TOPIC, ""); break; case SC_CLEAR: SettingsUpdateText(SET_MQTT_SWITCH_TOPIC, ""); break;
case SC_DEFAULT: SettingsUpdateText(SET_MQTT_SWITCH_TOPIC, TasmotaGlobal.mqtt_topic); break; case SC_DEFAULT: SettingsUpdateText(SET_MQTT_SWITCH_TOPIC, TasmotaGlobal.mqtt_topic); break;
case SC_USER: SettingsUpdateText(SET_MQTT_SWITCH_TOPIC, MQTT_SWITCH_TOPIC); break; case SC_USER: SettingsUpdateText(SET_MQTT_SWITCH_TOPIC, PSTR(MQTT_SWITCH_TOPIC)); break;
default: SettingsUpdateText(SET_MQTT_SWITCH_TOPIC, XdrvMailbox.data); default: SettingsUpdateText(SET_MQTT_SWITCH_TOPIC, XdrvMailbox.data);
} }
} }
@ -1266,7 +1266,7 @@ void HandleMqttConfiguration(void)
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_MQTT)); AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_MQTT));
if (Webserver->hasArg("save")) { if (Webserver->hasArg(F("save"))) {
MqttSaveSettings(); MqttSaveSettings();
WebRestart(1); WebRestart(1);
return; return;
@ -1282,11 +1282,11 @@ void HandleMqttConfiguration(void)
#ifdef USE_MQTT_TLS #ifdef USE_MQTT_TLS
Mqtt.mqtt_tls ? PSTR(" checked") : "", // SetOption102 - Enable MQTT TLS Mqtt.mqtt_tls ? PSTR(" checked") : "", // SetOption102 - Enable MQTT TLS
#endif // USE_MQTT_TLS #endif // USE_MQTT_TLS
Format(str, MQTT_CLIENT_ID, sizeof(str)), MQTT_CLIENT_ID, SettingsText(SET_MQTT_CLIENT)); Format(str, PSTR(MQTT_CLIENT_ID), sizeof(str)), PSTR(MQTT_CLIENT_ID), SettingsText(SET_MQTT_CLIENT));
WSContentSend_P(HTTP_FORM_MQTT2, WSContentSend_P(HTTP_FORM_MQTT2,
(!strlen(SettingsText(SET_MQTT_USER))) ? "0" : SettingsText(SET_MQTT_USER), (!strlen(SettingsText(SET_MQTT_USER))) ? "0" : SettingsText(SET_MQTT_USER),
Format(str, MQTT_TOPIC, sizeof(str)), MQTT_TOPIC, SettingsText(SET_MQTT_TOPIC), Format(str, PSTR(MQTT_TOPIC), sizeof(str)), PSTR(MQTT_TOPIC), SettingsText(SET_MQTT_TOPIC),
MQTT_FULLTOPIC, MQTT_FULLTOPIC, SettingsText(SET_MQTT_FULLTOPIC)); PSTR(MQTT_FULLTOPIC), PSTR(MQTT_FULLTOPIC), SettingsText(SET_MQTT_FULLTOPIC));
WSContentSend_P(HTTP_FORM_END); WSContentSend_P(HTTP_FORM_END);
WSContentSpaceButton(BUTTON_CONFIGURATION); WSContentSpaceButton(BUTTON_CONFIGURATION);
WSContentStop(); WSContentStop();
@ -1298,10 +1298,10 @@ void MqttSaveSettings(void)
char stemp[TOPSZ]; char stemp[TOPSZ];
char stemp2[TOPSZ]; char stemp2[TOPSZ];
WebGetArg("mt", tmp, sizeof(tmp)); WebGetArg(PSTR("mt"), tmp, sizeof(tmp));
strlcpy(stemp, (!strlen(tmp)) ? MQTT_TOPIC : tmp, sizeof(stemp)); strlcpy(stemp, (!strlen(tmp)) ? MQTT_TOPIC : tmp, sizeof(stemp));
MakeValidMqtt(0, stemp); MakeValidMqtt(0, stemp);
WebGetArg("mf", tmp, sizeof(tmp)); WebGetArg(PSTR("mf"), tmp, sizeof(tmp));
strlcpy(stemp2, (!strlen(tmp)) ? MQTT_FULLTOPIC : tmp, sizeof(stemp2)); strlcpy(stemp2, (!strlen(tmp)) ? MQTT_FULLTOPIC : tmp, sizeof(stemp2));
MakeValidMqtt(1, stemp2); MakeValidMqtt(1, stemp2);
if ((strcmp(stemp, SettingsText(SET_MQTT_TOPIC))) || (strcmp(stemp2, SettingsText(SET_MQTT_FULLTOPIC)))) { if ((strcmp(stemp, SettingsText(SET_MQTT_TOPIC))) || (strcmp(stemp2, SettingsText(SET_MQTT_FULLTOPIC)))) {
@ -1310,18 +1310,18 @@ void MqttSaveSettings(void)
} }
SettingsUpdateText(SET_MQTT_TOPIC, stemp); SettingsUpdateText(SET_MQTT_TOPIC, stemp);
SettingsUpdateText(SET_MQTT_FULLTOPIC, stemp2); SettingsUpdateText(SET_MQTT_FULLTOPIC, stemp2);
WebGetArg("mh", tmp, sizeof(tmp)); WebGetArg(PSTR("mh"), tmp, sizeof(tmp));
SettingsUpdateText(SET_MQTT_HOST, (!strlen(tmp)) ? MQTT_HOST : (!strcmp(tmp,"0")) ? "" : tmp); SettingsUpdateText(SET_MQTT_HOST, (!strlen(tmp)) ? PSTR(MQTT_HOST) : (!strcmp(tmp,"0")) ? "" : tmp);
WebGetArg("ml", tmp, sizeof(tmp)); WebGetArg(PSTR("ml"), tmp, sizeof(tmp));
Settings.mqtt_port = (!strlen(tmp)) ? MQTT_PORT : atoi(tmp); Settings.mqtt_port = (!strlen(tmp)) ? MQTT_PORT : atoi(tmp);
#ifdef USE_MQTT_TLS #ifdef USE_MQTT_TLS
Settings.flag4.mqtt_tls = Webserver->hasArg("b3"); // SetOption102 - Enable MQTT TLS Settings.flag4.mqtt_tls = Webserver->hasArg(F("b3")); // SetOption102 - Enable MQTT TLS
#endif #endif
WebGetArg("mc", tmp, sizeof(tmp)); WebGetArg(PSTR("mc"), tmp, sizeof(tmp));
SettingsUpdateText(SET_MQTT_CLIENT, (!strlen(tmp)) ? MQTT_CLIENT_ID : tmp); SettingsUpdateText(SET_MQTT_CLIENT, (!strlen(tmp)) ? PSTR(MQTT_CLIENT_ID) : tmp);
WebGetArg("mu", tmp, sizeof(tmp)); WebGetArg(PSTR("mu"), tmp, sizeof(tmp));
SettingsUpdateText(SET_MQTT_USER, (!strlen(tmp)) ? MQTT_USER : (!strcmp(tmp,"0")) ? "" : tmp); SettingsUpdateText(SET_MQTT_USER, (!strlen(tmp)) ? PSTR(MQTT_USER) : (!strcmp(tmp,"0")) ? "" : tmp);
WebGetArg("mp", tmp, sizeof(tmp)); WebGetArg(PSTR("mp"), tmp, sizeof(tmp));
SettingsUpdateText(SET_MQTT_PWD, (!strlen(tmp)) ? "" : (!strcmp(tmp, D_ASTERISK_PWD)) ? SettingsText(SET_MQTT_PWD) : tmp); SettingsUpdateText(SET_MQTT_PWD, (!strlen(tmp)) ? "" : (!strcmp(tmp, D_ASTERISK_PWD)) ? SettingsText(SET_MQTT_PWD) : tmp);
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_MQTT D_CMND_MQTTHOST " %s, " D_CMND_MQTTPORT " %d, " D_CMND_MQTTCLIENT " %s, " D_CMND_MQTTUSER " %s, " D_CMND_TOPIC " %s, " D_CMND_FULLTOPIC " %s"), AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_MQTT D_CMND_MQTTHOST " %s, " D_CMND_MQTTPORT " %d, " D_CMND_MQTTCLIENT " %s, " D_CMND_MQTTUSER " %s, " D_CMND_TOPIC " %s, " D_CMND_FULLTOPIC " %s"),
SettingsText(SET_MQTT_HOST), Settings.mqtt_port, SettingsText(SET_MQTT_CLIENT), SettingsText(SET_MQTT_USER), SettingsText(SET_MQTT_TOPIC), SettingsText(SET_MQTT_FULLTOPIC)); SettingsText(SET_MQTT_HOST), Settings.mqtt_port, SettingsText(SET_MQTT_CLIENT), SettingsText(SET_MQTT_USER), SettingsText(SET_MQTT_TOPIC), SettingsText(SET_MQTT_FULLTOPIC));

View File

@ -2625,7 +2625,7 @@ void CmndWakeup(void)
Light.wakeup_active = 3; Light.wakeup_active = 3;
Settings.light_scheme = LS_WAKEUP; Settings.light_scheme = LS_WAKEUP;
LightPowerOn(); LightPowerOn();
ResponseCmndChar(D_JSON_STARTED); ResponseCmndChar(PSTR(D_JSON_STARTED));
} }
void CmndColorTemperature(void) void CmndColorTemperature(void)

View File

@ -546,7 +546,7 @@ void HandleDomoticzConfiguration(void) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_DOMOTICZ)); AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_DOMOTICZ));
if (Webserver->hasArg("save")) { if (Webserver->hasArg(F("save"))) {
DomoticzSaveSettings(); DomoticzSaveSettings();
WebRestart(1); WebRestart(1);
return; return;
@ -605,7 +605,7 @@ void DomoticzSaveSettings(void) {
Settings.domoticz_sensor_idx[i] = (!strlen(tmp)) ? 0 : atoi(tmp); Settings.domoticz_sensor_idx[i] = (!strlen(tmp)) ? 0 : atoi(tmp);
snprintf_P(ssensor_indices, sizeof(ssensor_indices), PSTR("%s%s%d"), ssensor_indices, (strlen(ssensor_indices)) ? "," : "", Settings.domoticz_sensor_idx[i]); snprintf_P(ssensor_indices, sizeof(ssensor_indices), PSTR("%s%s%d"), ssensor_indices, (strlen(ssensor_indices)) ? "," : "", Settings.domoticz_sensor_idx[i]);
} }
WebGetArg("ut", tmp, sizeof(tmp)); WebGetArg(PSTR("ut"), tmp, sizeof(tmp));
Settings.domoticz_update_timer = (!strlen(tmp)) ? DOMOTICZ_UPDATE_TIMER : atoi(tmp); Settings.domoticz_update_timer = (!strlen(tmp)) ? DOMOTICZ_UPDATE_TIMER : atoi(tmp);
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_DOMOTICZ D_CMND_IDX " %d,%d,%d,%d, " D_CMND_KEYIDX " %d,%d,%d,%d, " D_CMND_SWITCHIDX " %d,%d,%d,%d, " D_CMND_SENSORIDX " %s, " D_CMND_UPDATETIMER " %d"), AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_DOMOTICZ D_CMND_IDX " %d,%d,%d,%d, " D_CMND_KEYIDX " %d,%d,%d,%d, " D_CMND_SWITCHIDX " %d,%d,%d,%d, " D_CMND_SENSORIDX " %s, " D_CMND_UPDATETIMER " %d"),

View File

@ -841,7 +841,7 @@ void HandleTimerConfiguration(void)
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_TIMER)); AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_TIMER));
if (Webserver->hasArg("save")) { if (Webserver->hasArg(F("save"))) {
TimerSaveSettings(); TimerSaveSettings();
HandleConfiguration(); HandleConfiguration();
return; return;
@ -883,8 +883,8 @@ void TimerSaveSettings(void)
char message[32 + (MAX_TIMERS *11)]; // MQT: Timers 0,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 char message[32 + (MAX_TIMERS *11)]; // MQT: Timers 0,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000
Timer timer; Timer timer;
Settings.flag3.timers_enable = Webserver->hasArg("e0"); // CMND_TIMERS Settings.flag3.timers_enable = Webserver->hasArg(F("e0")); // CMND_TIMERS
WebGetArg("t0", tmp, sizeof(tmp)); WebGetArg(PSTR("t0"), tmp, sizeof(tmp));
char *p = tmp; char *p = tmp;
snprintf_P(message, sizeof(message), PSTR(D_LOG_MQTT D_CMND_TIMERS " %d"), Settings.flag3.timers_enable); // CMND_TIMERS snprintf_P(message, sizeof(message), PSTR(D_LOG_MQTT D_CMND_TIMERS " %d"), Settings.flag3.timers_enable); // CMND_TIMERS
for (uint32_t i = 0; i < MAX_TIMERS; i++) { for (uint32_t i = 0; i < MAX_TIMERS; i++) {

View File

@ -416,7 +416,7 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all
// Step1: Analyse rule // Step1: Analyse rule
String rule_expr = rule; // "TELE-INA219#CURRENT>0.100" String rule_expr = rule; // "TELE-INA219#CURRENT>0.100"
if (Rules.teleperiod) { if (Rules.teleperiod) {
int ppos = rule_expr.indexOf("TELE-"); // "TELE-INA219#CURRENT>0.100" or "INA219#CURRENT>0.100" int ppos = rule_expr.indexOf(F("TELE-")); // "TELE-INA219#CURRENT>0.100" or "INA219#CURRENT>0.100"
if (ppos == -1) { return false; } // No pre-amble in rule if (ppos == -1) { return false; } // No pre-amble in rule
rule_expr = rule.substring(5); // "INA219#CURRENT>0.100" or "SYSTEM#BOOT" rule_expr = rule.substring(5); // "INA219#CURRENT>0.100" or "SYSTEM#BOOT"
} }
@ -494,7 +494,7 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all
// Step2: Search rule_name // Step2: Search rule_name
int pos; int pos;
int rule_name_idx = 0; int rule_name_idx = 0;
if ((pos = rule_name.indexOf("[")) > 0) { // "SUBTYPE1#CURRENT[1]" if ((pos = rule_name.indexOf(F("["))) > 0) { // "SUBTYPE1#CURRENT[1]"
rule_name_idx = rule_name.substring(pos +1).toInt(); rule_name_idx = rule_name.substring(pos +1).toInt();
if ((rule_name_idx < 1) || (rule_name_idx > 6)) { // Allow indexes 1 to 6 if ((rule_name_idx < 1) || (rule_name_idx > 6)) { // Allow indexes 1 to 6
rule_name_idx = 1; rule_name_idx = 1;
@ -515,7 +515,7 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all
} }
String subtype; String subtype;
uint32_t i = 0; uint32_t i = 0;
while ((pos = rule_name.indexOf("#")) > 0) { // "SUBTYPE1#SUBTYPE2#CURRENT" while ((pos = rule_name.indexOf(F("#"))) > 0) { // "SUBTYPE1#SUBTYPE2#CURRENT"
subtype = rule_name.substring(0, pos); subtype = rule_name.substring(0, pos);
obj = obj[subtype.c_str()].getObject(); obj = obj[subtype.c_str()].getObject();
if (!obj) { return false; } // not found if (!obj) { return false; } // not found
@ -686,14 +686,14 @@ bool RuleSetProcess(uint8_t rule_set, String &event_saved)
String rule = rules; String rule = rules;
rule.toUpperCase(); // "ON INA219#CURRENT>0.100 DO BACKLOG DIMMER 10;COLOR 100000 ENDON" rule.toUpperCase(); // "ON INA219#CURRENT>0.100 DO BACKLOG DIMMER 10;COLOR 100000 ENDON"
if (!rule.startsWith("ON ")) { return serviced; } // Bad syntax - Nothing to start on if (!rule.startsWith(F("ON "))) { return serviced; } // Bad syntax - Nothing to start on
int pevt = rule.indexOf(" DO "); int pevt = rule.indexOf(F(" DO "));
if (pevt == -1) { return serviced; } // Bad syntax - Nothing to do if (pevt == -1) { return serviced; } // Bad syntax - Nothing to do
String event_trigger = rule.substring(3, pevt); // "INA219#CURRENT>0.100" String event_trigger = rule.substring(3, pevt); // "INA219#CURRENT>0.100"
plen = rule.indexOf(" ENDON"); plen = rule.indexOf(F(" ENDON"));
plen2 = rule.indexOf(" BREAK"); plen2 = rule.indexOf(F(" BREAK"));
if ((plen == -1) && (plen2 == -1)) { return serviced; } // Bad syntax - No ENDON neither BREAK if ((plen == -1) && (plen2 == -1)) { return serviced; } // Bad syntax - No ENDON neither BREAK
if (plen == -1) { plen = 9999; } if (plen == -1) { plen = 9999; }
@ -717,10 +717,10 @@ bool RuleSetProcess(uint8_t rule_set, String &event_saved)
// if (!ucommand.startsWith("BACKLOG")) { commands = "backlog " + commands; } // Always use Backlog to prevent power race exception // if (!ucommand.startsWith("BACKLOG")) { commands = "backlog " + commands; } // Always use Backlog to prevent power race exception
// Use Backlog with event to prevent rule event loop exception unless IF is used which uses an implicit backlog // Use Backlog with event to prevent rule event loop exception unless IF is used which uses an implicit backlog
if ((ucommand.indexOf("IF ") == -1) && if ((ucommand.indexOf(F("IF ")) == -1) &&
(ucommand.indexOf("EVENT ") != -1) && (ucommand.indexOf(F("EVENT ")) != -1) &&
(ucommand.indexOf("BACKLOG ") == -1)) { (ucommand.indexOf(F("BACKLOG ")) == -1)) {
commands = "backlog " + commands; commands = String(F("backlog ")) + commands;
} }
RulesVarReplace(commands, F("%VALUE%"), Rules.event_value); RulesVarReplace(commands, F("%VALUE%"), Rules.event_value);

View File

@ -294,7 +294,7 @@ void NewHAssDiscovery(void)
for (uint32_t i = 0; i < MAX_FRIENDLYNAMES; i++) { for (uint32_t i = 0; i < MAX_FRIENDLYNAMES; i++) {
char fname[TOPSZ]; char fname[TOPSZ];
snprintf_P(fname, sizeof(fname), PSTR("\"%s\""), EscapeJSONString(SettingsText(SET_FRIENDLYNAME1 +i)).c_str()); snprintf_P(fname, sizeof(fname), PSTR("\"%s\""), EscapeJSONString(SettingsText(SET_FRIENDLYNAME1 +i)).c_str());
snprintf_P(stemp2, sizeof(stemp2), PSTR("%s%s%s"), stemp2, (i > 0 ? "," : ""), (i < maxfn) ? fname : "null"); snprintf_P(stemp2, sizeof(stemp2), PSTR("%s%s%s"), stemp2, (i > 0 ? "," : ""), (i < maxfn) ? fname : PSTR("null"));
} }
stemp3[0] = '\0'; stemp3[0] = '\0';
@ -304,7 +304,7 @@ void NewHAssDiscovery(void)
char sname[TOPSZ]; char sname[TOPSZ];
snprintf_P(sname, sizeof(sname), PSTR("\"%s\""), GetSwitchText(i).c_str()); snprintf_P(sname, sizeof(sname), PSTR("\"%s\""), GetSwitchText(i).c_str());
snprintf_P(stemp3, sizeof(stemp3), PSTR("%s%s%d"), stemp3, (i > 0 ? "," : ""), (PinUsed(GPIO_SWT1, i) & Settings.flag5.mqtt_switches) ? Settings.switchmode[i] : -1); snprintf_P(stemp3, sizeof(stemp3), PSTR("%s%s%d"), stemp3, (i > 0 ? "," : ""), (PinUsed(GPIO_SWT1, i) & Settings.flag5.mqtt_switches) ? Settings.switchmode[i] : -1);
snprintf_P(stemp4, sizeof(stemp4), PSTR("%s%s%s"), stemp4, (i > 0 ? "," : ""), (PinUsed(GPIO_SWT1, i) & Settings.flag5.mqtt_switches) ? sname : "null"); snprintf_P(stemp4, sizeof(stemp4), PSTR("%s%s%s"), stemp4, (i > 0 ? "," : ""), (PinUsed(GPIO_SWT1, i) & Settings.flag5.mqtt_switches) ? sname : PSTR("null"));
} }
stemp5[0] = '\0'; stemp5[0] = '\0';
@ -338,7 +338,7 @@ void NewHAssDiscovery(void)
if (!Settings.flag.hass_discovery) { // HassDiscoveryRelays(relays) if (!Settings.flag.hass_discovery) { // HassDiscoveryRelays(relays)
Response_P(HASS_DISCOVER_DEVICE, WiFi.localIP().toString().c_str(), SettingsText(SET_DEVICENAME), Response_P(HASS_DISCOVER_DEVICE, WiFi.localIP().toString().c_str(), SettingsText(SET_DEVICENAME),
stemp2, TasmotaGlobal.hostname, unique_id, ModuleName().c_str(), TuyaMod, iFanMod, GetStateText(0), GetStateText(1), GetStateText(2), GetStateText(3), stemp2, TasmotaGlobal.hostname, unique_id, ModuleName().c_str(), TuyaMod, iFanMod, GetStateText(0), GetStateText(1), GetStateText(2), GetStateText(3),
TasmotaGlobal.version, TasmotaGlobal.mqtt_topic, SettingsText(SET_MQTT_FULLTOPIC), SUB_PREFIX, PUB_PREFIX, PUB_PREFIX2, Hass.RelLst, stemp3, stemp4, TasmotaGlobal.version, TasmotaGlobal.mqtt_topic, SettingsText(SET_MQTT_FULLTOPIC), PSTR(SUB_PREFIX), PSTR(PUB_PREFIX), PSTR(PUB_PREFIX2), Hass.RelLst, stemp3, stemp4,
stemp5, Settings.flag.mqtt_response, Settings.flag.button_swap, Settings.flag.button_single, Settings.flag.decimal_text, Settings.flag.not_power_linked, stemp5, Settings.flag.mqtt_response, Settings.flag.button_swap, Settings.flag.button_single, Settings.flag.decimal_text, Settings.flag.not_power_linked,
Settings.flag.hass_light, Settings.flag3.pwm_multi_channels, Settings.flag3.mqtt_buttons, Settings.flag4.alexa_ct_range, Settings.flag5.mqtt_switches, Settings.flag.hass_light, Settings.flag3.pwm_multi_channels, Settings.flag3.mqtt_buttons, Settings.flag4.alexa_ct_range, Settings.flag5.mqtt_switches,
Settings.flag5.fade_fixed_duration, light_controller.isCTRGBLinked(), Light.subtype, stemp6); Settings.flag5.fade_fixed_duration, light_controller.isCTRGBLinked(), Light.subtype, stemp6);

View File

@ -1295,7 +1295,7 @@ void TuyaSensorsShow(bool json)
GetTextIndexed(sname, sizeof(sname), (sensor-71), kTuyaSensors); GetTextIndexed(sname, sizeof(sname), (sensor-71), kTuyaSensors);
ResponseAppend_P(PSTR("\"%s\":%s"), sname, ResponseAppend_P(PSTR("\"%s\":%s"), sname,
(Tuya.SensorsValid[sensor-71] ? dtostrfd(Tuya.Sensors[sensor-71], res, tempval) : "null")); (Tuya.SensorsValid[sensor-71] ? dtostrfd(Tuya.Sensors[sensor-71], res, tempval) : PSTR("null")));
added = true; added = true;
} }
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER

View File

@ -429,9 +429,9 @@ void HandleUpnpSetupHue(void)
{ {
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_HUE_BRIDGE_SETUP)); AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_HUE_BRIDGE_SETUP));
String description_xml = Decompress(HUE_DESCRIPTION_XML_COMPRESSED,HUE_DESCRIPTION_XML_SIZE); String description_xml = Decompress(HUE_DESCRIPTION_XML_COMPRESSED,HUE_DESCRIPTION_XML_SIZE);
description_xml.replace("{x1", WiFi.localIP().toString()); description_xml.replace(F("{x1"), WiFi.localIP().toString());
description_xml.replace("{x2", HueUuid()); description_xml.replace(F("{x2"), HueUuid());
description_xml.replace("{x3", HueSerialnumber()); description_xml.replace(F("{x3"), HueSerialnumber());
WSSend(200, CT_XML, description_xml); WSSend(200, CT_XML, description_xml);
} }
@ -439,19 +439,19 @@ void HueNotImplemented(String *path)
{ {
AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_HTTP D_HUE_API_NOT_IMPLEMENTED " (%s)"), path->c_str()); AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_HTTP D_HUE_API_NOT_IMPLEMENTED " (%s)"), path->c_str());
WSSend(200, CT_JSON, "{}"); WSSend(200, CT_JSON, PSTR("{}"));
} }
void HueConfigResponse(String *response) void HueConfigResponse(String *response)
{ {
*response += Decompress(HueConfigResponse_JSON, HueConfigResponse_JSON_SIZE); *response += Decompress(HueConfigResponse_JSON, HueConfigResponse_JSON_SIZE);
response->replace("{ma", WiFi.macAddress()); response->replace(F("{ma"), WiFi.macAddress());
response->replace("{ip", WiFi.localIP().toString()); response->replace(F("{ip"), WiFi.localIP().toString());
response->replace("{ms", WiFi.subnetMask().toString()); response->replace(F("{ms"), WiFi.subnetMask().toString());
response->replace("{gw", WiFi.gatewayIP().toString()); response->replace(F("{gw"), WiFi.gatewayIP().toString());
response->replace("{br", HueBridgeId()); response->replace(F("{br"), HueBridgeId());
response->replace("{dt", GetDateAndTime(DT_UTC)); response->replace(F("{dt"), GetDateAndTime(DT_UTC));
response->replace("{id", GetHueUserId()); response->replace(F("{id"), GetHueUserId());
} }
void HueConfig(String *path) void HueConfig(String *path)
@ -534,13 +534,13 @@ void HueLightStatus1(uint8_t device, String *response)
char * buf = (char*) malloc(buf_size); // temp buffer for strings, avoid stack char * buf = (char*) malloc(buf_size); // temp buffer for strings, avoid stack
UnishoxStrings msg(HUE_LIGHTS); UnishoxStrings msg(HUE_LIGHTS);
snprintf_P(buf, buf_size, PSTR("{\"on\":%s,"), (TasmotaGlobal.power & (1 << (device-1))) ? "true" : "false"); snprintf_P(buf, buf_size, PSTR("{\"on\":%s,"), (TasmotaGlobal.power & (1 << (device-1))) ? PSTR("true") : PSTR("false"));
// Brightness for all devices with PWM // Brightness for all devices with PWM
if ((1 == echo_gen) || (LST_SINGLE <= local_light_subtype)) { // force dimmer for 1st gen Echo if ((1 == echo_gen) || (LST_SINGLE <= local_light_subtype)) { // force dimmer for 1st gen Echo
snprintf_P(buf, buf_size, PSTR("%s\"bri\":%d,"), buf, bri); snprintf_P(buf, buf_size, PSTR("%s\"bri\":%d,"), buf, bri);
} }
if (LST_COLDWARM <= local_light_subtype) { if (LST_COLDWARM <= local_light_subtype) {
snprintf_P(buf, buf_size, PSTR("%s\"colormode\":\"%s\","), buf, g_gotct ? "ct" : "hs"); snprintf_P(buf, buf_size, PSTR("%s\"colormode\":\"%s\","), buf, g_gotct ? PSTR("ct") : PSTR("hs"));
} }
if (LST_RGB <= local_light_subtype) { // colors if (LST_RGB <= local_light_subtype) { // colors
if (prev_x_str[0] && prev_y_str[0]) { if (prev_x_str[0] && prev_y_str[0]) {
@ -680,7 +680,7 @@ void HueGlobalConfig(String *path) {
#endif // USE_ZIGBEE #endif // USE_ZIGBEE
response += F("},\"groups\":{},\"schedules\":{},\"config\":"); response += F("},\"groups\":{},\"schedules\":{},\"config\":");
HueConfigResponse(&response); HueConfigResponse(&response);
response += "}"; response += F("}");
WSSend(200, CT_JSON, response); WSSend(200, CT_JSON, response);
} }
@ -700,7 +700,7 @@ void CheckHue(String * response, bool &appending) {
for (uint32_t i = 1; i <= maxhue; i++) { for (uint32_t i = 1; i <= maxhue; i++) {
if (HueActive(i)) { if (HueActive(i)) {
if (appending) { *response += ","; } if (appending) { *response += ","; }
*response += "\""; *response += F("\"");
*response += EncodeLightId(i); *response += EncodeLightId(i);
*response += F("\":{\"state\":"); *response += F("\":{\"state\":");
HueLightStatus1(i, response); HueLightStatus1(i, response);
@ -735,7 +735,7 @@ void HueLightsCommand(uint8_t device, uint32_t device_id, String &response) {
on = hue_on.getBool(); on = hue_on.getBool();
snprintf_P(buf, buf_size, snprintf_P(buf, buf_size,
msg[HUE_RESP_ON], msg[HUE_RESP_ON],
device_id, on ? "true" : "false"); device_id, on ? PSTR("true") : PSTR("false"));
#ifdef USE_SHUTTER #ifdef USE_SHUTTER
if (ShutterState(device)) { if (ShutterState(device)) {
@ -778,7 +778,7 @@ void HueLightsCommand(uint8_t device, uint32_t device_id, String &response) {
if (resp) { response += ","; } if (resp) { response += ","; }
snprintf_P(buf, buf_size, snprintf_P(buf, buf_size,
msg[HUE_RESP_NUM], msg[HUE_RESP_NUM],
device_id, "bri", bri); device_id, PSTR("bri"), bri);
response += buf; response += buf;
if (LST_SINGLE <= Light.subtype) { if (LST_SINGLE <= Light.subtype) {
// extend bri value if set to max // extend bri value if set to max
@ -824,7 +824,7 @@ void HueLightsCommand(uint8_t device, uint32_t device_id, String &response) {
if (resp) { response += ","; } if (resp) { response += ","; }
snprintf_P(buf, buf_size, snprintf_P(buf, buf_size,
msg[HUE_RESP_NUM], msg[HUE_RESP_NUM],
device_id, "hue", hue); device_id, PSTR("hue"), hue);
response += buf; response += buf;
if (LST_RGB <= Light.subtype) { if (LST_RGB <= Light.subtype) {
// change range from 0..65535 to 0..360 // change range from 0..65535 to 0..360
@ -843,7 +843,7 @@ void HueLightsCommand(uint8_t device, uint32_t device_id, String &response) {
if (resp) { response += ","; } if (resp) { response += ","; }
snprintf_P(buf, buf_size, snprintf_P(buf, buf_size,
msg[HUE_RESP_NUM], msg[HUE_RESP_NUM],
device_id, "sat", sat); device_id, PSTR("sat"), sat);
response += buf; response += buf;
if (LST_RGB <= Light.subtype) { if (LST_RGB <= Light.subtype) {
// extend sat value if set to max // extend sat value if set to max
@ -862,7 +862,7 @@ void HueLightsCommand(uint8_t device, uint32_t device_id, String &response) {
if (resp) { response += ","; } if (resp) { response += ","; }
snprintf_P(buf, buf_size, snprintf_P(buf, buf_size,
msg[HUE_RESP_NUM], msg[HUE_RESP_NUM],
device_id, "ct", ct); device_id, PSTR("ct"), ct);
response += buf; response += buf;
if ((LST_COLDWARM == Light.subtype) || (LST_RGBW <= Light.subtype)) { if ((LST_COLDWARM == Light.subtype) || (LST_RGBW <= Light.subtype)) {
g_gotct = true; g_gotct = true;
@ -923,7 +923,7 @@ void HueLights(String *path)
path->remove(0,path->indexOf(F("/lights"))); // Remove until /lights path->remove(0,path->indexOf(F("/lights"))); // Remove until /lights
if (path->endsWith(F("/lights"))) { // Got /lights if (path->endsWith(F("/lights"))) { // Got /lights
response = "{"; response = F("{");
bool appending = false; bool appending = false;
#ifdef USE_LIGHT #ifdef USE_LIGHT
CheckHue(&response, appending); CheckHue(&response, appending);
@ -934,7 +934,7 @@ void HueLights(String *path)
#ifdef USE_SCRIPT_HUE #ifdef USE_SCRIPT_HUE
Script_Check_Hue(&response); Script_Check_Hue(&response);
#endif #endif
response += "}"; response += F("}");
} }
else if (path->endsWith(F("/state"))) { // Got ID/state else if (path->endsWith(F("/state"))) { // Got ID/state
path->remove(0,8); // Remove /lights/ path->remove(0,8); // Remove /lights/
@ -992,7 +992,7 @@ void HueLights(String *path)
#endif // USE_LIGHT #endif // USE_LIGHT
} }
else { else {
response = "{}"; response = F("{}");
code = 406; code = 406;
} }
exit: exit:
@ -1005,24 +1005,24 @@ void HueGroups(String *path)
/* /*
* http://tasmota/api/username/groups?1={"name":"Woonkamer","lights":[],"type":"Room","class":"Living room"}) * http://tasmota/api/username/groups?1={"name":"Woonkamer","lights":[],"type":"Room","class":"Living room"})
*/ */
String response = "{}"; String response(F("{}"));
uint8_t maxhue = (TasmotaGlobal.devices_present > MAX_HUE_DEVICES) ? MAX_HUE_DEVICES : TasmotaGlobal.devices_present; uint8_t maxhue = (TasmotaGlobal.devices_present > MAX_HUE_DEVICES) ? MAX_HUE_DEVICES : TasmotaGlobal.devices_present;
//AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_HTTP D_HUE " HueGroups (%s)"), path->c_str()); //AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_HTTP D_HUE " HueGroups (%s)"), path->c_str());
if (path->endsWith("/0")) { if (path->endsWith(F("/0"))) {
UnishoxStrings msg(HUE_LIGHTS); UnishoxStrings msg(HUE_LIGHTS);
response = msg[HUE_GROUP0_STATUS_JSON]; response = msg[HUE_GROUP0_STATUS_JSON];
String lights = F("\"1\""); String lights = F("\"1\"");
for (uint32_t i = 2; i <= maxhue; i++) { for (uint32_t i = 2; i <= maxhue; i++) {
lights += ",\""; lights += F(",\"");
lights += EncodeLightId(i); lights += EncodeLightId(i);
lights += "\""; lights += F("\"");
} }
#ifdef USE_ZIGBEE #ifdef USE_ZIGBEE
ZigbeeHueGroups(&response); ZigbeeHueGroups(&response);
#endif // USE_ZIGBEE #endif // USE_ZIGBEE
response.replace("{l1", lights); response.replace(F("{l1"), lights);
#ifdef USE_LIGHT #ifdef USE_LIGHT
HueLightStatus1(1, &response); HueLightStatus1(1, &response);
#endif // USE_LIGHT #endif // USE_LIGHT

View File

@ -579,7 +579,7 @@ String Z_attribute::toString(bool prefix_comma) const {
// value part // value part
switch (type) { switch (type) {
case Za_type::Za_none: case Za_type::Za_none:
res += "null"; res += F("null");
break; break;
case Za_type::Za_bool: case Za_type::Za_bool:
res += val.uval32 ? F("true") : F("false"); res += val.uval32 ? F("true") : F("false");
@ -638,7 +638,9 @@ String Z_attribute::toString(bool prefix_comma) const {
if (val.arrval) { if (val.arrval) {
res += val.arrval->toString(); res += val.arrval->toString();
} else { } else {
res += "[]"; // res += '[';
// res += ']';
res += F("[]");
} }
break; break;
} }

View File

@ -556,7 +556,7 @@ void Z_Device::jsonPublishAttrList(const char * json_prefix, const Z_attribute_l
if (Settings.flag5.zb_received_as_subtopic) if (Settings.flag5.zb_received_as_subtopic)
GetTopic_P(stopic, TELE, subtopic, json_prefix); GetTopic_P(stopic, TELE, subtopic, json_prefix);
else else
GetTopic_P(stopic, TELE, subtopic, D_RSLT_SENSOR); GetTopic_P(stopic, TELE, subtopic, PSTR(D_RSLT_SENSOR));
MqttPublish(stopic, Settings.flag.mqtt_sensor_retain); MqttPublish(stopic, Settings.flag.mqtt_sensor_retain);
} else { } else {
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
@ -767,7 +767,7 @@ String Z_Devices::dumpCoordinator(void) const {
attr_list.addAttributePMEM(PSTR("IEEEAddr")).setHex64(localIEEEAddr); attr_list.addAttributePMEM(PSTR("IEEEAddr")).setHex64(localIEEEAddr);
attr_list.addAttributePMEM(PSTR("TotalDevices")).setUInt(zigbee_devices.devicesSize()); attr_list.addAttributePMEM(PSTR("TotalDevices")).setUInt(zigbee_devices.devicesSize());
return attr_list.toString(); return attr_list.toString(true);
} }
// If &device == nullptr, then dump all // If &device == nullptr, then dump all

View File

@ -62,13 +62,13 @@ void HueLightStatus1Zigbee(uint16_t shortaddr, uint8_t local_light_subtype, Stri
const size_t buf_size = 256; const size_t buf_size = 256;
char * buf = (char*) malloc(buf_size); // temp buffer for strings, avoid stack char * buf = (char*) malloc(buf_size); // temp buffer for strings, avoid stack
snprintf_P(buf, buf_size, PSTR("{\"on\":%s,"), power ? "true" : "false"); snprintf_P(buf, buf_size, PSTR("{\"on\":%s,"), power ? PSTR("true") : PSTR("false"));
// Brightness for all devices with PWM // Brightness for all devices with PWM
if ((1 == echo_gen) || (LST_SINGLE <= local_light_subtype)) { // force dimmer for 1st gen Echo if ((1 == echo_gen) || (LST_SINGLE <= local_light_subtype)) { // force dimmer for 1st gen Echo
snprintf_P(buf, buf_size, PSTR("%s\"bri\":%d,"), buf, bri); snprintf_P(buf, buf_size, PSTR("%s\"bri\":%d,"), buf, bri);
} }
if (LST_COLDWARM <= local_light_subtype) { if (LST_COLDWARM <= local_light_subtype) {
snprintf_P(buf, buf_size, PSTR("%s\"colormode\":\"%s\","), buf, (0 == colormode) ? "hs" : (1 == colormode) ? "xy" : "ct"); snprintf_P(buf, buf_size, PSTR("%s\"colormode\":\"%s\","), buf, (0 == colormode) ? PSTR("hs") : (1 == colormode) ? PSTR("xy") : PSTR("ct"));
} }
if (LST_RGB <= local_light_subtype) { // colors if (LST_RGB <= local_light_subtype) { // colors
if (prev_x_str[0] && prev_y_str[0]) { if (prev_x_str[0] && prev_y_str[0]) {
@ -83,7 +83,7 @@ void HueLightStatus1Zigbee(uint16_t shortaddr, uint8_t local_light_subtype, Stri
if (LST_COLDWARM == local_light_subtype || LST_RGBW <= local_light_subtype) { // white temp if (LST_COLDWARM == local_light_subtype || LST_RGBW <= local_light_subtype) { // white temp
snprintf_P(buf, buf_size, PSTR("%s\"ct\":%d,"), buf, ct > 0 ? ct : 284); snprintf_P(buf, buf_size, PSTR("%s\"ct\":%d,"), buf, ct > 0 ? ct : 284);
} }
snprintf_P(buf, buf_size, HUE_LIGHTS_STATUS_JSON1_SUFFIX_ZIGBEE, buf, reachable ? "true" : "false"); snprintf_P(buf, buf_size, HUE_LIGHTS_STATUS_JSON1_SUFFIX_ZIGBEE, buf, reachable ? PSTR("true") : PSTR("false"));
*response += buf; *response += buf;
free(buf); free(buf);
@ -233,7 +233,7 @@ void ZigbeeHandleHue(uint16_t shortaddr, uint32_t device_id, String &response) {
on = hue_on.getBool(); on = hue_on.getBool();
snprintf_P(buf, buf_size, snprintf_P(buf, buf_size,
msg[HUE_RESP_ON], msg[HUE_RESP_ON],
device_id, on ? "true" : "false"); device_id, on ? PSTR("true") : PSTR("false"));
if (on) { if (on) {
ZigbeeHuePower(shortaddr, 0x01); ZigbeeHuePower(shortaddr, 0x01);
@ -252,7 +252,7 @@ void ZigbeeHandleHue(uint16_t shortaddr, uint32_t device_id, String &response) {
if (resp) { response += ","; } if (resp) { response += ","; }
snprintf_P(buf, buf_size, snprintf_P(buf, buf_size,
msg[HUE_RESP_NUM], msg[HUE_RESP_NUM],
device_id, "bri", bri); device_id, PSTR("bri"), bri);
response += buf; response += buf;
if (LST_SINGLE <= bulbtype) { if (LST_SINGLE <= bulbtype) {
// extend bri value if set to max // extend bri value if set to max
@ -293,7 +293,7 @@ void ZigbeeHandleHue(uint16_t shortaddr, uint32_t device_id, String &response) {
if (resp) { response += ","; } if (resp) { response += ","; }
snprintf_P(buf, buf_size, snprintf_P(buf, buf_size,
msg[HUE_RESP_NUM], msg[HUE_RESP_NUM],
device_id, "hue", hue); device_id, PSTR("hue"), hue);
response += buf; response += buf;
if (LST_RGB <= bulbtype) { if (LST_RGB <= bulbtype) {
// change range from 0..65535 to 0..360 // change range from 0..65535 to 0..360
@ -311,7 +311,7 @@ void ZigbeeHandleHue(uint16_t shortaddr, uint32_t device_id, String &response) {
if (resp) { response += ","; } if (resp) { response += ","; }
snprintf_P(buf, buf_size, snprintf_P(buf, buf_size,
msg[HUE_RESP_NUM], msg[HUE_RESP_NUM],
device_id, "sat", sat); device_id, PSTR("sat"), sat);
response += buf; response += buf;
if (LST_RGB <= bulbtype) { if (LST_RGB <= bulbtype) {
// extend sat value if set to max // extend sat value if set to max
@ -332,7 +332,7 @@ void ZigbeeHandleHue(uint16_t shortaddr, uint32_t device_id, String &response) {
if (resp) { response += ","; } if (resp) { response += ","; }
snprintf_P(buf, buf_size, snprintf_P(buf, buf_size,
msg[HUE_RESP_NUM], msg[HUE_RESP_NUM],
device_id, "ct", ct); device_id, PSTR("ct"), ct);
response += buf; response += buf;
if ((LST_COLDWARM == bulbtype) || (LST_RGBW <= bulbtype)) { if ((LST_COLDWARM == bulbtype) || (LST_RGBW <= bulbtype)) {
ZigbeeHueCT(shortaddr, ct); ZigbeeHueCT(shortaddr, ct);

View File

@ -1673,6 +1673,27 @@ void ZCLFrame::parseClusterSpecificCommand(Z_attribute_list& attr_list) {
} }
} }
} }
// Send Default Response to acknowledge the attribute reporting
if (0 == _frame_control.b.disable_def_resp) {
// the device expects a default response
SBuffer buf(2);
buf.add8(_cmd_id);
buf.add8(0x00); // Status = OK
ZigbeeZCLSend_Raw(ZigbeeZCLSendMessage({
_srcaddr,
0x0000,
_cluster_id,
_srcendpoint,
ZCL_DEFAULT_RESPONSE,
_manuf_code,
false /* not cluster specific */,
false /* noresponse */,
true /* direct no retry */,
_transact_seq, /* zcl transaction id */
buf.getBuffer(), buf.len()
}));
}
} }
// ====================================================================== // ======================================================================

View File

@ -789,38 +789,38 @@ static const Zigbee_Instruction zb_prog[] PROGMEM = {
// configure EFR32 // configure EFR32
ZI_MQTT_STATE(ZIGBEE_STATUS_STARTING, kConfiguredCoord) ZI_MQTT_STATE(ZIGBEE_STATUS_STARTING, kConfiguredCoord)
ZI_SEND(ZBS_SET_ADDR_TABLE) ZI_WAIT_RECV(500, ZBR_SET_OK) // Address table size ZI_SEND(ZBS_SET_ADDR_TABLE) ZI_WAIT_RECV(2500, ZBR_SET_OK) // Address table size
ZI_SEND(ZBS_SET_MCAST_TABLE) ZI_WAIT_RECV(500, ZBR_SET_OK) ZI_SEND(ZBS_SET_MCAST_TABLE) ZI_WAIT_RECV(2500, ZBR_SET_OK)
ZI_SEND(ZBS_SET_STK_PROF) ZI_WAIT_RECV(500, ZBR_SET_OK) ZI_SEND(ZBS_SET_STK_PROF) ZI_WAIT_RECV(2500, ZBR_SET_OK)
ZI_SEND(ZBS_SET_SEC_LEVEL) ZI_WAIT_RECV(500, ZBR_SET_OK) ZI_SEND(ZBS_SET_SEC_LEVEL) ZI_WAIT_RECV(2500, ZBR_SET_OK)
ZI_SEND(ZBS_SET_MAX_DEVICES) ZI_WAIT_RECV(500, ZBR_SET_OK) ZI_SEND(ZBS_SET_MAX_DEVICES) ZI_WAIT_RECV(2500, ZBR_SET_OK)
ZI_SEND(ZBS_SET_INDIRECT_TMO) ZI_WAIT_RECV(500, ZBR_SET_OK) ZI_SEND(ZBS_SET_INDIRECT_TMO) ZI_WAIT_RECV(2500, ZBR_SET_OK)
ZI_SEND(ZBS_SET_TC_CACHE) ZI_WAIT_RECV(500, ZBR_SET_OK) ZI_SEND(ZBS_SET_TC_CACHE) ZI_WAIT_RECV(2500, ZBR_SET_OK)
ZI_SEND(ZBS_SET_ROUTE_TBL) ZI_WAIT_RECV(500, ZBR_SET_OK) ZI_SEND(ZBS_SET_ROUTE_TBL) ZI_WAIT_RECV(2500, ZBR_SET_OK)
ZI_SEND(ZBS_SET_KEY_TBL) ZI_WAIT_RECV(500, ZBR_SET_OK) ZI_SEND(ZBS_SET_KEY_TBL) ZI_WAIT_RECV(2500, ZBR_SET_OK)
ZI_SEND(ZBS_SET_PANID_CNFLCT) ZI_WAIT_RECV(500, ZBR_SET_OK) ZI_SEND(ZBS_SET_PANID_CNFLCT) ZI_WAIT_RECV(2500, ZBR_SET_OK)
ZI_SEND(ZBS_SET_ZDO_REQ) ZI_WAIT_RECV(500, ZBR_SET_OK) ZI_SEND(ZBS_SET_ZDO_REQ) ZI_WAIT_RECV(2500, ZBR_SET_OK)
ZI_SEND(ZBS_SET_NETWORKS) ZI_WAIT_RECV(500, ZBR_SET_OK) ZI_SEND(ZBS_SET_NETWORKS) ZI_WAIT_RECV(2500, ZBR_SET_OK)
ZI_SEND(ZBS_SET_PACKET_BUF) ZI_WAIT_RECV(500, ZBR_SET_OK2) ZI_SEND(ZBS_SET_PACKET_BUF) ZI_WAIT_RECV(2500, ZBR_SET_OK2)
// read configuration // read configuration
// TODO - not sure it's useful // TODO - not sure it's useful
//ZI_SEND(ZBS_GET_APS_UNI) ZI_WAIT_RECV_FUNC(500, ZBR_GET_OK, &EZ_ReadAPSUnicastMessage) //ZI_SEND(ZBS_GET_APS_UNI) ZI_WAIT_RECV_FUNC(2500, ZBR_GET_OK, &EZ_ReadAPSUnicastMessage)
// add endpoint 0x01 and 0x0B // add endpoint 0x01 and 0x0B
ZI_SEND(ZBS_ADD_ENDPOINT1) ZI_WAIT_RECV(500, ZBR_ADD_ENDPOINT) ZI_SEND(ZBS_ADD_ENDPOINT1) ZI_WAIT_RECV(2500, ZBR_ADD_ENDPOINT)
ZI_SEND(ZBS_ADD_ENDPOINTB) ZI_WAIT_RECV(500, ZBR_ADD_ENDPOINT) ZI_SEND(ZBS_ADD_ENDPOINTB) ZI_WAIT_RECV(2500, ZBR_ADD_ENDPOINT)
// set Concentrator // set Concentrator
ZI_SEND(ZBS_SET_CONCENTRATOR) ZI_WAIT_RECV(500, ZBR_SET_CONCENTRATOR) ZI_SEND(ZBS_SET_CONCENTRATOR) ZI_WAIT_RECV(2500, ZBR_SET_CONCENTRATOR)
// setInitialSecurityState // setInitialSecurityState
ZI_SEND(ZBS_SET_POLICY_00) ZI_WAIT_RECV(500, ZBR_SET_POLICY_XX) ZI_SEND(ZBS_SET_POLICY_00) ZI_WAIT_RECV(2500, ZBR_SET_POLICY_XX)
ZI_SEND(ZBS_SET_POLICY_02) ZI_WAIT_RECV(500, ZBR_SET_POLICY_XX) ZI_SEND(ZBS_SET_POLICY_02) ZI_WAIT_RECV(2500, ZBR_SET_POLICY_XX)
ZI_SEND(ZBS_SET_POLICY_03) ZI_WAIT_RECV(500, ZBR_SET_POLICY_XX) ZI_SEND(ZBS_SET_POLICY_03) ZI_WAIT_RECV(2500, ZBR_SET_POLICY_XX)
// ZI_SEND(ZBS_SET_POLICY_04) ZI_WAIT_RECV(500, ZBR_SET_POLICY_XX) // ZI_SEND(ZBS_SET_POLICY_04) ZI_WAIT_RECV(2500, ZBR_SET_POLICY_XX)
ZI_SEND(ZBS_SET_POLICY_05) ZI_WAIT_RECV(500, ZBR_SET_POLICY_XX) ZI_SEND(ZBS_SET_POLICY_05) ZI_WAIT_RECV(2500, ZBR_SET_POLICY_XX)
ZI_SEND(ZBS_SET_POLICY_06) ZI_WAIT_RECV(500, ZBR_SET_POLICY_XX) ZI_SEND(ZBS_SET_POLICY_06) ZI_WAIT_RECV(2500, ZBR_SET_POLICY_XX)
// Decide whether we try 'networkInit()' to restore configuration, or create a new network // Decide whether we try 'networkInit()' to restore configuration, or create a new network
ZI_CALL(&EZ_GotoIfResetConfig, ZIGBEE_LABEL_CONFIGURE_EZSP) // goto ZIGBEE_LABEL_CONFIGURE_EZSP if reset_config is set ZI_CALL(&EZ_GotoIfResetConfig, ZIGBEE_LABEL_CONFIGURE_EZSP) // goto ZIGBEE_LABEL_CONFIGURE_EZSP if reset_config is set
@ -830,12 +830,12 @@ static const Zigbee_Instruction zb_prog[] PROGMEM = {
// Try networkInit to restore settings, and check if network comes up // Try networkInit to restore settings, and check if network comes up
ZI_ON_TIMEOUT_GOTO(ZIGBEE_LABEL_BAD_CONFIG) // ZI_ON_TIMEOUT_GOTO(ZIGBEE_LABEL_BAD_CONFIG) //
ZI_ON_ERROR_GOTO(ZIGBEE_LABEL_BAD_CONFIG) ZI_ON_ERROR_GOTO(ZIGBEE_LABEL_BAD_CONFIG)
ZI_SEND(ZBS_NETWORK_INIT) ZI_WAIT_RECV(500, ZBR_NETWORK_INIT) ZI_SEND(ZBS_NETWORK_INIT) ZI_WAIT_RECV(2500, ZBR_NETWORK_INIT)
ZI_WAIT_RECV(1500, ZBR_NETWORK_UP) // wait for network to start ZI_WAIT_RECV(1500, ZBR_NETWORK_UP) // wait for network to start
// check if configuration is ok // check if configuration is ok
ZI_SEND(ZBS_GET_KEY_NWK) ZI_WAIT_RECV_FUNC(500, ZBR_GET_KEY_NWK, &EZ_CheckKeyNWK) ZI_SEND(ZBS_GET_KEY_NWK) ZI_WAIT_RECV_FUNC(2500, ZBR_GET_KEY_NWK, &EZ_CheckKeyNWK)
ZI_SEND(ZBS_GET_EUI64) ZI_WAIT_RECV_FUNC(500, ZBR_GET_EUI64, &EZ_GetEUI64) ZI_SEND(ZBS_GET_EUI64) ZI_WAIT_RECV_FUNC(2500, ZBR_GET_EUI64, &EZ_GetEUI64)
ZI_SEND(ZBS_GET_NETW_PARM) ZI_WAIT_RECV_FUNC(500, ZBR_CHECK_NETW_PARM, &EZ_NetworkParameters) ZI_SEND(ZBS_GET_NETW_PARM) ZI_WAIT_RECV_FUNC(2500, ZBR_CHECK_NETW_PARM, &EZ_NetworkParameters)
// all ok, proceed to next step // all ok, proceed to next step
ZI_GOTO(ZIGBEE_LABEL_NETWORK_CONFIGURED) ZI_GOTO(ZIGBEE_LABEL_NETWORK_CONFIGURED)
@ -851,9 +851,9 @@ static const Zigbee_Instruction zb_prog[] PROGMEM = {
ZI_ON_TIMEOUT_GOTO(ZIGBEE_LABEL_ABORT) ZI_ON_TIMEOUT_GOTO(ZIGBEE_LABEL_ABORT)
ZI_ON_ERROR_GOTO(ZIGBEE_LABEL_ABORT) ZI_ON_ERROR_GOTO(ZIGBEE_LABEL_ABORT)
// set encryption keys // set encryption keys
ZI_SEND(ZBS_SET_SECURITY) ZI_WAIT_RECV(500, ZBR_SET_SECURITY) ZI_SEND(ZBS_SET_SECURITY) ZI_WAIT_RECV(2500, ZBR_SET_SECURITY)
// formNetwork // formNetwork
ZI_SEND(ZBS_FORM_NETWORK) ZI_WAIT_RECV(500, ZBR_FORM_NETWORK) ZI_SEND(ZBS_FORM_NETWORK) ZI_WAIT_RECV(2500, ZBR_FORM_NETWORK)
ZI_WAIT_RECV(5000, ZBR_NETWORK_UP) // wait for network to start ZI_WAIT_RECV(5000, ZBR_NETWORK_UP) // wait for network to start
ZI_LABEL(ZIGBEE_LABEL_NETWORK_CONFIGURED) ZI_LABEL(ZIGBEE_LABEL_NETWORK_CONFIGURED)
@ -861,11 +861,11 @@ static const Zigbee_Instruction zb_prog[] PROGMEM = {
ZI_ON_TIMEOUT_GOTO(ZIGBEE_LABEL_ABORT) ZI_ON_TIMEOUT_GOTO(ZIGBEE_LABEL_ABORT)
ZI_ON_ERROR_GOTO(ZIGBEE_LABEL_ABORT) ZI_ON_ERROR_GOTO(ZIGBEE_LABEL_ABORT)
// Query device information // Query device information
ZI_SEND(ZBS_GET_EUI64) ZI_WAIT_RECV_FUNC(500, ZBR_GET_EUI64, &EZ_GetEUI64) ZI_SEND(ZBS_GET_EUI64) ZI_WAIT_RECV_FUNC(2500, ZBR_GET_EUI64, &EZ_GetEUI64)
ZI_SEND(ZBS_GET_NODEID) ZI_WAIT_RECV_FUNC(500, ZBR_GET_NODEID, &EZ_GetNodeId) ZI_SEND(ZBS_GET_NODEID) ZI_WAIT_RECV_FUNC(2500, ZBR_GET_NODEID, &EZ_GetNodeId)
// auto-register multicast group 0x0000 // auto-register multicast group 0x0000
ZI_LOG(LOG_LEVEL_INFO, kZigbeeGroup0) ZI_LOG(LOG_LEVEL_INFO, kZigbeeGroup0)
ZI_SEND(ZBS_SET_MCAST_ENTRY) ZI_WAIT_RECV(500, ZBR_SET_MCAST_ENTRY) ZI_SEND(ZBS_SET_MCAST_ENTRY) ZI_WAIT_RECV(2500, ZBR_SET_MCAST_ENTRY)
// ZI_LABEL(ZIGBEE_LABEL_READY) // ZI_LABEL(ZIGBEE_LABEL_READY)
ZI_MQTT_STATE(ZIGBEE_STATUS_OK, kStarted) ZI_MQTT_STATE(ZIGBEE_STATUS_OK, kStarted)

View File

@ -81,6 +81,13 @@ char ZigbeeUploadFlashRead(void) {
ZbUpload.byte_counter++; ZbUpload.byte_counter++;
if (ZbUpload.byte_counter > ZbUpload.ota_size) { if (ZbUpload.byte_counter > ZbUpload.ota_size) {
// static bool padding = true;
// if (padding) {
// AddLog_P(LOG_LEVEL_DEBUG, PSTR("XMD: Start padding from %d"), ZbUpload.byte_counter);
// padding = false;
// }
// When the source device reaches the last XModem data block, it should be padded to 128 bytes // When the source device reaches the last XModem data block, it should be padded to 128 bytes
// of data using SUB (ASCII 0x1A) characters. // of data using SUB (ASCII 0x1A) characters.
data = XM_SUB; data = XM_SUB;
@ -107,8 +114,8 @@ struct XMODEM {
uint32_t delay = 0; uint32_t delay = 0;
uint32_t flush_delay = 0xFFFFFFFF; uint32_t flush_delay = 0xFFFFFFFF;
uint32_t filepos = 0; uint32_t filepos = 0;
uint32_t packet_no = 1;
int crcBuf = 0; int crcBuf = 0;
uint8_t packetNo = 1;
uint8_t checksumBuf = 0; uint8_t checksumBuf = 0;
bool oldChecksum; bool oldChecksum;
} XModem; } XModem;
@ -142,6 +149,11 @@ char XModemWaitACK(void)
if (i > 200) { return -1; } if (i > 200) { return -1; }
} }
in_char = ZigbeeSerial->read(); in_char = ZigbeeSerial->read();
// if (in_char != XM_ACK) {
// AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("XMD: Rcvd3 0x%02X"), in_char);
// }
if (XM_CAN == in_char) { return XM_CAN; } if (XM_CAN == in_char) { return XM_CAN; }
} while ((in_char != XM_NAK) && (in_char != XM_ACK) && (in_char != 'C')); } while ((in_char != XM_NAK) && (in_char != XM_ACK) && (in_char != 'C'));
return in_char; return in_char;
@ -162,10 +174,12 @@ bool XModemSendPacket(uint32_t packet_no) {
XModem.checksumBuf = 0x00; XModem.checksumBuf = 0x00;
XModem.crcBuf = 0x00; XModem.crcBuf = 0x00;
uint8_t packet_num = packet_no;
// Try to send packet, so header first // Try to send packet, so header first
ZigbeeSerial->write(XM_SOH); ZigbeeSerial->write(XM_SOH);
ZigbeeSerial->write(packet_no); ZigbeeSerial->write(packet_num);
ZigbeeSerial->write(~packet_no); ZigbeeSerial->write(~packet_num);
for (uint32_t i = 0; i < XMODEM_PACKET_SIZE; i++) { for (uint32_t i = 0; i < XMODEM_PACKET_SIZE; i++) {
in_char = ZigbeeUploadFlashRead(); in_char = ZigbeeUploadFlashRead();
XModemOutputByte(in_char); XModemOutputByte(in_char);
@ -220,6 +234,13 @@ bool ZigbeeUploadBootloaderPrompt(void) {
yield(); yield();
char bootloader_byte = ZigbeeSerial->read(); char bootloader_byte = ZigbeeSerial->read();
// [cr][lf]
// Gecko Bootloader v1.A.3 or Gecko Bootloader v1.9.1.04[cr][lf]
// 1. upload gbl[cr][lf]
// 2. run[cr][lf]
// 3. ebl info[cr][lf]
// BL >
if (((uint8_t)bootloader_byte >=0) && (buf_len < sizeof(serial_buffer) -2)) { if (((uint8_t)bootloader_byte >=0) && (buf_len < sizeof(serial_buffer) -2)) {
serial_buffer[buf_len++] = bootloader_byte; serial_buffer[buf_len++] = bootloader_byte;
} }
@ -332,10 +353,11 @@ bool ZigbeeUploadXmodem(void) {
} }
} else { } else {
// After the bootloader receives a carriage return from the target device, it displays a menu // After the bootloader receives a carriage return from the target device, it displays a menu
// Gecko Bootloader v1.A.3 // [cr][lf]
// 1. upload gbl // Gecko Bootloader v1.A.3 or Gecko Bootloader v1.9.1.04[cr][lf]
// 2. run // 1. upload gbl[cr][lf]
// 3. ebl info // 2. run[cr][lf]
// 3. ebl info[cr][lf]
// BL > // BL >
if (ZigbeeUploadBootloaderPrompt()) { if (ZigbeeUploadBootloaderPrompt()) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("XMD: Init sync")); AddLog_P(LOG_LEVEL_DEBUG, PSTR("XMD: Init sync"));
@ -358,11 +380,17 @@ bool ZigbeeUploadXmodem(void) {
} }
// Wait for either C or NACK as a sync packet. Determines protocol details, checksum algorithm. // Wait for either C or NACK as a sync packet. Determines protocol details, checksum algorithm.
if (ZigbeeSerial->available()) { if (ZigbeeSerial->available()) {
// [cr][lf]
// begin upload[cr][lf]
// C
char xmodem_sync = ZigbeeSerial->read(); char xmodem_sync = ZigbeeSerial->read();
// AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("XMD: Rcvd2 0x%02X"), xmodem_sync);
if (('C' == xmodem_sync) || (XM_NAK == xmodem_sync)) { if (('C' == xmodem_sync) || (XM_NAK == xmodem_sync)) {
// Determine which checksum algorithm to use // Determine which checksum algorithm to use
XModem.oldChecksum = (xmodem_sync == XM_NAK); XModem.oldChecksum = (xmodem_sync == XM_NAK);
XModem.packetNo = 1; XModem.packet_no = 1;
ZbUpload.byte_counter = 0; ZbUpload.byte_counter = 0;
ZbUpload.ota_step = ZBU_UPLOAD; ZbUpload.ota_step = ZBU_UPLOAD;
AddLog_P(LOG_LEVEL_DEBUG, PSTR("XMD: Init packet send")); AddLog_P(LOG_LEVEL_DEBUG, PSTR("XMD: Init packet send"));
@ -372,12 +400,15 @@ bool ZigbeeUploadXmodem(void) {
} }
case ZBU_UPLOAD: { // *** Handle file upload using XModem - upload case ZBU_UPLOAD: { // *** Handle file upload using XModem - upload
if (ZigbeeUploadAvailable()) { if (ZigbeeUploadAvailable()) {
if (!XModemSendPacket(XModem.packetNo)) { if (ZbUpload.byte_counter && !(ZbUpload.byte_counter % 10240)) { // Show progress every 10kB
AddLog_P(LOG_LEVEL_DEBUG, PSTR("XMD: Packet send failed")); AddLog_P(LOG_LEVEL_DEBUG, PSTR("XMD: Progress %d kB"), ZbUpload.byte_counter / 1024);
}
if (!XModemSendPacket(XModem.packet_no)) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("XMD: Packet %d send failed"), XModem.packet_no);
ZbUpload.ota_step = ZBU_ERROR; ZbUpload.ota_step = ZBU_ERROR;
return true; return true;
} }
XModem.packetNo++; XModem.packet_no++;
} else { } else {
// Once the last block is ACKed by the target, the transfer should be finalized by an // Once the last block is ACKed by the target, the transfer should be finalized by an
// EOT (ASCII 0x04) packet from the source. Once this packet is confirmed via XModem ACK // EOT (ASCII 0x04) packet from the source. Once this packet is confirmed via XModem ACK
@ -385,6 +416,7 @@ bool ZigbeeUploadXmodem(void) {
ZigbeeSerial->write(XM_EOT); ZigbeeSerial->write(XM_EOT);
XModem.timeout = millis() + (30 * 1000); // Allow 30 seconds to receive EOT ACK XModem.timeout = millis() + (30 * 1000); // Allow 30 seconds to receive EOT ACK
ZbUpload.ota_step = ZBU_EOT; ZbUpload.ota_step = ZBU_EOT;
AddLog_P(LOG_LEVEL_DEBUG, PSTR("XMD: Transferred %d bytes"), ZbUpload.ota_size);
} }
break; break;
} }
@ -401,7 +433,12 @@ bool ZigbeeUploadXmodem(void) {
} }
if (ZigbeeSerial->available()) { if (ZigbeeSerial->available()) {
char xmodem_ack = XModemWaitACK(); char xmodem_ack = XModemWaitACK();
if (XM_ACK == xmodem_ack) { if (XM_CAN == xmodem_ack) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("XMD: Transfer invalid"));
ZbUpload.ota_step = ZBU_ERROR;
return true;
}
else if (XM_ACK == xmodem_ack) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("XMD: " D_SUCCESSFUL)); AddLog_P(LOG_LEVEL_DEBUG, PSTR("XMD: " D_SUCCESSFUL));
XModem.timeout = millis() + (30 * 1000); // Allow 30 seconds to receive EBL prompt XModem.timeout = millis() + (30 * 1000); // Allow 30 seconds to receive EBL prompt
ZbUpload.byte_counter = 0; ZbUpload.byte_counter = 0;
@ -418,28 +455,33 @@ bool ZigbeeUploadXmodem(void) {
} else { } else {
// After an image successfully uploads, the XModem transaction completes and the bootloader displays // After an image successfully uploads, the XModem transaction completes and the bootloader displays
// Serial upload complete before redisplaying the menu // Serial upload complete before redisplaying the menu
// Serial upload complete //
// Gecko Bootloader v1.A.3 // [cr][lf]
// 1. upload gbl // Serial upload complete[cr][lf]
// 2. run // [cr][lf]
// 3. ebl info // Gecko Bootloader v1.A.3 or Gecko Bootloader v1.9.1.04[cr][lf]
// 1. upload gbl[cr][lf]
// 2. run[cr][lf]
// 3. ebl info[cr][lf]
// BL > // BL >
if (ZigbeeUploadBootloaderPrompt()) { if (ZigbeeUploadBootloaderPrompt()) {
ZbUpload.state = ZBU_COMPLETE; ZbUpload.state = ZBU_COMPLETE;
ZbUpload.ota_step = ZBU_DONE; ZbUpload.ota_step = ZBU_DONE;
AddLog_P(LOG_LEVEL_DEBUG, PSTR("XMD: " D_RESTARTING));
} }
} }
break; break;
} }
case ZBU_ERROR: case ZBU_ERROR:
ZbUpload.state = ZBU_ERROR; ZbUpload.state = ZBU_ERROR;
AddLog_P(LOG_LEVEL_DEBUG, PSTR("XMD: " D_FAILED));
case ZBU_DONE: { // *** Clean up and restart to disable bootloader and use new firmware case ZBU_DONE: { // *** Clean up and restart to disable bootloader and use new firmware
AddLog_P(LOG_LEVEL_DEBUG, PSTR("XMD: " D_RESTARTING));
ZigbeeUploadSetBootloader(1); // Disable bootloader and reset MCU - should happen at restart ZigbeeUploadSetBootloader(1); // Disable bootloader and reset MCU - should happen at restart
if (1 == TasmotaGlobal.sleep) { if (1 == TasmotaGlobal.sleep) {
TasmotaGlobal.sleep = Settings.sleep; // Restore loop sleep TasmotaGlobal.sleep = Settings.sleep; // Restore loop sleep
} }
// TasmotaGlobal.restart_flag = 2; // Restart to disable bootloader and use new firmware // TasmotaGlobal.restart_flag = 2; // Restart to disable bootloader and use new firmware
if (ZbUpload.buffer) { free(ZbUpload.buffer); }
ZbUpload.ota_step = ZBU_FINISH; // Never return to zero without a restart to get a sane Zigbee environment ZbUpload.ota_step = ZBU_FINISH; // Never return to zero without a restart to get a sane Zigbee environment
break; break;
} }
@ -472,10 +514,6 @@ void ZigbeeUploadStep1Done(uint32_t data, size_t size) {
ZbUpload.state = ZBU_UPLOAD; // Signal upload done and ready for delayed upload to MCU EFR32 ZbUpload.state = ZBU_UPLOAD; // Signal upload done and ready for delayed upload to MCU EFR32
} }
bool ZigbeeUploadFinish(void) {
return (ZBU_FINISH == ZbUpload.ota_step);
}
#define WEB_HANDLE_ZIGBEE_XFER "zx" #define WEB_HANDLE_ZIGBEE_XFER "zx"
const char HTTP_SCRIPT_XFER_STATE[] PROGMEM = const char HTTP_SCRIPT_XFER_STATE[] PROGMEM =
@ -500,12 +538,12 @@ void HandleZigbeeXfer(void) {
if (!HttpCheckPriviledgedAccess()) { return; } if (!HttpCheckPriviledgedAccess()) { return; }
if (Webserver->hasArg("z")) { // Status refresh requested if (Webserver->hasArg("z")) { // Status refresh requested
WSContentBegin(200, CT_PLAIN);
WSContentSend_P(PSTR("%d"), ZbUpload.state);
WSContentEnd();
if (ZBU_ERROR == ZbUpload.state) { if (ZBU_ERROR == ZbUpload.state) {
Web.upload_error = 7; // Upload aborted (xmodem transfer failed) Web.upload_error = 7; // Upload aborted (xmodem transfer failed)
} }
WSContentBegin(200, CT_PLAIN);
WSContentSend_P(PSTR("%d"), ZbUpload.state);
WSContentEnd();
return; return;
} }

View File

@ -2092,7 +2092,7 @@ void ZigbeeMapRefresh(void) {
if ((!zigbee.init_phase) && (!zigbee.mapping_in_progress)) { if ((!zigbee.init_phase) && (!zigbee.mapping_in_progress)) {
ZigbeeMapAllDevices(); ZigbeeMapAllDevices();
} }
Webserver->sendHeader("Location","/zbm"); // Add a header to respond with a new location for the browser to go to the home page again Webserver->sendHeader(F("Location"),F("/zbm")); // Add a header to respond with a new location for the browser to go to the home page again
Webserver->send(302); Webserver->send(302);
} }

View File

@ -303,7 +303,7 @@ void PingResponsePoll(void) {
",\"AvgTime\":%d" ",\"AvgTime\":%d"
"}}}"), "}}}"),
ping->hostname.c_str(), ping->hostname.c_str(),
success ? "true" : "false", success ? PSTR("true") : PSTR("false"),
ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24, ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24,
success, success,
ping->timeout_count, ping->timeout_count,

View File

@ -434,14 +434,14 @@ void CmndTmChatId(void) {
void CmndTmSend(void) { void CmndTmSend(void) {
if (!Telegram.send_enable || !strlen(SettingsText(SET_TELEGRAM_CHATID))) { if (!Telegram.send_enable || !strlen(SettingsText(SET_TELEGRAM_CHATID))) {
ResponseCmndChar(D_JSON_FAILED); ResponseCmndChar(PSTR(D_JSON_FAILED));
return; return;
} }
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
String message = XdrvMailbox.data; String message = XdrvMailbox.data;
String chat_id = SettingsText(SET_TELEGRAM_CHATID); String chat_id = SettingsText(SET_TELEGRAM_CHATID);
if (!TelegramSendMessage(chat_id.toInt(), message)) { if (!TelegramSendMessage(chat_id.toInt(), message)) {
ResponseCmndChar(D_JSON_FAILED); ResponseCmndChar(PSTR(D_JSON_FAILED));
return; return;
} }
} }

View File

@ -391,7 +391,7 @@ void UFSDelete(void) {
result = (ufs_type && ufsp->remove(XdrvMailbox.data)); result = (ufs_type && ufsp->remove(XdrvMailbox.data));
} }
if (!result) { if (!result) {
ResponseCmndChar(D_JSON_FAILED); ResponseCmndChar(PSTR(D_JSON_FAILED));
} else { } else {
ResponseCmndDone(); ResponseCmndDone();
} }
@ -454,8 +454,8 @@ void UfsDirectory(void) {
strcpy(ufs_path, "/"); strcpy(ufs_path, "/");
if (Webserver->hasArg("download")) { if (Webserver->hasArg(F("download"))) {
String stmp = Webserver->arg("download"); String stmp = Webserver->arg(F("download"));
char *cp = (char*)stmp.c_str(); char *cp = (char*)stmp.c_str();
if (UfsDownloadFile(cp)) { if (UfsDownloadFile(cp)) {
// is directory // is directory
@ -465,8 +465,8 @@ void UfsDirectory(void) {
} }
} }
if (Webserver->hasArg("dir")) { if (Webserver->hasArg(F("dir"))) {
String stmp = Webserver->arg("dir"); String stmp = Webserver->arg(F("dir"));
ufs_dir = atoi(stmp.c_str()); ufs_dir = atoi(stmp.c_str());
if (ufs_dir == 1) { if (ufs_dir == 1) {
dfsp = ufsp; dfsp = ufsp;
@ -477,8 +477,8 @@ void UfsDirectory(void) {
} }
} }
if (Webserver->hasArg("delete")) { if (Webserver->hasArg(F("delete"))) {
String stmp = Webserver->arg("delete"); String stmp = Webserver->arg(F("delete"));
char *cp = (char*)stmp.c_str(); char *cp = (char*)stmp.c_str();
dfsp->remove(cp); dfsp->remove(cp);
} }
@ -498,7 +498,7 @@ void UfsDirectory(void) {
} }
WSContentSend_P(UFS_FORM_FILE_UPGc2); WSContentSend_P(UFS_FORM_FILE_UPGc2);
WSContentSend_P(UFS_FORM_FILE_UPG, D_SCRIPT_UPLOAD); WSContentSend_P(UFS_FORM_FILE_UPG, PSTR(D_SCRIPT_UPLOAD));
WSContentSend_P(UFS_FORM_SDC_DIRa); WSContentSend_P(UFS_FORM_SDC_DIRa);
if (ufs_type) { if (ufs_type) {
@ -516,7 +516,7 @@ void UfsListDir(char *path, uint8_t depth) {
char name[32]; char name[32];
char npath[128]; char npath[128];
char format[12]; char format[12];
sprintf(format, "%%-%ds", 24 - depth); sprintf(format, PSTR("%%-%ds"), 24 - depth);
File dir = dfsp->open(path, UFS_FILE_READ); File dir = dfsp->open(path, UFS_FILE_READ);
if (dir) { if (dir) {
@ -533,7 +533,7 @@ void UfsListDir(char *path, uint8_t depth) {
break; break;
} }
} }
WSContentSend_P(UFS_FORM_SDC_DIRd, npath, path, ".."); WSContentSend_P(UFS_FORM_SDC_DIRd, npath, path, PSTR(".."));
} }
char *ep; char *ep;
while (true) { while (true) {
@ -764,13 +764,13 @@ bool Xdrv50(uint8_t function) {
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
case FUNC_WEB_ADD_MANAGEMENT_BUTTON: case FUNC_WEB_ADD_MANAGEMENT_BUTTON:
if (ufs_type) { if (ufs_type) {
WSContentSend_PD(UFS_WEB_DIR, D_MANAGE_FILE_SYSTEM); WSContentSend_PD(UFS_WEB_DIR, PSTR(D_MANAGE_FILE_SYSTEM));
} }
break; break;
case FUNC_WEB_ADD_HANDLER: case FUNC_WEB_ADD_HANDLER:
Webserver->on("/ufsd", UfsDirectory); Webserver->on(F("/ufsd"), UfsDirectory);
Webserver->on("/ufsu", HTTP_GET, UfsDirectory); Webserver->on(F("/ufsu"), HTTP_GET, UfsDirectory);
Webserver->on("/ufsu", HTTP_POST,[](){Webserver->sendHeader("Location","/ufsu");Webserver->send(303);}, HandleUploadLoop); Webserver->on(F("/ufsu"), HTTP_POST,[](){Webserver->sendHeader(F("Location"),F("/ufsu"));Webserver->send(303);}, HandleUploadLoop);
break; break;
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
} }

View File

@ -599,7 +599,7 @@ int addSeenDevice(const uint8_t *mac, uint8_t addrtype, const char *name, int8_t
int total = seenDevices.size(); int total = seenDevices.size();
if (total < MAX_BLE_DEVICES_LOGGED){ if (total < MAX_BLE_DEVICES_LOGGED){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("new seendev slot %d"), total); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: New seendev slot %d"), total);
#endif #endif
BLE_ESP32::BLE_simple_device_t* dev = new BLE_ESP32::BLE_simple_device_t; BLE_ESP32::BLE_simple_device_t* dev = new BLE_ESP32::BLE_simple_device_t;
freeDevices.push_back(dev); freeDevices.push_back(dev);
@ -667,10 +667,10 @@ int deleteSeenDevices(int ageS = 0){
dump(addr, 20, dev->mac, 6); dump(addr, 20, dev->mac, 6);
const char *alias = getAlias(dev->mac); const char *alias = getAlias(dev->mac);
if (!filter){ if (!filter){
AddLog_P(LOG_LEVEL_INFO,PSTR("delete device %s(%s) by age lastseen %u + maxage %u < now %u."), AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: Delete device %s(%s) by age lastseen %u + maxage %u < now %u."),
addr, alias, lastseenS, ageS, nowS); addr, alias, lastseenS, ageS, nowS);
} else { } else {
AddLog_P(LOG_LEVEL_INFO,PSTR("delete device %s(%s) by addrtype filter %d > %d."), AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: Delete device %s(%s) by addrtype filter %d > %d."),
addr, alias, dev->addrtype, BLEAddressFilter); addr, alias, dev->addrtype, BLEAddressFilter);
} }
#endif #endif
@ -682,7 +682,7 @@ int deleteSeenDevices(int ageS = 0){
} }
if (res){ if (res){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_INFO,PSTR("BLE deleted %d devices"), res); AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: Deleted %d devices"), res);
#endif #endif
} }
return res; return res;
@ -820,7 +820,7 @@ int getSeenDevicesToJson(char *dest, int maxlen){
} }
// deliberate test of SafeAddLog_P from main thread... // deliberate test of SafeAddLog_P from main thread...
//AddLog_P(LOG_LEVEL_INFO,PSTR("getSeen %d"), seenDevices.size()); //AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: getSeen %d"), seenDevices.size());
int len; int len;
@ -1184,17 +1184,17 @@ void postAdvertismentDetails(){
class BLESensorCallback : public NimBLEClientCallbacks { class BLESensorCallback : public NimBLEClientCallbacks {
void onConnect(NimBLEClient* pClient) { void onConnect(NimBLEClient* pClient) {
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("onConnect %s"), ((std::string)pClient->getPeerAddress()).c_str()); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: onConnect %s"), ((std::string)pClient->getPeerAddress()).c_str());
#endif #endif
} }
void onDisconnect(NimBLEClient* pClient) { void onDisconnect(NimBLEClient* pClient) {
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("onDisconnect %s"), ((std::string)pClient->getPeerAddress()).c_str()); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: onDisconnect %s"), ((std::string)pClient->getPeerAddress()).c_str());
#endif #endif
} }
bool onConnParamsUpdateRequest(NimBLEClient* pClient, const ble_gap_upd_params* params) { bool onConnParamsUpdateRequest(NimBLEClient* pClient, const ble_gap_upd_params* params) {
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("onConnParamsUpdateRequest %s"), ((std::string)pClient->getPeerAddress()).c_str()); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: onConnParamsUpdateRequest %s"), ((std::string)pClient->getPeerAddress()).c_str());
#endif #endif
// if(params->itvl_min < 24) { /** 1.25ms units */ // if(params->itvl_min < 24) { /** 1.25ms units */
@ -1315,7 +1315,7 @@ class BLEAdvCallbacks: public NimBLEAdvertisedDeviceCallbacks {
} }
} catch(const std::exception& e){ } catch(const std::exception& e){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("exception in advertismentCallbacks")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: exception in advertismentCallbacks"));
#endif #endif
} }
} }
@ -1334,18 +1334,18 @@ static BLESensorCallback BLESensorCB;
static void BLEscanEndedCB(NimBLEScanResults results){ static void BLEscanEndedCB(NimBLEScanResults results){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("Scan ended")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: Scan ended"));
#endif #endif
for (int i = 0; i < scancompleteCallbacks.size(); i++){ for (int i = 0; i < scancompleteCallbacks.size(); i++){
try { try {
SCANCOMPLETE_CALLBACK *pFn = scancompleteCallbacks[i]; SCANCOMPLETE_CALLBACK *pFn = scancompleteCallbacks[i];
int callbackres = pFn(results); int callbackres = pFn(results);
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("scancompleteCallbacks %d %d"), i, callbackres); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: scancompleteCallbacks %d %d"), i, callbackres);
#endif #endif
} catch(const std::exception& e){ } catch(const std::exception& e){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("exception in operationsCallbacks")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: exception in operationsCallbacks"));
#endif #endif
} }
} }
@ -1367,21 +1367,21 @@ static void BLEGenNotifyCB(NimBLERemoteCharacteristic* pRemoteCharacteristic, ui
if (!pRemoteCharacteristic){ if (!pRemoteCharacteristic){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_DEBUG,PSTR("Notify: no remote char!!??")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: Notify: no remote char!!??"));
#endif #endif
return; return;
} }
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("Notified length: %u"),length); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: Notified length: %u"),length);
#endif #endif
// find the operation this is associated with // find the operation this is associated with
NimBLERemoteService *pSvc = pRemoteCharacteristic->getRemoteService(); NimBLERemoteService *pSvc = pRemoteCharacteristic->getRemoteService();
if (!pSvc){ if (!pSvc){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("Notify: no remote service found")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Notify: no remote service found"));
#endif #endif
return; return;
} }
@ -1389,7 +1389,7 @@ static void BLEGenNotifyCB(NimBLERemoteCharacteristic* pRemoteCharacteristic, ui
pRClient = pSvc->getClient(); pRClient = pSvc->getClient();
if (!pRClient){ if (!pRClient){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("Notify: no remote client!!??")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Notify: no remote client!!??"));
#endif #endif
return; return;
} }
@ -1404,7 +1404,7 @@ static void BLEGenNotifyCB(NimBLERemoteCharacteristic* pRemoteCharacteristic, ui
generic_sensor_t *op = currentOperations[i]; generic_sensor_t *op = currentOperations[i];
if (!op){ if (!op){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("Notify: null op in currentOperations!!??")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Notify: null op in currentOperations!!??"));
#endif #endif
} else { } else {
if (devaddr == op->addr){ if (devaddr == op->addr){
@ -1420,7 +1420,7 @@ static void BLEGenNotifyCB(NimBLERemoteCharacteristic* pRemoteCharacteristic, ui
if (!thisop){ if (!thisop){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_DEBUG,PSTR("no op for notify")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: no op for notify"));
#endif #endif
return; return;
} }
@ -1524,7 +1524,7 @@ static void BLEOperationTask(void *pvParameters);
static void BLEStartOperationTask(){ static void BLEStartOperationTask(){
if (BLERunning == false){ if (BLERunning == false){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_DEBUG,PSTR("%s: Start operations"),D_CMND_BLE); AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: %s: Start operations"),D_CMND_BLE);
#endif #endif
BLERunning = true; BLERunning = true;
@ -1547,25 +1547,25 @@ static void BLEStartOperationTask(){
static void BLETaskStopStartNimBLE(NimBLEClient **ppClient, bool start = true){ static void BLETaskStopStartNimBLE(NimBLEClient **ppClient, bool start = true){
if (*ppClient){ if (*ppClient){
AddLog_P(LOG_LEVEL_ERROR,PSTR("BLETask:Stopping NimBLE")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Task:Stopping NimBLE"));
(*ppClient)->setClientCallbacks(nullptr, false); (*ppClient)->setClientCallbacks(nullptr, false);
try { try {
if ((*ppClient)->isConnected()){ if ((*ppClient)->isConnected()){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_INFO,PSTR("disconnecting connected client")); AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: disconnecting connected client"));
#endif #endif
(*ppClient)->disconnect(); (*ppClient)->disconnect();
} }
NimBLEDevice::deleteClient((*ppClient)); NimBLEDevice::deleteClient((*ppClient));
(*ppClient) = nullptr; (*ppClient) = nullptr;
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_INFO,PSTR("deleted client")); AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: deleted client"));
#endif #endif
} catch(const std::exception& e){ } catch(const std::exception& e){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("Stopping NimBLE:exception in delete client")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Stopping NimBLE:exception in delete client"));
#endif #endif
} }
@ -1582,7 +1582,7 @@ static void BLETaskStopStartNimBLE(NimBLEClient **ppClient, bool start = true){
BLERunningScan = 0; BLERunningScan = 0;
if (start){ if (start){
AddLog_P(LOG_LEVEL_INFO,PSTR("BLETask:Starting NimBLE")); AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: BLETask:Starting NimBLE"));
NimBLEDevice::init("BLE_ESP32"); NimBLEDevice::init("BLE_ESP32");
*ppClient = NimBLEDevice::createClient(); *ppClient = NimBLEDevice::createClient();
@ -1623,7 +1623,7 @@ int BLETaskStartScan(int time){
} }
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLETask: Startscan")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: BLETask: Startscan"));
#endif #endif
//vTaskDelay(500/ portTICK_PERIOD_MS); //vTaskDelay(500/ portTICK_PERIOD_MS);
ble32Scan->setActiveScan(BLEScanActiveMode ? 1: 0); ble32Scan->setActiveScan(BLEScanActiveMode ? 1: 0);
@ -1652,7 +1652,7 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
*pCurrentOperation = nextOperation(&queuedOperations); *pCurrentOperation = nextOperation(&queuedOperations);
if (*pCurrentOperation){ if (*pCurrentOperation){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLETask: new currentOperation")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: BLETask: new currentOperation"));
#endif #endif
BLEOpCount++; BLEOpCount++;
generic_sensor_t* temp = *pCurrentOperation; generic_sensor_t* temp = *pCurrentOperation;
@ -1673,7 +1673,7 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
diff = diff/1000; diff = diff/1000;
if (diff > 20000){ // 20s if (diff > 20000){ // 20s
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLETask: notify timeout")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: BLETask: notify timeout"));
#endif #endif
(*pCurrentOperation)->state = GEN_STATE_FAILED_NOTIFYTIMEOUT; (*pCurrentOperation)->state = GEN_STATE_FAILED_NOTIFYTIMEOUT;
(*pCurrentOperation)->notifytimer = 0; (*pCurrentOperation)->notifytimer = 0;
@ -1690,7 +1690,7 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
(*pCurrentOperation)->state = GEN_STATE_NOTIFIED; (*pCurrentOperation)->state = GEN_STATE_NOTIFIED;
// just stay here until this is removed by the main thread // just stay here until this is removed by the main thread
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLETask: notify operation complete")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: BLETask: notify operation complete"));
#endif #endif
BLE_ESP32::BLETaskRunTaskDoneOperation(pCurrentOperation, ppClient); BLE_ESP32::BLETaskRunTaskDoneOperation(pCurrentOperation, ppClient);
pClient = *ppClient; pClient = *ppClient;
@ -1701,7 +1701,7 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
case GEN_STATE_NOTIFIED: // - may have completed DURING our read/write to get here case GEN_STATE_NOTIFIED: // - may have completed DURING our read/write to get here
// just stay here until this is removed by the main thread // just stay here until this is removed by the main thread
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLETask: operation complete")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: BLETask: operation complete"));
#endif #endif
BLE_ESP32::BLETaskRunTaskDoneOperation(pCurrentOperation, ppClient); BLE_ESP32::BLETaskRunTaskDoneOperation(pCurrentOperation, ppClient);
pClient = *ppClient; pClient = *ppClient;
@ -1721,7 +1721,7 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
if ((*pCurrentOperation)->state <= GEN_STATE_FAILED){ if ((*pCurrentOperation)->state <= GEN_STATE_FAILED){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("BLETask: op failed %d"), (*pCurrentOperation)->state); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: BLETask: op failed %d"), (*pCurrentOperation)->state);
#endif #endif
BLE_ESP32::BLETaskRunTaskDoneOperation(pCurrentOperation, ppClient); BLE_ESP32::BLETaskRunTaskDoneOperation(pCurrentOperation, ppClient);
pClient = *ppClient; pClient = *ppClient;
@ -1735,7 +1735,7 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
if (pClient->isConnected()){ if (pClient->isConnected()){
// don't do anything if we are still connected // don't do anything if we are still connected
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLETask: still connected")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: BLETask: still connected"));
#endif #endif
return; return;
} }
@ -1755,7 +1755,7 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
op->state = GEN_STATE_STARTED; op->state = GEN_STATE_STARTED;
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLETask: attempt connect %s"), ((std::string)op->addr).c_str()); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: BLETask: attempt connect %s"), ((std::string)op->addr).c_str());
#endif #endif
if (!op->serviceUUID.bitSize()){ if (!op->serviceUUID.bitSize()){
@ -1766,7 +1766,7 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
if (pClient->connect(op->addr, true)) { if (pClient->connect(op->addr, true)) {
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("connected %s -> getservice"), ((std::string)op->addr).c_str()); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: connected %s -> getservice"), ((std::string)op->addr).c_str());
#endif #endif
NimBLERemoteService *pService = pClient->getService(op->serviceUUID); NimBLERemoteService *pService = pClient->getService(op->serviceUUID);
int waitNotify = false; int waitNotify = false;
@ -1775,7 +1775,7 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
if (pService != nullptr) { if (pService != nullptr) {
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("got service")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: got service"));
#endif #endif
// pre-set to fail if no operations requested // pre-set to fail if no operations requested
//newstate = GEN_STATE_FAILED_NOREADWRITE; //newstate = GEN_STATE_FAILED_NOREADWRITE;
@ -1792,13 +1792,13 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
pService->getCharacteristic(op->notificationCharacteristicUUID); pService->getCharacteristic(op->notificationCharacteristicUUID);
if (pNCharacteristic != nullptr) { if (pNCharacteristic != nullptr) {
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("got notify characteristic")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: got notify characteristic"));
#endif #endif
op->notifylen = 0; op->notifylen = 0;
if(pNCharacteristic->canNotify()) { if(pNCharacteristic->canNotify()) {
if(pNCharacteristic->subscribe(true, BLE_ESP32::BLEGenNotifyCB)) { if(pNCharacteristic->subscribe(true, BLE_ESP32::BLEGenNotifyCB)) {
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("subscribe for notify")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: subscribe for notify"));
#endif #endif
uint64_t now = esp_timer_get_time(); uint64_t now = esp_timer_get_time();
op->notifytimer = now; op->notifytimer = now;
@ -1808,7 +1808,7 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
waitNotify = true; waitNotify = true;
} else { } else {
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("failed subscribe for notify")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: failed subscribe for notify"));
#endif #endif
newstate = GEN_STATE_FAILED_NOTIFY; newstate = GEN_STATE_FAILED_NOTIFY;
} }
@ -1816,7 +1816,7 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
if(pNCharacteristic->canIndicate()) { if(pNCharacteristic->canIndicate()) {
if(pNCharacteristic->subscribe(false, BLE_ESP32::BLEGenNotifyCB)) { if(pNCharacteristic->subscribe(false, BLE_ESP32::BLEGenNotifyCB)) {
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_DEBUG,PSTR("subscribe for indicate")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: subscribe for indicate"));
#endif #endif
notifystate = GEN_STATE_WAITINDICATE; notifystate = GEN_STATE_WAITINDICATE;
uint64_t now = esp_timer_get_time(); uint64_t now = esp_timer_get_time();
@ -1824,21 +1824,21 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
waitNotify = true; waitNotify = true;
} else { } else {
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("failed subscribe for indicate")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: failed subscribe for indicate"));
#endif #endif
newstate = GEN_STATE_FAILED_INDICATE; newstate = GEN_STATE_FAILED_INDICATE;
} }
} else { } else {
newstate = GEN_STATE_FAILED_CANTNOTIFYORINDICATE; newstate = GEN_STATE_FAILED_CANTNOTIFYORINDICATE;
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("characteristic can't notify")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: characteristic can't notify"));
#endif #endif
} }
} }
} else { } else {
newstate = GEN_STATE_FAILED_NONOTIFYCHAR; newstate = GEN_STATE_FAILED_NONOTIFYCHAR;
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("notify characteristic not found")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: notify characteristic not found"));
#endif #endif
} }
@ -1855,7 +1855,7 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
pCharacteristic = pService->getCharacteristic(op->characteristicUUID); pCharacteristic = pService->getCharacteristic(op->characteristicUUID);
if (pCharacteristic != nullptr) { if (pCharacteristic != nullptr) {
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("got read/write characteristic")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: got read/write characteristic"));
#endif #endif
newstate = GEN_STATE_FAILED_NOREADWRITE; // overwritten on failure newstate = GEN_STATE_FAILED_NOREADWRITE; // overwritten on failure
@ -1875,12 +1875,12 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
if (op->readmodifywritecallback){ if (op->readmodifywritecallback){
READ_CALLBACK *pFn = (READ_CALLBACK *)op->readmodifywritecallback; READ_CALLBACK *pFn = (READ_CALLBACK *)op->readmodifywritecallback;
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("read characteristic with readmodifywritecallback")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: read characteristic with readmodifywritecallback"));
#endif #endif
pFn(op); pFn(op);
} else { } else {
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("read characteristic")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: read characteristic"));
#endif #endif
} }
@ -1896,12 +1896,12 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
if (!pCharacteristic->writeValue(op->dataToWrite, op->writelen, true)){ if (!pCharacteristic->writeValue(op->dataToWrite, op->writelen, true)){
newstate = GEN_STATE_FAILED_WRITE; newstate = GEN_STATE_FAILED_WRITE;
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_DEBUG,PSTR("characteristic write fail")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: characteristic write fail"));
#endif #endif
} else { } else {
if (!waitNotify) newstate = GEN_STATE_WRITEDONE; if (!waitNotify) newstate = GEN_STATE_WRITEDONE;
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("write characteristic")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: write characteristic"));
#endif #endif
} }
} else { } else {
@ -1913,7 +1913,7 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
} else { } else {
newstate = GEN_STATE_FAILED_NO_RW_CHAR; newstate = GEN_STATE_FAILED_NO_RW_CHAR;
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_DEBUG,PSTR("r/w characteristic not found")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: r/w characteristic not found"));
#endif #endif
} }
} }
@ -1934,7 +1934,7 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
newstate = GEN_STATE_FAILED_NOSERVICE; newstate = GEN_STATE_FAILED_NOSERVICE;
// failed to get a service // failed to get a service
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_DEBUG,PSTR("failed - svc not on device?")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: failed - svc not on device?"));
#endif #endif
} }
@ -1946,14 +1946,14 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
switch (rc){ switch (rc){
case (0x0200+BLE_ERR_CONN_LIMIT ): case (0x0200+BLE_ERR_CONN_LIMIT ):
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("Hit connection limit? - restarting NimBLE")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Hit connection limit? - restarting NimBLE"));
#endif #endif
BLERestartNimBLE = 1; BLERestartNimBLE = 1;
BLERestartBLEReason = BLE_RESTART_BLE_REASON_CONN_LIMIT; BLERestartBLEReason = BLE_RESTART_BLE_REASON_CONN_LIMIT;
break; break;
case (0x0200+BLE_ERR_ACL_CONN_EXISTS): case (0x0200+BLE_ERR_ACL_CONN_EXISTS):
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("Connection exists? - restarting NimBLE")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Connection exists? - restarting NimBLE"));
#endif #endif
BLERestartNimBLE = 1; BLERestartNimBLE = 1;
BLERestartBLEReason = BLE_RESTART_BLE_REASON_CONN_EXISTS; BLERestartBLEReason = BLE_RESTART_BLE_REASON_CONN_EXISTS;
@ -1963,7 +1963,7 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
// failed to connect // failed to connect
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_DEBUG,PSTR("failed to connect to device %d"), rc); AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: failed to connect to device %d"), rc);
#endif #endif
} }
op->state = newstate; op->state = newstate;
@ -1979,7 +1979,7 @@ static void BLETaskRunTaskDoneOperation(BLE_ESP32::generic_sensor_t** op, NimBLE
try { try {
if ((*ppClient)->isConnected()){ if ((*ppClient)->isConnected()){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("runTaskDoneOperation: disconnecting connected client")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: runTaskDoneOperation: disconnecting connected client"));
#endif #endif
(*ppClient)->disconnect(); (*ppClient)->disconnect();
// wait for 1/2 second after disconnect // wait for 1/2 second after disconnect
@ -1990,7 +1990,7 @@ static void BLETaskRunTaskDoneOperation(BLE_ESP32::generic_sensor_t** op, NimBLE
//(*ppClient)->disconnect(); //(*ppClient)->disconnect();
// we will stall here forever!!! - as testing // we will stall here forever!!! - as testing
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE wait discon%d"), waits); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: wait discon%d"), waits);
#endif #endif
vTaskDelay(500/ portTICK_PERIOD_MS); vTaskDelay(500/ portTICK_PERIOD_MS);
} }
@ -1999,11 +1999,11 @@ static void BLETaskRunTaskDoneOperation(BLE_ESP32::generic_sensor_t** op, NimBLE
int conn_id = (*ppClient)->getConnId(); int conn_id = (*ppClient)->getConnId();
ble_gap_conn_broken(conn_id, -1); ble_gap_conn_broken(conn_id, -1);
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE wait discon%d - kill connection"), waits); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: wait discon%d - kill connection"), waits);
#endif #endif
} }
if (waits == 60){ if (waits == 60){
AddLog_P(LOG_LEVEL_ERROR,PSTR(">60s waiting -> BLE Failed, restart Tasmota %d"), waits); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: >60s waiting -> BLE Failed, restart Tasmota %d"), waits);
BLEStop = 1; BLEStop = 1;
BLEStopAt = esp_timer_get_time(); BLEStopAt = esp_timer_get_time();
@ -2015,7 +2015,7 @@ static void BLETaskRunTaskDoneOperation(BLE_ESP32::generic_sensor_t** op, NimBLE
} }
} catch(const std::exception& e){ } catch(const std::exception& e){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("runTaskDoneOperation: exception in disconnect")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: runTaskDoneOperation: exception in disconnect"));
#endif #endif
} }
@ -2035,7 +2035,7 @@ static void BLETaskRunTaskDoneOperation(BLE_ESP32::generic_sensor_t** op, NimBLE
// by adding it to this list, this will cause it to be sent to MQTT // by adding it to this list, this will cause it to be sent to MQTT
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("runTaskDoneOperation: add to completedOperations")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: runTaskDoneOperation: add to completedOperations"));
#endif #endif
addOperation(&completedOperations, op); addOperation(&completedOperations, op);
return; return;
@ -2096,7 +2096,7 @@ static void BLEOperationTask(void *pvParameters){
BLERestartNimBLE = 0; BLERestartNimBLE = 0;
BLERestartTasmota = 10; BLERestartTasmota = 10;
BLERestartTasmotaReason = BLE_RESTART_TEAMOTA_REASON_RESTARTING_BLE_TIMEOUT; BLERestartTasmotaReason = BLE_RESTART_TEAMOTA_REASON_RESTARTING_BLE_TIMEOUT;
AddLog_P(LOG_LEVEL_ERROR,PSTR("BLETask: Restart NimBLE - restart Tasmota in 10 if not complt")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: BLETask: Restart NimBLE - restart Tasmota in 10 if not complt"));
BLE_ESP32::BLETaskStopStartNimBLE(&pClient); BLE_ESP32::BLETaskStopStartNimBLE(&pClient);
BLERestartTasmotaReason = BLE_RESTART_TEAMOTA_REASON_UNKNOWN; BLERestartTasmotaReason = BLE_RESTART_TEAMOTA_REASON_UNKNOWN;
BLERestartTasmota = 0; BLERestartTasmota = 0;
@ -2110,7 +2110,7 @@ static void BLEOperationTask(void *pvParameters){
vTaskDelay(100/ portTICK_PERIOD_MS); vTaskDelay(100/ portTICK_PERIOD_MS);
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLEOperationTask: Left task")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: BLEOperationTask: Left task"));
#endif #endif
deleteSeenDevices(); deleteSeenDevices();
@ -2192,11 +2192,11 @@ static void BLEEverySecond(bool restart){
if (!BLERestartTasmotaReason) BLERestartTasmotaReason = BLE_RESTART_TEAMOTA_REASON_UNKNOWN; if (!BLERestartTasmotaReason) BLERestartTasmotaReason = BLE_RESTART_TEAMOTA_REASON_UNKNOWN;
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"reboot\":\"%s\"}"), BLERestartTasmotaReason); snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"reboot\":\"%s\"}"), BLERestartTasmotaReason);
MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain); MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE Failure! Restarting Tasmota in %d seconds because %s"), BLERestartTasmota, BLERestartTasmotaReason); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Failure! Restarting Tasmota in %d seconds because %s"), BLERestartTasmota, BLERestartTasmotaReason);
} }
if (!BLERestartTasmota){ if (!BLERestartTasmota){
AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE Failure! Restarting Tasmota because %s"), BLERestartTasmotaReason); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Failure! Restarting Tasmota because %s"), BLERestartTasmotaReason);
// just a normal restart // just a normal restart
TasmotaGlobal.restart_flag = 1; TasmotaGlobal.restart_flag = 1;
} }
@ -2205,7 +2205,7 @@ static void BLEEverySecond(bool restart){
if (BLERestartBLEReason){ // just use the ptr as the trigger to send MQTT if (BLERestartBLEReason){ // just use the ptr as the trigger to send MQTT
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"blerestart\":\"%s\"}"), BLERestartBLEReason); snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"blerestart\":\"%s\"}"), BLERestartBLEReason);
MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain); MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE Failure! Restarting BLE Stack because %s"), BLERestartBLEReason); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Failure! Restarting BLE Stack because %s"), BLERestartBLEReason);
BLERestartBLEReason = nullptr; BLERestartBLEReason = nullptr;
} }
@ -2250,9 +2250,9 @@ int addOperation(std::deque<generic_sensor_t*> *ops, generic_sensor_t** op){
} }
} }
if (res){ if (res){
//AddLog_P(LOG_LEVEL_DEBUG,PSTR("added operation")); //AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: added operation"));
} else { } else {
AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE op - no room")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: op - no room"));
} }
return res; return res;
} }
@ -2260,7 +2260,7 @@ int addOperation(std::deque<generic_sensor_t*> *ops, generic_sensor_t** op){
int newOperation(BLE_ESP32::generic_sensor_t** op){ int newOperation(BLE_ESP32::generic_sensor_t** op){
if (!op) { if (!op) {
AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE op inv in newOperation")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: op inv in newOperation"));
return 0; return 0;
} }
@ -2307,7 +2307,7 @@ int extQueueOperation(BLE_ESP32::generic_sensor_t** op){
int res = addOperation(&queuedOperations, op); int res = addOperation(&queuedOperations, op);
if (!res){ if (!res){
AddLog_P(LOG_LEVEL_ERROR,PSTR("extQueueOperation: op added id %d failed"), (lastopid-1)); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: extQueueOperation: op added id %d failed"), (lastopid-1));
} }
return res; return res;
} }
@ -2427,7 +2427,7 @@ static int StartBLE(void) {
BLE_ESP32::BLEStartOperationTask(); BLE_ESP32::BLEStartOperationTask();
return 1; return 1;
} }
AddLog_P(LOG_LEVEL_ERROR,PSTR("StartBLE - wait as BLEStop==1")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: StartBLE - wait as BLEStop==1"));
return 0; return 0;
} }
@ -2436,16 +2436,16 @@ static int StopBLE(void){
if (BLERunning){ if (BLERunning){
if (BLEStop != 1){ if (BLEStop != 1){
BLEStop = 1; BLEStop = 1;
AddLog_P(LOG_LEVEL_INFO,PSTR("StopBLE - BLEStop->1")); AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: StopBLE - BLEStop->1"));
BLEStopAt = esp_timer_get_time(); BLEStopAt = esp_timer_get_time();
// give a little time for it to stop. // give a little time for it to stop.
vTaskDelay(1000/ portTICK_PERIOD_MS); vTaskDelay(1000/ portTICK_PERIOD_MS);
return 1; return 1;
} }
AddLog_P(LOG_LEVEL_ERROR,PSTR("StopBLE - wait as BLEStop==1")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: StopBLE - wait as BLEStop==1"));
return 0; return 0;
} else { } else {
AddLog_P(LOG_LEVEL_ERROR,PSTR("StopBLE - was not running")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: StopBLE - was not running"));
return 1; return 1;
} }
} }
@ -2686,7 +2686,7 @@ void CmndBLEDetails(void){
void CmndBLEAlias(void){ void CmndBLEAlias(void){
#ifdef BLE_ESP32_ALIASES #ifdef BLE_ESP32_ALIASES
int op = XdrvMailbox.index; int op = XdrvMailbox.index;
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("Alias %d %s"), op, XdrvMailbox.data); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: Alias %d %s"), op, XdrvMailbox.data);
int res = -1; int res = -1;
switch(op){ switch(op){
@ -2705,7 +2705,7 @@ void CmndBLEAlias(void){
char *mac = p; char *mac = p;
int len = fromHex(addr, p, sizeof(addr)); int len = fromHex(addr, p, sizeof(addr));
if (len != 6){ if (len != 6){
AddLog_P(LOG_LEVEL_ERROR,PSTR("Alias invalid mac %s"), p); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Alias invalid mac %s"), p);
ResponseCmndChar("invalidmac"); ResponseCmndChar("invalidmac");
return; return;
} }
@ -2726,7 +2726,7 @@ void CmndBLEAlias(void){
return; return;
} }
AddLog_P(LOG_LEVEL_ERROR,PSTR("Add Alias mac %s = name %s"), mac, p); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Add Alias mac %s = name %s"), mac, p);
if (addAlias( addr, name )){ if (addAlias( addr, name )){
added++; added++;
} }
@ -2734,7 +2734,7 @@ void CmndBLEAlias(void){
} while (p); } while (p);
if (added){ if (added){
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("Added %d Aliases"), added); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: Added %d Aliases"), added);
BLEAliasListResp(); BLEAliasListResp();
} else { } else {
BLEAliasListResp(); BLEAliasListResp();
@ -2742,7 +2742,7 @@ void CmndBLEAlias(void){
return; return;
} break; } break;
case 2:{ // clear case 2:{ // clear
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLEAlias clearing %d"), aliases.size()); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: Alias clearing %d"), aliases.size());
for (int i = aliases.size()-1; i >= 0; i--){ for (int i = aliases.size()-1; i >= 0; i--){
BLE_ESP32::ble_alias_t *alias = aliases[i]; BLE_ESP32::ble_alias_t *alias = aliases[i];
aliases.pop_back(); aliases.pop_back();
@ -2773,14 +2773,14 @@ void CmndBLEName(void) {
if (addrres){ if (addrres){
if (addrres == 2){ if (addrres == 2){
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE addr used alias: %s"), p); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: addr used alias: %s"), p);
} }
//#ifdef EQ3_DEBUG //#ifdef EQ3_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("BLE cmd addr: %s -> %s"), p, addr.toString().c_str()); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: cmd addr: %s -> %s"), p, addr.toString().c_str());
//#endif //#endif
} else { } else {
AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE addr invalid: %s"), p); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: addr invalid: %s"), p);
ResponseCmndIdxChar(PSTR("invalidaddr")); ResponseCmndIdxChar(PSTR("invalidaddr"));
return; return;
} }
@ -2789,11 +2789,11 @@ void CmndBLEName(void) {
// ALWAYS use this function to create a new one. // ALWAYS use this function to create a new one.
int res = BLE_ESP32::newOperation(&op); int res = BLE_ESP32::newOperation(&op);
if (!res){ if (!res){
AddLog_P(LOG_LEVEL_ERROR,PSTR("Can't get a newOperation")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Can't get a newOperation"));
ResponseCmndChar(PSTR("FAIL")); ResponseCmndChar(PSTR("FAIL"));
return; return;
} else { } else {
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("got a newOperation from BLE")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: got a newOperation from BLE"));
} }
op->addr = addr; op->addr = addr;
@ -2804,21 +2804,21 @@ void CmndBLEName(void) {
char *name = strtok(nullptr, " "); char *name = strtok(nullptr, " ");
bool write = false; bool write = false;
if (name && *name){ if (name && *name){
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("write name %s"), name); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: write name %s"), name);
op->writelen = strlen(name); op->writelen = strlen(name);
memcpy(op->dataToWrite, name, op->writelen); memcpy(op->dataToWrite, name, op->writelen);
write = true; write = true;
} else { } else {
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("read name")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: read name"));
op->readlen = 1; op->readlen = 1;
} }
res = BLE_ESP32::extQueueOperation(&op); res = BLE_ESP32::extQueueOperation(&op);
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("queue res %d"), res); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: queue res %d"), res);
if (!res){ if (!res){
// if it fails to add to the queue, do please delete it // if it fails to add to the queue, do please delete it
BLE_ESP32::freeOperation(&op); BLE_ESP32::freeOperation(&op);
AddLog_P(LOG_LEVEL_ERROR,PSTR("Failed to queue new operation - deleted")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Failed to queue new operation - deleted"));
ResponseCmndChar(PSTR("QUEUEFAIL")); ResponseCmndChar(PSTR("QUEUEFAIL"));
return; return;
} }
@ -2856,7 +2856,7 @@ void CmndBLEOperation(void){
int op = XdrvMailbox.index; int op = XdrvMailbox.index;
//AddLog_P(LOG_LEVEL_INFO,PSTR("op %d"), op); //AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: op %d"), op);
int res = -1; int res = -1;
@ -2864,7 +2864,7 @@ void CmndBLEOperation(void){
switch(op) { switch(op) {
case 0: case 0:
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("preview")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: preview"));
#endif #endif
BLEPostMQTTTrigger = 1; BLEPostMQTTTrigger = 1;
break; break;
@ -2875,7 +2875,7 @@ void CmndBLEOperation(void){
int opres = BLE_ESP32::newOperation(&prepOperation); int opres = BLE_ESP32::newOperation(&prepOperation);
if (!opres){ if (!opres){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("Could not create new operation")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Could not create new operation"));
#endif #endif
ResponseCmndChar("FailCreate"); ResponseCmndChar("FailCreate");
return; return;
@ -2933,14 +2933,14 @@ void CmndBLEOperation(void){
// this means you could retry with another BLEOp10. // this means you could retry with another BLEOp10.
// it WOULD be deleted if you sent another BELOP1 <MAC> // it WOULD be deleted if you sent another BELOP1 <MAC>
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("Could not queue new operation")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Could not queue new operation"));
#endif #endif
ResponseCmndChar("FailQueue"); ResponseCmndChar("FailQueue");
return; return;
} else { } else {
// NOTE: prepOperation has been set to null if we queued sucessfully. // NOTE: prepOperation has been set to null if we queued sucessfully.
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("Operations queued:%d"), queuedOperations.size()); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: Operations queued:%d"), queuedOperations.size());
#endif #endif
char temp[40]; char temp[40];
sprintf(temp, "{\"opid\":%d,\"u\":%d}", lastopid-1, u); sprintf(temp, "{\"opid\":%d,\"u\":%d}", lastopid-1, u);
@ -2969,13 +2969,13 @@ void CmndBLEOperation(void){
// this means you could retry with another BLEOp10. // this means you could retry with another BLEOp10.
// it WOULD be deleted if you sent another BELOP1 <MAC> // it WOULD be deleted if you sent another BELOP1 <MAC>
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("Could not queue new operation")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Could not queue new operation"));
#endif #endif
ResponseCmndChar("FailQueue"); ResponseCmndChar("FailQueue");
} else { } else {
// NOTE: prepOperation has been set to null if we queued sucessfully. // NOTE: prepOperation has been set to null if we queued sucessfully.
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("Operations queued:%d"), queuedOperations.size()); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: Operations queued:%d"), queuedOperations.size());
#endif #endif
char temp[40]; char temp[40];
sprintf(temp, "{\"opid\":%d,\"u\":%d}", lastopid-1, u); sprintf(temp, "{\"opid\":%d,\"u\":%d}", lastopid-1, u);
@ -3026,20 +3026,20 @@ static void BLEPostMQTT(bool onlycompleted) {
if (prepOperation || completedOperations.size() || queuedOperations.size() || currentOperations.size()){ if (prepOperation || completedOperations.size() || queuedOperations.size() || currentOperations.size()){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("some to show")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: some to show"));
#endif #endif
if (prepOperation && !onlycompleted){ if (prepOperation && !onlycompleted){
std::string out = BLETriggerResponse(prepOperation); std::string out = BLETriggerResponse(prepOperation);
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("%s"), out.c_str()); snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("%s"), out.c_str());
MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain); MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("prep sent %s"), out.c_str()); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: prep sent %s"), out.c_str());
#endif #endif
} }
if (queuedOperations.size() && !onlycompleted){ if (queuedOperations.size() && !onlycompleted){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("queued %d"), queuedOperations.size()); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: queued %d"), queuedOperations.size());
#endif #endif
for (int i = 0; i < queuedOperations.size(); i++){ for (int i = 0; i < queuedOperations.size(); i++){
TasAutoMutex localmutex(&BLEOperationsRecursiveMutex, "BLEPost1"); TasAutoMutex localmutex(&BLEOperationsRecursiveMutex, "BLEPost1");
@ -3053,7 +3053,7 @@ static void BLEPostMQTT(bool onlycompleted) {
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("%s"), out.c_str()); snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("%s"), out.c_str());
MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain); MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("queued %d sent %s"), i, out.c_str()); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: queued %d sent %s"), i, out.c_str());
#endif #endif
//break; //break;
} }
@ -3062,7 +3062,7 @@ static void BLEPostMQTT(bool onlycompleted) {
if (currentOperations.size() && !onlycompleted){ if (currentOperations.size() && !onlycompleted){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("current %d"), currentOperations.size()); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: current %d"), currentOperations.size());
#endif #endif
for (int i = 0; i < currentOperations.size(); i++){ for (int i = 0; i < currentOperations.size(); i++){
TasAutoMutex localmutex(&BLEOperationsRecursiveMutex, "BLEPost2"); TasAutoMutex localmutex(&BLEOperationsRecursiveMutex, "BLEPost2");
@ -3075,7 +3075,7 @@ static void BLEPostMQTT(bool onlycompleted) {
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("%s"), out.c_str()); snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("%s"), out.c_str());
MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain); MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("curr %d sent %s"), i, out.c_str()); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: curr %d sent %s"), i, out.c_str());
#endif #endif
//break; //break;
} }
@ -3084,7 +3084,7 @@ static void BLEPostMQTT(bool onlycompleted) {
if (completedOperations.size()){ if (completedOperations.size()){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("completed %d"), completedOperations.size()); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: completed %d"), completedOperations.size());
#endif #endif
do { do {
generic_sensor_t *toSend = nextOperation(&completedOperations); generic_sensor_t *toSend = nextOperation(&completedOperations);
@ -3154,7 +3154,7 @@ static void mainThreadBLETimeouts() {
static void mainThreadOpCallbacks() { static void mainThreadOpCallbacks() {
if (completedOperations.size()){ if (completedOperations.size()){
//AddLog_P(LOG_LEVEL_INFO,PSTR("completed %d"), completedOperations.size()); //AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: completed %d"), completedOperations.size());
TasAutoMutex localmutex(&BLEOperationsRecursiveMutex, "BLEMainCB"); TasAutoMutex localmutex(&BLEOperationsRecursiveMutex, "BLEMainCB");
// find this operation in currentOperations, and remove it. // find this operation in currentOperations, and remove it.
@ -3169,11 +3169,11 @@ static void mainThreadOpCallbacks() {
OPCOMPLETE_CALLBACK *pFn = (OPCOMPLETE_CALLBACK *)(op->completecallback); OPCOMPLETE_CALLBACK *pFn = (OPCOMPLETE_CALLBACK *)(op->completecallback);
callbackres = pFn(op); callbackres = pFn(op);
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("op->completecallback %d"), callbackres); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: op->completecallback %d"), callbackres);
#endif #endif
} catch(const std::exception& e){ } catch(const std::exception& e){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("exception in op->completecallback")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: exception in op->completecallback"));
#endif #endif
} }
} }
@ -3184,14 +3184,14 @@ static void mainThreadOpCallbacks() {
OPCOMPLETE_CALLBACK *pFn = operationsCallbacks[i]; OPCOMPLETE_CALLBACK *pFn = operationsCallbacks[i];
callbackres = pFn(op); callbackres = pFn(op);
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("operationsCallbacks %d %d"), i, callbackres); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: operationsCallbacks %d %d"), i, callbackres);
#endif #endif
if (callbackres){ if (callbackres){
break; // this callback ate the op. break; // this callback ate the op.
} }
} catch(const std::exception& e){ } catch(const std::exception& e){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_ERROR,PSTR("exception in operationsCallbacks")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: exception in operationsCallbacks"));
#endif #endif
} }
} }
@ -3200,7 +3200,7 @@ static void mainThreadOpCallbacks() {
// if some callback told us not to send on MQTT, then remove from completed and delete the data // if some callback told us not to send on MQTT, then remove from completed and delete the data
if (callbackres){ if (callbackres){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("callbackres true -> delete op")); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("BLE: callbackres true -> delete op"));
#endif #endif
completedOperations.erase(completedOperations.begin() + i); completedOperations.erase(completedOperations.begin() + i);
delete op; delete op;
@ -3214,7 +3214,7 @@ static void BLEShow(bool json)
{ {
if (json){ if (json){
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("show json %d"),json); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: show json %d"),json);
#endif #endif
uint32_t totalCount = BLEAdvertisment.totalCount; uint32_t totalCount = BLEAdvertisment.totalCount;
uint32_t deviceCount = seenDevices.size(); uint32_t deviceCount = seenDevices.size();
@ -3372,12 +3372,12 @@ void HandleBleConfiguration(void)
{ {
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_DEBUG, PSTR("HandleBleConfiguration")); AddLog_P(LOG_LEVEL_DEBUG, PSTR("BLE: HandleBleConfiguration"));
#endif #endif
if (!HttpCheckPriviledgedAccess()) { if (!HttpCheckPriviledgedAccess()) {
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_DEBUG, PSTR("!HttpCheckPriviledgedAccess()")); AddLog_P(LOG_LEVEL_DEBUG, PSTR("BLE: !HttpCheckPriviledgedAccess()"));
#endif #endif
return; return;
} }
@ -3390,12 +3390,12 @@ void HandleBleConfiguration(void)
WebGetArg("en", tmp, sizeof(tmp)); WebGetArg("en", tmp, sizeof(tmp));
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("arg en is %s"), tmp); if (BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("BLE: arg en is %s"), tmp);
#endif #endif
if (Webserver->hasArg("save")) { if (Webserver->hasArg("save")) {
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_DEBUG, PSTR("BLE SETTINGS SAVE")); AddLog_P(LOG_LEVEL_DEBUG, PSTR("BLE: SETTINGS SAVE"));
#endif #endif
Settings.flag5.mi32_enable = Webserver->hasArg("e0"); // Settings.flag5.mi32_enable = Webserver->hasArg("e0"); //
BLEScanActiveMode = (Webserver->hasArg("e1")?1:0); // BLEScanActiveMode = (Webserver->hasArg("e1")?1:0); //
@ -3405,7 +3405,7 @@ void HandleBleConfiguration(void)
return; return;
} }
#ifdef BLE_ESP32_DEBUG #ifdef BLE_ESP32_DEBUG
AddLog_P(LOG_LEVEL_DEBUG, PSTR("!SAVE")); AddLog_P(LOG_LEVEL_DEBUG, PSTR("BLE: !SAVE"));
#endif #endif
char str[TOPSZ]; char str[TOPSZ];
@ -3460,7 +3460,7 @@ void HandleBleConfiguration(void)
\*********************************************************************************************/ \*********************************************************************************************/
int ExtStopBLE(){ int ExtStopBLE(){
AddLog_P(LOG_LEVEL_INFO, PSTR("Stopping BLE if active - upgrade starting?")); AddLog_P(LOG_LEVEL_INFO, PSTR("BLE: Stopping if active"));
BLE_ESP32::BLEMode = BLE_ESP32::BLEModeDisabled; BLE_ESP32::BLEMode = BLE_ESP32::BLEModeDisabled;
BLE_ESP32::StopBLE(); BLE_ESP32::StopBLE();
return 0; return 0;
@ -3548,13 +3548,13 @@ int myAdvertCallback(BLE_ESP32::ble_advertisment_t *pStruct) {
// this one is used to demonstrate processing ALL operations // this one is used to demonstrate processing ALL operations
int myOpCallback(BLE_ESP32::generic_sensor_t *pStruct){ int myOpCallback(BLE_ESP32::generic_sensor_t *pStruct){
AddLog_P(LOG_LEVEL_INFO,PSTR("myOpCallback")); AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: myOpCallback"));
return 0; // return true to block MQTT broadcast return 0; // return true to block MQTT broadcast
} }
// this one is used to demonstrate processing of ONE specific operation // this one is used to demonstrate processing of ONE specific operation
int myOpCallback2(BLE_ESP32::generic_sensor_t *pStruct){ int myOpCallback2(BLE_ESP32::generic_sensor_t *pStruct){
AddLog_P(LOG_LEVEL_INFO,PSTR("myOpCallback2")); AddLog_P(LOG_LEVEL_INFO,PSTR("BLE: myOpCallback2"));
return 1; // return true to block MQTT broadcast return 1; // return true to block MQTT broadcast
} }
#endif #endif
@ -3577,7 +3577,7 @@ void sendExample(){
BLE_ESP32::generic_sensor_t *op = nullptr; BLE_ESP32::generic_sensor_t *op = nullptr;
int res = BLE_ESP32::newOperation(&op); int res = BLE_ESP32::newOperation(&op);
if (!res){ if (!res){
AddLog_P(LOG_LEVEL_ERROR,PSTR("Could not create new operation")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Could not create new operation"));
return; return;
} }
strncpy(op->MAC, "001A22092EE0", sizeof(op->MAC)); strncpy(op->MAC, "001A22092EE0", sizeof(op->MAC));
@ -3592,7 +3592,7 @@ void sendExample(){
if (!res){ if (!res){
// if it fails to add to the queue, do please delete it // if it fails to add to the queue, do please delete it
BLE_ESP32::freeOperation(&op); BLE_ESP32::freeOperation(&op);
AddLog_P(LOG_LEVEL_ERROR,PSTR("Failed to queue new operation - deleted")); AddLog_P(LOG_LEVEL_ERROR,PSTR("BLE: Failed to queue new operation - deleted"));
return; return;
} }

View File

@ -241,7 +241,7 @@ bool HxCommand(void)
break; break;
case 7: // WeightSave case 7: // WeightSave
Settings.energy_frequency_calibration = Hx.weight; Settings.energy_frequency_calibration = Hx.weight;
Response_P(S_JSON_SENSOR_INDEX_SVALUE, XSNS_34, D_JSON_DONE); Response_P(S_JSON_SENSOR_INDEX_SVALUE, XSNS_34, PSTR(D_JSON_DONE));
break; break;
case 8: // Json on weight change case 8: // Json on weight change
if (strchr(XdrvMailbox.data, ',') != nullptr) { if (strchr(XdrvMailbox.data, ',') != nullptr) {

View File

@ -490,7 +490,7 @@ int toggleUnit(BLE_ESP32::generic_sensor_t *op){
bool MI32Operation(int slot, int optype, const char *svc, const char *charactistic, const char *notifychar = nullptr, const uint8_t *data = nullptr, int datalen = 0, uint8_t *addr = nullptr ) { bool MI32Operation(int slot, int optype, const char *svc, const char *charactistic, const char *notifychar = nullptr, const uint8_t *data = nullptr, int datalen = 0, uint8_t *addr = nullptr ) {
if (!svc || !svc[0]){ if (!svc || !svc[0]){
AddLog_P(LOG_LEVEL_ERROR,PSTR("MI32Op: inv svc")); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: Op inv svc"));
return 0; return 0;
} }
@ -499,17 +499,17 @@ bool MI32Operation(int slot, int optype, const char *svc, const char *charactist
// ALWAYS use this function to create a new one. // ALWAYS use this function to create a new one.
int res = BLE_ESP32::newOperation(&op); int res = BLE_ESP32::newOperation(&op);
if (!res){ if (!res){
AddLog_P(LOG_LEVEL_ERROR,PSTR("Can't get a newOperation from BLE")); AddLog_P(LOG_LEVEL_ERROR,PSTR("M32: Can't get a newOperation"));
return 0; return 0;
} else { } else {
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("got a newOperation from BLE")); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: Got a newOperation"));
} }
if (slot >= 0){ if (slot >= 0){
op->addr = NimBLEAddress(MIBLEsensors[slot].MAC); op->addr = NimBLEAddress(MIBLEsensors[slot].MAC);
} else { } else {
if (!addr){ if (!addr){
AddLog_P(LOG_LEVEL_ERROR,PSTR("no addr")); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: No addr"));
BLE_ESP32::freeOperation(&op); BLE_ESP32::freeOperation(&op);
return 0; return 0;
} }
@ -521,7 +521,7 @@ bool MI32Operation(int slot, int optype, const char *svc, const char *charactist
if (!op->serviceUUID.bitSize()){ if (!op->serviceUUID.bitSize()){
BLE_ESP32::freeOperation(&op); BLE_ESP32::freeOperation(&op);
AddLog_P(LOG_LEVEL_ERROR,PSTR("MI: Bad service string %s"), svc); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: MI Bad service string %s"), svc);
return 0; return 0;
} }
@ -531,7 +531,7 @@ bool MI32Operation(int slot, int optype, const char *svc, const char *charactist
op->characteristicUUID = NimBLEUUID(charactistic); op->characteristicUUID = NimBLEUUID(charactistic);
if (!op->characteristicUUID.bitSize()){ if (!op->characteristicUUID.bitSize()){
BLE_ESP32::freeOperation(&op); BLE_ESP32::freeOperation(&op);
AddLog_P(LOG_LEVEL_ERROR,PSTR("MI: Bad characteristic string %s"), charactistic); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: MI Bad characteristic string %s"), charactistic);
return 0; return 0;
} }
} }
@ -539,7 +539,7 @@ bool MI32Operation(int slot, int optype, const char *svc, const char *charactist
op->notificationCharacteristicUUID = NimBLEUUID(notifychar); op->notificationCharacteristicUUID = NimBLEUUID(notifychar);
if (!op->notificationCharacteristicUUID.bitSize()){ if (!op->notificationCharacteristicUUID.bitSize()){
BLE_ESP32::freeOperation(&op); BLE_ESP32::freeOperation(&op);
AddLog_P(LOG_LEVEL_ERROR,PSTR("MI: Bad notifycharacteristic string %s"), notifychar); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: MI Bad notifycharacteristic string %s"), notifychar);
return 0; return 0;
} }
} }
@ -564,13 +564,13 @@ bool MI32Operation(int slot, int optype, const char *svc, const char *charactist
uint32_t context = (optype << 24) | (MIBLEsensors[slot].type << 16) | slot; uint32_t context = (optype << 24) | (MIBLEsensors[slot].type << 16) | slot;
op->context = (void *)context; op->context = (void *)context;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI s:%d op:%s"), slot, BLE_ESP32::BLETriggerResponse(op).c_str()); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: MI s:%d op:%s"), slot, BLE_ESP32::BLETriggerResponse(op).c_str());
res = BLE_ESP32::extQueueOperation(&op); res = BLE_ESP32::extQueueOperation(&op);
if (!res){ if (!res){
// if it fails to add to the queue, do please delete it // if it fails to add to the queue, do please delete it
BLE_ESP32::freeOperation(&op); BLE_ESP32::freeOperation(&op);
AddLog_P(LOG_LEVEL_ERROR,PSTR("Failed to queue new operation - deleted")); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: Failed to queue new operation - deleted"));
} }
return res; return res;
@ -611,9 +611,9 @@ int genericBatReadFn(int slot){
break; break;
} }
if (res > 0){ if (res > 0){
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("Req batt read slot %d type %d queued"), slot, MIBLEsensors[slot].type); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO, PSTR("M32: Req batt read slot %d type %d queued"), slot, MIBLEsensors[slot].type);
} else { } else {
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("Req batt read slot %d type %d non-queued res %d"), slot, MIBLEsensors[slot].type, res); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO, PSTR("M32: Req batt read slot %d type %d non-queued res %d"), slot, MIBLEsensors[slot].type, res);
} }
return res; return res;
} }
@ -653,7 +653,7 @@ int genericSensorReadFn(int slot, int force){
// called once per second // called once per second
int readOneSensor(){ int readOneSensor(){
if (MI32.sensorreader.active){ if (MI32.sensorreader.active){
AddLog_P(LOG_LEVEL_DEBUG,PSTR("readOneSensor - already active reading %d"), MI32.sensorreader.slot-1); AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: readOneSensor - already active reading %d"), MI32.sensorreader.slot-1);
return 0; return 0;
} }
@ -663,12 +663,12 @@ int readOneSensor(){
do { do {
// MI32.sensorreader.slot is reset to zero to trigger a read sequence // MI32.sensorreader.slot is reset to zero to trigger a read sequence
if (MI32.sensorreader.slot >= MIBLEsensors.size()){ if (MI32.sensorreader.slot >= MIBLEsensors.size()){
//AddLog_P(LOG_LEVEL_DEBUG,PSTR("readOneSensor past end of slots - %d > %d"), MI32.sensorreader.slot, MIBLEsensors.size()); //AddLog_P(LOG_LEVEL_DEBUG, PSTR("BLE: readOneSensor past end of slots - %d > %d"), MI32.sensorreader.slot, MIBLEsensors.size());
return 0; return 0;
} }
res = genericSensorReadFn(MI32.sensorreader.slot, 0); res = genericSensorReadFn(MI32.sensorreader.slot, 0);
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("genericSensorReadFn slot %d res %d"), MI32.sensorreader.slot, res); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: genericSensorReadFn slot %d res %d"), MI32.sensorreader.slot, res);
// if this sensor in this slot does not need to be read via notify, just move on top the next one // if this sensor in this slot does not need to be read via notify, just move on top the next one
if (res < 0){ if (res < 0){
@ -680,7 +680,7 @@ int readOneSensor(){
if (res == 0){ if (res == 0){
// can't read at the moment (no operations available?) // can't read at the moment (no operations available?)
AddLog_P(LOG_LEVEL_DEBUG,PSTR("readOneSensor no ops available slot %d res %d"), MI32.sensorreader.slot, res); AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: readOneSensor no ops available slot %d res %d"), MI32.sensorreader.slot, res);
return 0; return 0;
} }
@ -689,7 +689,7 @@ int readOneSensor(){
// and make it wait until the read/notify is complete // and make it wait until the read/notify is complete
// this is cleared in the response callback. // this is cleared in the response callback.
MI32.sensorreader.active = 1; MI32.sensorreader.active = 1;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("readOneSensor reading for slot %d res %d"), MI32.sensorreader.slot-1, res); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: readOneSensor reading for slot %d res %d"), MI32.sensorreader.slot-1, res);
// started one // started one
return 1; return 1;
@ -714,7 +714,7 @@ int readOneBat(){
if (res < 0){ if (res < 0){
MI32.batteryreader.slot++; MI32.batteryreader.slot++;
if (MI32.batteryreader.slot >= MIBLEsensors.size()){ if (MI32.batteryreader.slot >= MIBLEsensors.size()){
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("Batt loop complete at %d"), MI32.batteryreader.slot); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO, PSTR("M32: Batt loop complete at %d"), MI32.batteryreader.slot);
} }
return 0; return 0;
} }
@ -730,7 +730,7 @@ int readOneBat(){
// this is cleared in the response callback. // this is cleared in the response callback.
MI32.batteryreader.active = 1; MI32.batteryreader.active = 1;
if (MI32.batteryreader.slot >= MIBLEsensors.size()){ if (MI32.batteryreader.slot >= MIBLEsensors.size()){
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO,PSTR("Batt loop will complete at %d"), MI32.batteryreader.slot); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_INFO, PSTR("M32: Batt loop will complete at %d"), MI32.batteryreader.slot);
} }
// started one // started one
return 1; return 1;
@ -816,7 +816,7 @@ int genericTimeWriteFn(int slot){
int genericOpCompleteFn(BLE_ESP32::generic_sensor_t *op){ int genericOpCompleteFn(BLE_ESP32::generic_sensor_t *op){
uint32_t context = (uint32_t) op->context; uint32_t context = (uint32_t) op->context;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI op complete context %x"), context); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: MI op complete context %x"), context);
int opType = context >> 24; int opType = context >> 24;
int devType = (context >> 16) & 0xff; int devType = (context >> 16) & 0xff;
@ -832,12 +832,12 @@ int genericOpCompleteFn(BLE_ESP32::generic_sensor_t *op){
bool fail = false; bool fail = false;
if (op->addr != addr){ if (op->addr != addr){
// slot changed during operation? // slot changed during operation?
AddLog_P(LOG_LEVEL_ERROR,PSTR("Slot mac changed during an operation")); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: Slot mac changed during an operation"));
fail = true; fail = true;
} }
if (op->state <= GEN_STATE_FAILED){ if (op->state <= GEN_STATE_FAILED){
AddLog_P(LOG_LEVEL_ERROR,PSTR("operation failed %d for %s"), op->state, slotMAC); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: Operation failed %d for %s"), op->state, slotMAC);
fail = true; fail = true;
} }
@ -857,7 +857,7 @@ int genericOpCompleteFn(BLE_ESP32::generic_sensor_t *op){
switch(opType){ switch(opType){
case OP_TIME_WRITE: case OP_TIME_WRITE:
AddLog_P(LOG_LEVEL_DEBUG,PSTR("Time write for %s complete"), slotMAC); AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: Time write for %s complete"), slotMAC);
return 0; // nothing to do return 0; // nothing to do
case OP_BATT_READ:{ case OP_BATT_READ:{
uint8_t *data = nullptr; uint8_t *data = nullptr;
@ -876,33 +876,33 @@ int genericOpCompleteFn(BLE_ESP32::generic_sensor_t *op){
// allow another... // allow another...
MI32.batteryreader.active = 0; MI32.batteryreader.active = 0;
AddLog_P(LOG_LEVEL_INFO,PSTR("batt read slot %d done state %x"), slot, op->state); AddLog_P(LOG_LEVEL_INFO, PSTR("M32: Batt read slot %d done state %x"), slot, op->state);
} return 0; } return 0;
case OP_UNIT_WRITE: // nothing more to do? case OP_UNIT_WRITE: // nothing more to do?
AddLog_P(LOG_LEVEL_DEBUG,PSTR("Unit write for %s complete"), slotMAC); AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: Unit write for %s complete"), slotMAC);
return 0; return 0;
case OP_UNIT_READ: { case OP_UNIT_READ: {
uint8_t currUnit = op->dataRead[0]; uint8_t currUnit = op->dataRead[0];
AddLog_P(LOG_LEVEL_DEBUG,PSTR("Unit read for %s complete %d"), slotMAC, currUnit); AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: Unit read for %s complete %d"), slotMAC, currUnit);
} return 0; } return 0;
case OP_UNIT_TOGGLE: { case OP_UNIT_TOGGLE: {
uint8_t currUnit = op->dataToWrite[0]; uint8_t currUnit = op->dataToWrite[0];
AddLog_P(LOG_LEVEL_DEBUG,PSTR("Unit toggle for %s complete %d->%d; datasize was %d"), slotMAC, op->dataRead[0], op->dataToWrite[0], op->readlen); AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: Unit toggle for %s complete %d->%d; datasize was %d"), slotMAC, op->dataRead[0], op->dataToWrite[0], op->readlen);
} return 0; } return 0;
case OP_READ_HT_LY: { case OP_READ_HT_LY: {
// allow another... // allow another...
MI32.sensorreader.active = 0; MI32.sensorreader.active = 0;
MI32notifyHT_LY(slot, (char*)op->dataNotify, op->notifylen); MI32notifyHT_LY(slot, (char*)op->dataNotify, op->notifylen);
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("HT_LY notify for %s complete"), slotMAC); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: HT_LY notify for %s complete"), slotMAC);
} return 0; } return 0;
default: default:
AddLog_P(LOG_LEVEL_ERROR,PSTR("OpType %d not recognised?"), opType); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: OpType %d not recognised?"), opType);
return 0; return 0;
} }
@ -914,7 +914,7 @@ int MI32advertismentCallback(BLE_ESP32::ble_advertisment_t *pStruct)
// we will try not to use this... // we will try not to use this...
BLEAdvertisedDevice *advertisedDevice = pStruct->advertisedDevice; BLEAdvertisedDevice *advertisedDevice = pStruct->advertisedDevice;
// AddLog_P(LOG_LEVEL_DEBUG,PSTR("Advertised Device: %s Buffer: %u"),advertisedDevice->getAddress().toString().c_str(),advertisedDevice->getServiceData(0).length()); // AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: Advertised Device: %s Buffer: %u"),advertisedDevice->getAddress().toString().c_str(),advertisedDevice->getServiceData(0).length());
int RSSI = pStruct->RSSI; int RSSI = pStruct->RSSI;
const uint8_t *addr = pStruct->addr; const uint8_t *addr = pStruct->addr;
if(MI32isInBlockList(addr) == true) return 0; if(MI32isInBlockList(addr) == true) return 0;
@ -937,13 +937,13 @@ int MI32advertismentCallback(BLE_ESP32::ble_advertisment_t *pStruct)
char temp[60]; char temp[60];
BLE_ESP32::dump(temp, 13, addr, 6); BLE_ESP32::dump(temp, 13, addr, 6);
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("MI:%s svc[0] UUID (%x)"), temp, UUID); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("M32: MI:%s svc[0] UUID (%x)"), temp, UUID);
std::string ServiceDataStr = advertisedDevice->getServiceData(0); std::string ServiceDataStr = advertisedDevice->getServiceData(0);
uint32_t ServiceDataLength = ServiceDataStr.length(); uint32_t ServiceDataLength = ServiceDataStr.length();
const uint8_t *ServiceData = (const uint8_t *)ServiceDataStr.data(); const uint8_t *ServiceData = (const uint8_t *)ServiceDataStr.data();
BLE_ESP32::dump(temp, 60, ServiceData, ServiceDataLength); BLE_ESP32::dump(temp, 60, ServiceData, ServiceDataLength);
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("MI:%s"), temp); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("M32: MI:%s"), temp);
if (UUID){ if (UUID){
@ -1041,14 +1041,14 @@ int MI32AddKey(char* payload, char* key = nullptr){
bool unknownKey = true; bool unknownKey = true;
for(uint32_t i=0; i<MIBLEbindKeys.size(); i++){ for(uint32_t i=0; i<MIBLEbindKeys.size(); i++){
if(memcmp(keyMAC.MAC,MIBLEbindKeys[i].MAC,sizeof(keyMAC.MAC))==0){ if(memcmp(keyMAC.MAC,MIBLEbindKeys[i].MAC,sizeof(keyMAC.MAC))==0){
AddLog_P(LOG_LEVEL_DEBUG,PSTR("known key")); AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: Known key"));
memcpy(MIBLEbindKeys[i].key, keyMAC.key, 16); memcpy(MIBLEbindKeys[i].key, keyMAC.key, 16);
unknownKey=false; unknownKey=false;
return 1; return 1;
} }
} }
if(unknownKey){ if(unknownKey){
AddLog_P(LOG_LEVEL_DEBUG,PSTR("New key")); AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: New key"));
MIBLEbindKeys.push_back(keyMAC); MIBLEbindKeys.push_back(keyMAC);
return 1; return 1;
} }
@ -1066,17 +1066,17 @@ int MIDecryptPayload(const uint8_t *macin, const uint8_t *nonce, uint32_t tag, u
uint8_t _bindkey[32] = {0x0}; uint8_t _bindkey[32] = {0x0};
const unsigned char authData[16] = {0x11}; const unsigned char authData[16] = {0x11};
bool foundNoKey = true; bool foundNoKey = true;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: search key for MAC: %02x%02x%02x%02x%02x%02x"), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: Search key for MAC: %02x%02x%02x%02x%02x%02x"), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
for(uint32_t i=0; i<MIBLEbindKeys.size(); i++){ for(uint32_t i=0; i<MIBLEbindKeys.size(); i++){
if(memcmp(mac, MIBLEbindKeys[i].MAC, 6)==0){ if(memcmp(mac, MIBLEbindKeys[i].MAC, 6)==0){
memcpy(_bindkey, MIBLEbindKeys[i].key, 16); memcpy(_bindkey, MIBLEbindKeys[i].key, 16);
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: decryption Key found")); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Decryption Key found"));
foundNoKey = false; foundNoKey = false;
break; break;
} }
} }
if(foundNoKey){ if(foundNoKey){
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: no Key found !!")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: No Key found"));
return -2; // indicates needs key return -2; // indicates needs key
} }
@ -1098,7 +1098,7 @@ int MIDecryptPayload(const uint8_t *macin, const uint8_t *nonce, uint32_t tag, u
// returns 1 if matched, else 0 // returns 1 if matched, else 0
int ret = br_ccm_check_tag(&ctx, &tag); int ret = br_ccm_check_tag(&ctx, &tag);
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: Err:%i, Decrypted : %02x %02x %02x %02x %02x"), ret, payload[1],payload[2],payload[3],payload[4],payload[5]); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Err:%i, Decrypted : %02x %02x %02x %02x %02x"), ret, payload[1],payload[2],payload[3],payload[4],payload[5]);
return ret-1; // -> -1=fail, 0=success return ret-1; // -> -1=fail, 0=success
} }
@ -1168,7 +1168,7 @@ int MIParsePacket(const uint8_t* slotmac, struct mi_beacon_data_t *parsed, const
parsed->devicetype = *((uint16_t *)(data + byteindex)); parsed->devicetype = *((uint16_t *)(data + byteindex));
byteindex += 2; byteindex += 2;
parsed->framecnt = data[byteindex]; parsed->framecnt = data[byteindex];
//if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI frame %d"), parsed->framecnt); //if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: MI frame %d"), parsed->framecnt);
byteindex++; byteindex++;
@ -1217,17 +1217,17 @@ int MIParsePacket(const uint8_t* slotmac, struct mi_beacon_data_t *parsed, const
break; break;
case 0: // suceeded case 0: // suceeded
parsed->needkey = KEY_REQUIRED_AND_FOUND; parsed->needkey = KEY_REQUIRED_AND_FOUND;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI payload decrypted")); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Payload decrypted"));
break; break;
case -1: // key failed to work case -1: // key failed to work
parsed->needkey = KEY_REQUIRED_AND_INVALID; parsed->needkey = KEY_REQUIRED_AND_INVALID;
AddLog_P(LOG_LEVEL_ERROR,PSTR("MI payload decrypt failed")); AddLog_P(LOG_LEVEL_ERROR,PSTR("M32: Payload decrypt failed"));
parsed->payloadpresent = 0; parsed->payloadpresent = 0;
return 0; return 0;
break; break;
case -2: // key not present case -2: // key not present
parsed->needkey = KEY_REQUIRED_BUT_NOT_FOUND; parsed->needkey = KEY_REQUIRED_BUT_NOT_FOUND;
AddLog_P(LOG_LEVEL_ERROR,PSTR("MI payload encrypted but no key")); AddLog_P(LOG_LEVEL_ERROR,PSTR("M32: Payload encrypted but no key"));
parsed->payloadpresent = 0; parsed->payloadpresent = 0;
return 0; return 0;
break; break;
@ -1262,7 +1262,7 @@ int MIParsePacket(const uint8_t* slotmac, struct mi_beacon_data_t *parsed, const
} }
if ((len - byteindex) == 0){ if ((len - byteindex) == 0){
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI no payload")); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: No payload"));
parsed->payload.size = 0; parsed->payload.size = 0;
parsed->payloadpresent = 0; parsed->payloadpresent = 0;
return 0; return 0;
@ -1271,14 +1271,14 @@ int MIParsePacket(const uint8_t* slotmac, struct mi_beacon_data_t *parsed, const
// we have payload which did not need decrypt. // we have payload which did not need decrypt.
if (decres == 1){ if (decres == 1){
parsed->needkey = KEY_NOT_REQUIRED; parsed->needkey = KEY_NOT_REQUIRED;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI payload unencrypted")); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Payload unencrypted"));
} }
// already decrypted if required // already decrypted if required
parsed->payloadpresent = 1; parsed->payloadpresent = 1;
memcpy(&parsed->payload, (data + byteindex), (len - byteindex)); memcpy(&parsed->payload, (data + byteindex), (len - byteindex));
if (parsed->payload.size != (len - byteindex) - 3){ if (parsed->payload.size != (len - byteindex) - 3){
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI payload length mismatch")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Payload length mismatch"));
} }
return 1; return 1;
@ -1319,7 +1319,7 @@ void MI32nullifyEndOfMQTT_DATA(){
*/ */
uint32_t MIBLEgetSensorSlot(const uint8_t *mac, uint16_t _type, uint8_t counter){ uint32_t MIBLEgetSensorSlot(const uint8_t *mac, uint16_t _type, uint8_t counter){
//AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("%s: will test ID-type: %x"),D_CMND_MI32, _type); //AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: %s: will test ID-type: %x"),D_CMND_MI32, _type);
bool _success = false; bool _success = false;
for (uint32_t i=0; i < MI_MI32_TYPES; i++){ // i < sizeof(kMI32DeviceID) gives compiler warning for (uint32_t i=0; i < MI_MI32_TYPES; i++){ // i < sizeof(kMI32DeviceID) gives compiler warning
if(_type == kMI32DeviceID[i]){ if(_type == kMI32DeviceID[i]){
@ -1328,40 +1328,40 @@ uint32_t MIBLEgetSensorSlot(const uint8_t *mac, uint16_t _type, uint8_t counter)
break; break;
} }
else { else {
//AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("%s: ID-type is not: %x"),D_CMND_MI32,kMI32DeviceID[i]); //AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: %s: ID-type is not: %x"),D_CMND_MI32,kMI32DeviceID[i]);
} }
} }
if(!_success) { if(!_success) {
_type = 1; // unknown _type = 1; // unknown
} }
//AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("%s: vector size %u"),D_CMND_MI32, MIBLEsensors.size()); //AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: %s: vector size %u"),D_CMND_MI32, MIBLEsensors.size());
for(uint32_t i=0; i<MIBLEsensors.size(); i++){ for(uint32_t i=0; i<MIBLEsensors.size(); i++){
if(memcmp(mac, MIBLEsensors[i].MAC, 6)==0){ if(memcmp(mac, MIBLEsensors[i].MAC, 6)==0){
// AddLog_P(LOG_LEVEL_DEBUG,PSTR("Counters: %x %x"),MIBLEsensors[i].lastCnt, counter); // AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Counters: %x %x"),MIBLEsensors[i].lastCnt, counter);
if(MIBLEsensors[i].lastCnt==counter) { if(MIBLEsensors[i].lastCnt==counter) {
// AddLog_P(LOG_LEVEL_DEBUG,PSTR("Old packet")); // AddLog_P(LOG_LEVEL_DEBUG,PSTR("Old packet"));
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("%s: slot: %u/%u - ign repeat"),D_CMND_MI32, i, MIBLEsensors.size()); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: %s: slot: %u/%u - ign repeat"),D_CMND_MI32, i, MIBLEsensors.size());
//return 0xff; // packet received before, stop here //return 0xff; // packet received before, stop here
} }
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI frame %d, last %d"), counter, MIBLEsensors[i].lastCnt); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Frame %d, last %d"), counter, MIBLEsensors[i].lastCnt);
MIBLEsensors[i].lastCnt = counter; MIBLEsensors[i].lastCnt = counter;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("%s: slot: %u/%u"),D_CMND_MI32, i, MIBLEsensors.size()); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: %s: slot: %u/%u"),D_CMND_MI32, i, MIBLEsensors.size());
if (MIBLEsensors[i].type != _type){ if (MIBLEsensors[i].type != _type){
// this happens on incorrectly configured pvvx ATC firmware // this happens on incorrectly configured pvvx ATC firmware
AddLog_P(LOG_LEVEL_ERROR,PSTR("%s: slot: %u - device type 0x%04x(%s) -> 0x%04x(%s) - check device is only sending one type of advert."),D_CMND_MI32, i, AddLog_P(LOG_LEVEL_ERROR,PSTR("M32: %s: slot: %u - device type 0x%04x(%s) -> 0x%04x(%s) - check device is only sending one type of advert."),D_CMND_MI32, i,
kMI32DeviceID[MIBLEsensors[i].type-1], kMI32DeviceType[MIBLEsensors[i].type-1], kMI32DeviceID[_type-1], kMI32DeviceType[_type-1]); kMI32DeviceID[MIBLEsensors[i].type-1], kMI32DeviceType[MIBLEsensors[i].type-1], kMI32DeviceID[_type-1], kMI32DeviceType[_type-1]);
MIBLEsensors[i].type = _type; MIBLEsensors[i].type = _type;
} }
return i; return i;
} }
//AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("%s: i: %x %x %x %x %x %x"),D_CMND_MI32, MIBLEsensors[i].MAC[5], MIBLEsensors[i].MAC[4],MIBLEsensors[i].MAC[3],MIBLEsensors[i].MAC[2],MIBLEsensors[i].MAC[1],MIBLEsensors[i].MAC[0]); //AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: %s: i: %x %x %x %x %x %x"),D_CMND_MI32, MIBLEsensors[i].MAC[5], MIBLEsensors[i].MAC[4],MIBLEsensors[i].MAC[3],MIBLEsensors[i].MAC[2],MIBLEsensors[i].MAC[1],MIBLEsensors[i].MAC[0]);
//AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("%s: n: %x %x %x %x %x %x"),D_CMND_MI32, mac[5], mac[4], mac[3],mac[2],mac[1],mac[0]); //AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: %s: n: %x %x %x %x %x %x"),D_CMND_MI32, mac[5], mac[4], mac[3],mac[2],mac[1],mac[0]);
} }
//AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("%s: new sensor -> slot: %u"),D_CMND_MI32, MIBLEsensors.size()); //AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: %s: new sensor -> slot: %u"),D_CMND_MI32, MIBLEsensors.size());
//AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("%s: found new sensor"),D_CMND_MI32); //AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: %s: found new sensor"),D_CMND_MI32);
mi_sensor_t _newSensor; mi_sensor_t _newSensor;
memset(&_newSensor, 0 , sizeof(_newSensor)); memset(&_newSensor, 0 , sizeof(_newSensor));
memcpy(_newSensor.MAC, mac, 6); memcpy(_newSensor.MAC, mac, 6);
@ -1411,7 +1411,7 @@ uint32_t MIBLEgetSensorSlot(const uint8_t *mac, uint16_t _type, uint8_t counter)
break; break;
} }
MIBLEsensors.push_back(_newSensor); MIBLEsensors.push_back(_newSensor);
AddLog_P(LOG_LEVEL_DEBUG,PSTR("%s: new %s at slot: %u"),D_CMND_MI32, kMI32DeviceType[_type-1],MIBLEsensors.size()-1); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: %s: new %s at slot: %u"),D_CMND_MI32, kMI32DeviceType[_type-1],MIBLEsensors.size()-1);
MI32.mode.shallShowStatusInfo = 1; MI32.mode.shallShowStatusInfo = 1;
return MIBLEsensors.size()-1; return MIBLEsensors.size()-1;
}; };
@ -1444,7 +1444,7 @@ void MI32StatusInfo() {
int MI32scanCompleteCallback(NimBLEScanResults results){ int MI32scanCompleteCallback(NimBLEScanResults results){
// we actually don't need to do anything here.... // we actually don't need to do anything here....
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: scancomplete")); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Scan complete"));
return 0; return 0;
} }
@ -1473,7 +1473,7 @@ void MI32Init(void) {
// note: for operations, we will set individual callbacks in the operations we request // note: for operations, we will set individual callbacks in the operations we request
//void registerForOpCallbacks(const char *tag, BLE_ESP32::OPCOMPLETE_CALLBACK* pFn); //void registerForOpCallbacks(const char *tag, BLE_ESP32::OPCOMPLETE_CALLBACK* pFn);
AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: init: request callbacks")); AddLog_P(LOG_LEVEL_INFO,PSTR("M32: init: request callbacks"));
MI32.period = Settings.tele_period; MI32.period = Settings.tele_period;
MI32.mode.init = 1; MI32.mode.init = 1;
return; return;
@ -1496,19 +1496,19 @@ int MIParseBatt(int slot, uint8_t *data, int len){
MIBLEsensors[slot].bat = value; MIBLEsensors[slot].bat = value;
if(MIBLEsensors[slot].type==MI_FLORA){ if(MIBLEsensors[slot].type==MI_FLORA){
if (len < 7){ if (len < 7){
AddLog_P(LOG_LEVEL_ERROR,PSTR("FLORA: not enough bytes read for firmware?")); AddLog_P(LOG_LEVEL_ERROR,PSTR("M32: FLORA: not enough bytes read for firmware?"));
} else { } else {
memcpy(MIBLEsensors[slot].firmware, data+2, 5); memcpy(MIBLEsensors[slot].firmware, data+2, 5);
MIBLEsensors[slot].firmware[5] = '\0'; MIBLEsensors[slot].firmware[5] = '\0';
AddLog_P(LOG_LEVEL_DEBUG,PSTR("%s: FLORA Firmware: %s"),D_CMND_MI32,MIBLEsensors[slot].firmware); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: %s: FLORA Firmware: %s"),D_CMND_MI32,MIBLEsensors[slot].firmware);
} }
} }
MIBLEsensors[slot].eventType.bat = 1; MIBLEsensors[slot].eventType.bat = 1;
MIBLEsensors[slot].shallSendMQTT = 1; MIBLEsensors[slot].shallSendMQTT = 1;
MI32.mode.shallTriggerTele = 1; MI32.mode.shallTriggerTele = 1;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("Batt read for %s complete %d"), slotMAC, value); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Batt read for %s complete %d"), slotMAC, value);
} else { } else {
AddLog_P(LOG_LEVEL_ERROR,PSTR("Batt read for %s complete but out of range 1-101 (%d)"), slotMAC, value); AddLog_P(LOG_LEVEL_ERROR,PSTR("M32: Batt read for %s complete but out of range 1-101 (%d)"), slotMAC, value);
} }
return 0; return 0;
@ -1540,7 +1540,7 @@ void MI32ParseATCPacket(const uint8_t * _buf, uint32_t length, const uint8_t *ad
if(_slot==0xff) return; if(_slot==0xff) return;
if ((_slot >= 0) && (_slot < MIBLEsensors.size())){ if ((_slot >= 0) && (_slot < MIBLEsensors.size())){
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("%s:pvvx at slot %u"), kMI32DeviceType[MIBLEsensors[_slot].type-1],_slot); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: %s:pvvx at slot %u"), kMI32DeviceType[MIBLEsensors[_slot].type-1],_slot);
MIBLEsensors[_slot].RSSI=RSSI; MIBLEsensors[_slot].RSSI=RSSI;
MIBLEsensors[_slot].needkey=KEY_NOT_REQUIRED; MIBLEsensors[_slot].needkey=KEY_NOT_REQUIRED;
@ -1557,7 +1557,7 @@ void MI32ParseATCPacket(const uint8_t * _buf, uint32_t length, const uint8_t *ad
} }
return; return;
} else { } else {
AddLog_P(LOG_LEVEL_ERROR, PSTR("PVVX packet mac mismatch - ignored?")); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: PVVX packet mac mismatch - ignored?"));
return; return;
} }
} }
@ -1571,9 +1571,9 @@ void MI32ParseATCPacket(const uint8_t * _buf, uint32_t length, const uint8_t *ad
if (memcmp(addrrev, _packet->MAC, 6)){ if (memcmp(addrrev, _packet->MAC, 6)){
MI32_ReverseMAC(_packet->MAC); MI32_ReverseMAC(_packet->MAC);
if (!memcmp(addrrev, _packet->MAC, 6)){ if (!memcmp(addrrev, _packet->MAC, 6)){
AddLog_P(LOG_LEVEL_ERROR, PSTR("ATC packet with reversed MAC addr?")); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: ATC packet with reversed MAC addr?"));
} else { } else {
AddLog_P(LOG_LEVEL_ERROR, PSTR("ATC packet with MAC addr mismatch - is this mesh?")); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: ATC packet with MAC addr mismatch - is this mesh?"));
memcpy(addrrev, _packet->MAC, 6); memcpy(addrrev, _packet->MAC, 6);
} }
addr = addrrev; addr = addrrev;
@ -1584,7 +1584,7 @@ void MI32ParseATCPacket(const uint8_t * _buf, uint32_t length, const uint8_t *ad
if(_slot==0xff) return; if(_slot==0xff) return;
if ((_slot >= 0) && (_slot < MIBLEsensors.size())){ if ((_slot >= 0) && (_slot < MIBLEsensors.size())){
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("%s at slot %u"), kMI32DeviceType[MIBLEsensors[_slot].type-1],_slot); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: %s at slot %u"), kMI32DeviceType[MIBLEsensors[_slot].type-1],_slot);
MIBLEsensors[_slot].RSSI=RSSI; MIBLEsensors[_slot].RSSI=RSSI;
MIBLEsensors[_slot].needkey=KEY_NOT_REQUIRED; MIBLEsensors[_slot].needkey=KEY_NOT_REQUIRED;
@ -1616,7 +1616,7 @@ int MI32parseMiPayload(int _slot, struct mi_beacon_data_t *parsed){
char tmp[20]; char tmp[20];
BLE_ESP32::dump(tmp, 20, (uint8_t*)&(parsed->payload), parsed->payload.size+3); BLE_ESP32::dump(tmp, 20, (uint8_t*)&(parsed->payload), parsed->payload.size+3);
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("MI%d payload %s"), _slot, tmp); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: MI%d payload %s"), _slot, tmp);
switch(parsed->payload.type){ switch(parsed->payload.type){
case 0x01: // button press case 0x01: // button press
@ -1636,22 +1636,22 @@ int MI32parseMiPayload(int _slot, struct mi_beacon_data_t *parsed){
if(_tempFloat<60){ if(_tempFloat<60){
MIBLEsensors[_slot].temp=_tempFloat; MIBLEsensors[_slot].temp=_tempFloat;
MIBLEsensors[_slot].eventType.temp = 1; MIBLEsensors[_slot].eventType.temp = 1;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("Mode 4: temp updated")); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: Mode 4: temp updated"));
} else { } else {
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("Mode 4: temp ignored > 60 (%f)"), _tempFloat); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: Mode 4: temp ignored > 60 (%f)"), _tempFloat);
} }
// AddLog_P(LOG_LEVEL_DEBUG,PSTR("Mode 4: U16: %u Temp"), _beacon.temp ); // AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Mode 4: U16: %u Temp"), _beacon.temp );
} break; } break;
case 0x06: { case 0x06: {
float _tempFloat=(float)(pld->hum)/10.0f; float _tempFloat=(float)(pld->hum)/10.0f;
if(_tempFloat<101){ if(_tempFloat<101){
MIBLEsensors[_slot].hum=_tempFloat; MIBLEsensors[_slot].hum=_tempFloat;
MIBLEsensors[_slot].eventType.hum = 1; MIBLEsensors[_slot].eventType.hum = 1;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("Mode 6: hum updated")); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: Mode 6: hum updated"));
} else { } else {
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("Mode 6: hum ignored > 101 (%f)"), _tempFloat); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: Mode 6: hum ignored > 101 (%f)"), _tempFloat);
} }
// AddLog_P(LOG_LEVEL_DEBUG,PSTR("Mode 6: U16: %u Hum"), _beacon.hum); // AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Mode 6: U16: %u Hum"), _beacon.hum);
} break; } break;
case 0x07: case 0x07:
MIBLEsensors[_slot].lux=pld->lux & 0x00ffffff; MIBLEsensors[_slot].lux=pld->lux & 0x00ffffff;
@ -1659,19 +1659,19 @@ int MI32parseMiPayload(int _slot, struct mi_beacon_data_t *parsed){
MIBLEsensors[_slot].eventType.noMotion = 1; MIBLEsensors[_slot].eventType.noMotion = 1;
} }
MIBLEsensors[_slot].eventType.lux = 1; MIBLEsensors[_slot].eventType.lux = 1;
// AddLog_P(LOG_LEVEL_DEBUG,PSTR("Mode 7: U24: %u Lux"), _beacon.lux & 0x00ffffff); // AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Mode 7: U24: %u Lux"), _beacon.lux & 0x00ffffff);
break; break;
case 0x08: case 0x08:
MIBLEsensors[_slot].moisture=pld->moist; MIBLEsensors[_slot].moisture=pld->moist;
MIBLEsensors[_slot].eventType.moist = 1; MIBLEsensors[_slot].eventType.moist = 1;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("Mode 8: moisture updated")); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: Mode 8: moisture updated"));
// AddLog_P(LOG_LEVEL_DEBUG,PSTR("Mode 8: U8: %u Moisture"), _beacon.moist); // AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Mode 8: U8: %u Moisture"), _beacon.moist);
break; break;
case 0x09: // 'conductivity' case 0x09: // 'conductivity'
MIBLEsensors[_slot].fertility=pld->fert; MIBLEsensors[_slot].fertility=pld->fert;
MIBLEsensors[_slot].eventType.fert = 1; MIBLEsensors[_slot].eventType.fert = 1;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("Mode 9: fertility updated")); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: Mode 9: fertility updated"));
// AddLog_P(LOG_LEVEL_DEBUG,PSTR("Mode 9: U16: %u Fertility"), _beacon.fert); // AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Mode 9: U16: %u Fertility"), _beacon.fert);
break; break;
case 0x0a: case 0x0a:
if(MI32.option.ignoreBogusBattery){ if(MI32.option.ignoreBogusBattery){
@ -1683,31 +1683,31 @@ int MI32parseMiPayload(int _slot, struct mi_beacon_data_t *parsed){
if(pld->bat<101){ if(pld->bat<101){
MIBLEsensors[_slot].bat = pld->bat; MIBLEsensors[_slot].bat = pld->bat;
MIBLEsensors[_slot].eventType.bat = 1; MIBLEsensors[_slot].eventType.bat = 1;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("Mode a: bat updated")); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: Mode a: bat updated"));
} else { } else {
MIBLEsensors[_slot].bat = 100; MIBLEsensors[_slot].bat = 100;
MIBLEsensors[_slot].eventType.bat = 1; MIBLEsensors[_slot].eventType.bat = 1;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("Mode a: bat > 100 (%d)"), pld->bat); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: Mode a: bat > 100 (%d)"), pld->bat);
} }
// AddLog_P(LOG_LEVEL_DEBUG,PSTR("Mode a: U8: %u %%"), _beacon.bat); // AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Mode a: U8: %u %%"), _beacon.bat);
break; break;
case 0x0d:{ case 0x0d:{
float _tempFloat=(float)(pld->HT.temp)/10.0f; float _tempFloat=(float)(pld->HT.temp)/10.0f;
if(_tempFloat < 60){ if(_tempFloat < 60){
MIBLEsensors[_slot].temp = _tempFloat; MIBLEsensors[_slot].temp = _tempFloat;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("Mode d: temp updated")); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: Mode d: temp updated"));
} else { } else {
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("Mode d: temp ignored > 60 (%f)"), _tempFloat); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: Mode d: temp ignored > 60 (%f)"), _tempFloat);
} }
_tempFloat=(float)(pld->HT.hum)/10.0f; _tempFloat=(float)(pld->HT.hum)/10.0f;
if(_tempFloat < 100){ if(_tempFloat < 100){
MIBLEsensors[_slot].hum = _tempFloat; MIBLEsensors[_slot].hum = _tempFloat;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("Mode d: hum updated")); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: Mode d: hum updated"));
} else { } else {
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("Mode d: hum ignored > 100 (%f)"), _tempFloat); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: Mode d: hum ignored > 100 (%f)"), _tempFloat);
} }
MIBLEsensors[_slot].eventType.tempHum = 1; MIBLEsensors[_slot].eventType.tempHum = 1;
// AddLog_P(LOG_LEVEL_DEBUG,PSTR("Mode d: U16: %x Temp U16: %x Hum"), _beacon.HT.temp, _beacon.HT.hum); // AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Mode d: U16: %x Temp U16: %x Hum"), _beacon.HT.temp, _beacon.HT.hum);
} break; } break;
case 0x0f: case 0x0f:
if (parsed->payload.ten != 0) break; if (parsed->payload.ten != 0) break;
@ -1718,7 +1718,7 @@ int MI32parseMiPayload(int _slot, struct mi_beacon_data_t *parsed){
MIBLEsensors[_slot].eventType.lux = 1; MIBLEsensors[_slot].eventType.lux = 1;
MIBLEsensors[_slot].NMT = 0; MIBLEsensors[_slot].NMT = 0;
MI32.mode.shallTriggerTele = 1; MI32.mode.shallTriggerTele = 1;
// AddLog_P(LOG_LEVEL_DEBUG,PSTR("PIR: primary"),MIBLEsensors[_slot].lux ); // AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: PIR: primary"),MIBLEsensors[_slot].lux );
break; break;
case 0x10:{ // 'formaldehide' case 0x10:{ // 'formaldehide'
const uint16_t f = uint16_t(parsed->payload.data[0]) | (uint16_t(parsed->payload.data[1]) << 8); const uint16_t f = uint16_t(parsed->payload.data[0]) | (uint16_t(parsed->payload.data[1]) << 8);
@ -1742,11 +1742,11 @@ int MI32parseMiPayload(int _slot, struct mi_beacon_data_t *parsed){
MIBLEsensors[_slot].NMT = pld->NMT; MIBLEsensors[_slot].NMT = pld->NMT;
MIBLEsensors[_slot].eventType.NMT = 1; MIBLEsensors[_slot].eventType.NMT = 1;
MI32.mode.shallTriggerTele = 1; MI32.mode.shallTriggerTele = 1;
// AddLog_P(LOG_LEVEL_DEBUG,PSTR("Mode 17: NMT: %u seconds"), _beacon.NMT); // AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Mode 17: NMT: %u seconds"), _beacon.NMT);
} break; } break;
default: { default: {
AddLog_P(LOG_LEVEL_DEBUG,PSTR("Unknown MI pld")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Unknown MI pld"));
res = 0; res = 0;
} break; } break;
} }
@ -1771,7 +1771,7 @@ void MI32ParseResponse(const uint8_t *buf, uint16_t bufsize, const uint8_t* addr
MI32_ReverseMAC(addrrev); MI32_ReverseMAC(addrrev);
if (memcmp(addrrev, parsed.macdata.mac, 6)){ if (memcmp(addrrev, parsed.macdata.mac, 6)){
AddLog_P(LOG_LEVEL_ERROR, PSTR("MI packet with MAC addr mismatch - is this mesh?")); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: MI packet with MAC addr mismatch - is this mesh?"));
memcpy(addrrev, parsed.macdata.mac, 6); memcpy(addrrev, parsed.macdata.mac, 6);
MI32_ReverseMAC(addrrev); MI32_ReverseMAC(addrrev);
addr = addrrev; addr = addrrev;
@ -1785,7 +1785,7 @@ void MI32ParseResponse(const uint8_t *buf, uint16_t bufsize, const uint8_t* addr
} }
MIBLEsensors[_slot].RSSI=RSSI; MIBLEsensors[_slot].RSSI=RSSI;
if (!res){ // - if the payload is not valid if (!res){ // - if the payload is not valid
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("MIParsePacket returned %d"), res); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: MIParsePacket returned %d"), res);
return; return;
} else { } else {
} }
@ -1814,14 +1814,14 @@ void MI32removeMIBLEsensor(uint8_t* MAC){
\***********************************************************************/ \***********************************************************************/
void MI32notifyHT_LY(int slot, char *_buf, int len){ void MI32notifyHT_LY(int slot, char *_buf, int len){
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("%s: raw data: %x%x%x%x%x%x%x"),D_CMND_MI32,_buf[0],_buf[1],_buf[2],_buf[3],_buf[4],_buf[5],_buf[6]); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: %s: raw data: %x%x%x%x%x%x%x"),D_CMND_MI32,_buf[0],_buf[1],_buf[2],_buf[3],_buf[4],_buf[5],_buf[6]);
// the value 0b00 is 28.16 C? // the value 0b00 is 28.16 C?
if(_buf[0] != 0 || _buf[1] != 0){ if(_buf[0] != 0 || _buf[1] != 0){
memcpy(&LYWSD0x_HT,(void *)_buf,sizeof(LYWSD0x_HT)); memcpy(&LYWSD0x_HT,(void *)_buf,sizeof(LYWSD0x_HT));
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("%s: T * 100: %u, H: %u, V: %u"),D_CMND_MI32,LYWSD0x_HT.temp,LYWSD0x_HT.hum, LYWSD0x_HT.volt); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: %s: T * 100: %u, H: %u, V: %u"),D_CMND_MI32,LYWSD0x_HT.temp,LYWSD0x_HT.hum, LYWSD0x_HT.volt);
uint32_t _slot = slot; uint32_t _slot = slot;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("MIBLE: Sensor slot: %u"), _slot); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: MIBLE: Sensor slot: %u"), _slot);
static float _tempFloat; static float _tempFloat;
_tempFloat=(float)(LYWSD0x_HT.temp)/100.0f; _tempFloat=(float)(LYWSD0x_HT.temp)/100.0f;
if(_tempFloat<60){ if(_tempFloat<60){
@ -1831,7 +1831,7 @@ void MI32notifyHT_LY(int slot, char *_buf, int len){
_tempFloat=(float)LYWSD0x_HT.hum; _tempFloat=(float)LYWSD0x_HT.hum;
if(_tempFloat<100){ if(_tempFloat<100){
MIBLEsensors[_slot].hum = _tempFloat; MIBLEsensors[_slot].hum = _tempFloat;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("LYWSD0x: hum updated")); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: LYWSD0x: hum updated"));
} }
MIBLEsensors[_slot].eventType.tempHum = 1; MIBLEsensors[_slot].eventType.tempHum = 1;
if (MIBLEsensors[_slot].type == MI_LYWSD03MMC || MIBLEsensors[_slot].type == MI_MHOC401){ if (MIBLEsensors[_slot].type == MI_LYWSD03MMC || MIBLEsensors[_slot].type == MI_MHOC401){
@ -1875,7 +1875,7 @@ void MI32Every50mSecond(){
void MI32EverySecond(bool restart){ void MI32EverySecond(bool restart){
// AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("MI32: onesec")); // AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("M32: onesec"));
MI32TimeoutSensors(); MI32TimeoutSensors();
MI32ShowSomeSensors(); MI32ShowSomeSensors();
@ -1893,7 +1893,7 @@ void MI32EverySecond(bool restart){
if (MI32.secondsCounter >= MI32.period){ if (MI32.secondsCounter >= MI32.period){
// only if we finished the last read // only if we finished the last read
if (MI32.sensorreader.slot >= MIBLEsensors.size()){ if (MI32.sensorreader.slot >= MIBLEsensors.size()){
AddLog_P(LOG_LEVEL_DEBUG,PSTR("kick off readOneSensor")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Kick off readOneSensor"));
// kick off notification sensor reading every period. // kick off notification sensor reading every period.
MI32.sensorreader.slot = 0; MI32.sensorreader.slot = 0;
MI32.secondsCounter = 0; MI32.secondsCounter = 0;
@ -1903,11 +1903,11 @@ void MI32EverySecond(bool restart){
if (MI32.secondsCounter2 >= MI32.period){ if (MI32.secondsCounter2 >= MI32.period){
if (MI32.mqttCurrentSlot >= MIBLEsensors.size()){ if (MI32.mqttCurrentSlot >= MIBLEsensors.size()){
AddLog_P(LOG_LEVEL_DEBUG,PSTR("kick off tele sending")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Kick off tele sending"));
MI32.mqttCurrentSlot = 0; MI32.mqttCurrentSlot = 0;
MI32.secondsCounter2 = 0; MI32.secondsCounter2 = 0;
} else { } else {
AddLog_P(LOG_LEVEL_DEBUG,PSTR("hit tele time, restarted but not finished last - lost from slot %d")+MI32.mqttCurrentSlot); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Hit tele time, restarted but not finished last - lost from slot %d")+MI32.mqttCurrentSlot);
MI32.mqttCurrentSlot = 0; MI32.mqttCurrentSlot = 0;
MI32.secondsCounter2 = 0; MI32.secondsCounter2 = 0;
} }
@ -1968,15 +1968,15 @@ void CmndMi32Time(void) {
if (MIBLEsensors.size() > slot) { if (MIBLEsensors.size() > slot) {
int res = genericTimeWriteFn(slot); int res = genericTimeWriteFn(slot);
if (res > 0){ if (res > 0){
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("MI32: will set Time")); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: will set Time"));
ResponseCmndNumber(slot); ResponseCmndNumber(slot);
return; return;
} }
if (res < 0) { if (res < 0) {
AddLog_P(LOG_LEVEL_ERROR, PSTR("MI32: cannot set Time on sensor type")); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: cannot set Time on sensor type"));
} }
if (res == 0) { if (res == 0) {
AddLog_P(LOG_LEVEL_ERROR, PSTR("MI32: cannot set Time right now")); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: cannot set Time right now"));
} }
} }
} }
@ -2009,15 +2009,15 @@ void CmndMi32Unit(void) {
// TOGGLE unit? // TOGGLE unit?
int res = genericUnitWriteFn(slot, -1); int res = genericUnitWriteFn(slot, -1);
if (res > 0){ if (res > 0){
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("MI32: will toggle Unit")); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: will toggle Unit"));
ResponseCmndNumber(slot); ResponseCmndNumber(slot);
return; return;
} }
if (res < 0) { if (res < 0) {
AddLog_P(LOG_LEVEL_ERROR, PSTR("MI32: cannot toggle Unit on sensor type")); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: cannot toggle Unit on sensor type"));
} }
if (res == 0) { if (res == 0) {
AddLog_P(LOG_LEVEL_ERROR, PSTR("MI32: cannot toggle Unit right now")); AddLog_P(LOG_LEVEL_ERROR, PSTR("M32: cannot toggle Unit right now"));
} }
} }
} }
@ -2091,7 +2091,7 @@ void CmndMi32Block(void){
MIBLEBlockList.push_back(_MACasBytes); MIBLEBlockList.push_back(_MACasBytes);
MI32removeMIBLEsensor(_MACasBytes.buf); MI32removeMIBLEsensor(_MACasBytes.buf);
} }
// AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: size of ilist: %u"), MIBLEBlockList.size()); // AddLog_P(LOG_LEVEL_INFO,PSTR("M32: size of ilist: %u"), MIBLEBlockList.size());
} break; } break;
} }
MI32BlockListResp(); MI32BlockListResp();
@ -2136,7 +2136,7 @@ void MI32KeyListResp(){
void CmndMi32Keys(void){ void CmndMi32Keys(void){
#ifdef BLE_ESP32_ALIASES #ifdef BLE_ESP32_ALIASES
int op = XdrvMailbox.index; int op = XdrvMailbox.index;
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("key %d %s"), op, XdrvMailbox.data); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Key %d %s"), op, XdrvMailbox.data);
int res = -1; int res = -1;
switch(op){ switch(op){
@ -2175,7 +2175,7 @@ void CmndMi32Keys(void){
return; return;
} }
AddLog_P(LOG_LEVEL_ERROR,PSTR("Add key mac %s = key %s"), mac, key); AddLog_P(LOG_LEVEL_ERROR,PSTR("M32: Add key mac %s = key %s"), mac, key);
char tmp[20]; char tmp[20];
// convert mac back to string // convert mac back to string
ToHex_P(addr,6,tmp,20,0); ToHex_P(addr,6,tmp,20,0);
@ -2186,7 +2186,7 @@ void CmndMi32Keys(void){
} while (p); } while (p);
if (added){ if (added){
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("Added %d Keys"), added); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Added %d Keys"), added);
MI32KeyListResp(); MI32KeyListResp();
} else { } else {
MI32KeyListResp(); MI32KeyListResp();
@ -2194,7 +2194,7 @@ void CmndMi32Keys(void){
return; return;
} break; } break;
case 2:{ // clear case 2:{ // clear
if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32Keys clearing %d"), MIBLEbindKeys.size()); if (BLE_ESP32::BLEDebugMode > 0) AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Keys clearing %d"), MIBLEbindKeys.size());
for (int i = MIBLEbindKeys.size()-1; i >= 0; i--){ for (int i = MIBLEbindKeys.size()-1; i >= 0; i--){
MIBLEbindKeys.pop_back(); MIBLEbindKeys.pop_back();
} }
@ -2246,9 +2246,9 @@ const char HTTP_MI_KEY_STYLE[] PROGMEM = "";
#define D_MI32_KEY "MI32 Set Key" #define D_MI32_KEY "MI32 Set Key"
void HandleMI32Key(){ void HandleMI32Key(){
AddLog_P(LOG_LEVEL_DEBUG, PSTR("HandleMI32Key hit")); AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: HandleMI32Key hit"));
if (!HttpCheckPriviledgedAccess()) { if (!HttpCheckPriviledgedAccess()) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("!HttpCheckPriviledgedAccess()")); AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: !HttpCheckPriviledgedAccess()"));
return; return;
} }
WSContentStart_P(PSTR(D_MI32_KEY)); WSContentStart_P(PSTR(D_MI32_KEY));
@ -2292,7 +2292,7 @@ void MI32TimeoutSensors(){
//if (MIBLEsensors[i].MAC[2] || MIBLEsensors[i].MAC[3] || MIBLEsensors[i].MAC[4] || MIBLEsensors[i].MAC[5]){ //if (MIBLEsensors[i].MAC[2] || MIBLEsensors[i].MAC[3] || MIBLEsensors[i].MAC[4] || MIBLEsensors[i].MAC[5]){
if (!BLE_ESP32::devicePresent(MIBLEsensors[i].MAC)){ if (!BLE_ESP32::devicePresent(MIBLEsensors[i].MAC)){
uint8_t *mac = MIBLEsensors[i].MAC; uint8_t *mac = MIBLEsensors[i].MAC;
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: dev no longer present MAC: %02x%02x%02x%02x%02x%02x"), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Dev no longer present MAC: %02x%02x%02x%02x%02x%02x"), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
TasAutoMutex localmutex(&slotmutex, "Mi32Timeout"); TasAutoMutex localmutex(&slotmutex, "Mi32Timeout");
MIBLEsensors.erase(MIBLEsensors.begin() + i); MIBLEsensors.erase(MIBLEsensors.begin() + i);
} }
@ -2497,7 +2497,7 @@ void MI32ShowSomeSensors(){
} }
ResponseAppend_P(PSTR("}")); ResponseAppend_P(PSTR("}"));
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
//AddLog_P(LOG_LEVEL_DEBUG,PSTR("%s: show some %d %s"),D_CMND_MI32, MI32.mqttCurrentSlot, TasmotaGlobal.mqtt_data); //AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: %s: show some %d %s"),D_CMND_MI32, MI32.mqttCurrentSlot, TasmotaGlobal.mqtt_data);
#ifdef USE_RULES #ifdef USE_RULES
RulesTeleperiod(); // Allow rule based HA messages RulesTeleperiod(); // Allow rule based HA messages
@ -2547,7 +2547,7 @@ void MI32ShowTriggeredSensors(){
if (cnt){ // if we got one, then publish if (cnt){ // if we got one, then publish
ResponseAppend_P(PSTR("}")); ResponseAppend_P(PSTR("}"));
MqttPublishPrefixTopic_P(STAT, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); MqttPublishPrefixTopic_P(STAT, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
AddLog_P(LOG_LEVEL_DEBUG,PSTR("%s: triggered %d %s"),D_CMND_MI32, sensor, TasmotaGlobal.mqtt_data); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: %s: triggered %d %s"),D_CMND_MI32, sensor, TasmotaGlobal.mqtt_data);
#ifdef USE_RULES #ifdef USE_RULES
RulesTeleperiod(); // Allow rule based HA messages RulesTeleperiod(); // Allow rule based HA messages

View File

@ -3,8 +3,7 @@
## EmberZNet NCP UART EZSP firmware signed for Sonoff ZBBridge ## EmberZNet NCP UART EZSP firmware signed for Sonoff ZBBridge
- `ncp-uart-sw_6.7.6_115200.ota` - recommended stable version for EZSP v6, EZSP v7, and EZSP v8 compatible hosts. - `ncp-uart-sw_6.7.6_115200.ota` - recommended stable version for EZSP v6, EZSP v7, and EZSP v8 compatible hosts.
- `ncp-uart-sw-6.8.0.1_115200.ota` - latest cutting-edge version. largely untested and only for experimentation with EZSP v8 compatible hosts. - `ncp-uart-sw_6.7.8_115200.ota` - release candidate, supposedly fixing IKEA battery drain issue.
- `ncp-uart-sw_6.5.5_115200.ota` - legacy version for EZSP v4, EZSP v5, EZSP v6, or EZSP v7 compatible hosts.
## EmberZNet and EZSP Protocol Versions ## EmberZNet and EZSP Protocol Versions
@ -13,3 +12,7 @@ Silicon Labs do not currently have a consolidated list of changes by EmberZNet S
The largest change was between EZSP v4 (first added in EmberZNet 4.7.2 SDK) and EZSP v5 that was added in EmberZNet 5.9.0 SDK which requires the Legacy Frame ID 0xFF. The change from EZSP v5 to EZSP v6 was done in EmberZNet 6.0.0 SDK. The change from EZSP v6 to EZSP v7 was in EmberZNet 6.4.0 SDK. EmberZNet 6.7.0 SDK added EZSP v8 (and Secure EZSP Protocol Version 2). The largest change was between EZSP v4 (first added in EmberZNet 4.7.2 SDK) and EZSP v5 that was added in EmberZNet 5.9.0 SDK which requires the Legacy Frame ID 0xFF. The change from EZSP v5 to EZSP v6 was done in EmberZNet 6.0.0 SDK. The change from EZSP v6 to EZSP v7 was in EmberZNet 6.4.0 SDK. EmberZNet 6.7.0 SDK added EZSP v8 (and Secure EZSP Protocol Version 2).
Perhaps more important to know is that EZSP v5, v6 and v7 (EmberZNet 6.6.x.x) use the same framing format, but EmberZNet 6.7.x.x/EZSP v8 introduced new framing format and expanded command id field from 8 bits to 16 bits. Perhaps more important to know is that EZSP v5, v6 and v7 (EmberZNet 6.6.x.x) use the same framing format, but EmberZNet 6.7.x.x/EZSP v8 introduced new framing format and expanded command id field from 8 bits to 16 bits.
## Archived Versions
- `ncp-uart-sw_6.5.5_115200.ota` - legacy version for EZSP v4, EZSP v5, EZSP v6, or EZSP v7 compatible hosts.