mirror of https://github.com/arendst/Tasmota.git
Space saving code optimization
Space saving code optimization
This commit is contained in:
parent
37b1c25881
commit
fde53117d6
|
@ -108,6 +108,7 @@ int blinks = 201; // Number of LED blinks
|
||||||
uint32_t uptime = 0; // Counting every second until 4294967295 = 130 year
|
uint32_t uptime = 0; // Counting every second until 4294967295 = 130 year
|
||||||
uint32_t loop_load_avg = 0; // Indicative loop load average
|
uint32_t loop_load_avg = 0; // Indicative loop load average
|
||||||
uint32_t global_update = 0; // Timestamp of last global temperature and humidity update
|
uint32_t global_update = 0; // Timestamp of last global temperature and humidity update
|
||||||
|
uint32_t web_log_index = 1; // Index in Web log buffer (should never be 0)
|
||||||
float global_temperature = 9999; // Provide a global temperature to be used by some sensors
|
float global_temperature = 9999; // Provide a global temperature to be used by some sensors
|
||||||
float global_humidity = 0; // Provide a global humidity to be used by some sensors
|
float global_humidity = 0; // Provide a global humidity to be used by some sensors
|
||||||
float global_pressure = 0; // Provide a global pressure to be used by some sensors
|
float global_pressure = 0; // Provide a global pressure to be used by some sensors
|
||||||
|
@ -137,7 +138,6 @@ uint8_t energy_flg = 0; // Energy monitor configured
|
||||||
uint8_t light_type = 0; // Light types
|
uint8_t light_type = 0; // Light types
|
||||||
uint8_t serial_in_byte; // Received byte
|
uint8_t serial_in_byte; // Received byte
|
||||||
uint8_t ota_retry_counter = OTA_ATTEMPTS; // OTA retry counter
|
uint8_t ota_retry_counter = OTA_ATTEMPTS; // OTA retry counter
|
||||||
uint8_t web_log_index = 1; // Index in Web log buffer (should never be 0)
|
|
||||||
uint8_t devices_present = 0; // Max number of devices supported
|
uint8_t devices_present = 0; // Max number of devices supported
|
||||||
uint8_t seriallog_level; // Current copy of Settings.seriallog_level
|
uint8_t seriallog_level; // Current copy of Settings.seriallog_level
|
||||||
uint8_t syslog_level; // Current copy of Settings.syslog_level
|
uint8_t syslog_level; // Current copy of Settings.syslog_level
|
||||||
|
|
|
@ -502,16 +502,16 @@ bool ParseIp(uint32_t* addr, const char* str)
|
||||||
return (3 == i);
|
return (3 == i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MakeValidMqtt(uint8_t option, char* str)
|
void MakeValidMqtt(uint32_t option, char* str)
|
||||||
{
|
{
|
||||||
// option 0 = replace by underscore
|
// option 0 = replace by underscore
|
||||||
// option 1 = delete character
|
// option 1 = delete character
|
||||||
uint16_t i = 0;
|
uint32_t i = 0;
|
||||||
while (str[i] > 0) {
|
while (str[i] > 0) {
|
||||||
// if ((str[i] == '/') || (str[i] == '+') || (str[i] == '#') || (str[i] == ' ')) {
|
// if ((str[i] == '/') || (str[i] == '+') || (str[i] == '#') || (str[i] == ' ')) {
|
||||||
if ((str[i] == '+') || (str[i] == '#') || (str[i] == ' ')) {
|
if ((str[i] == '+') || (str[i] == '#') || (str[i] == ' ')) {
|
||||||
if (option) {
|
if (option) {
|
||||||
uint16_t j = i;
|
uint32_t j = i;
|
||||||
while (str[j] > 0) {
|
while (str[j] > 0) {
|
||||||
str[j] = str[j +1];
|
str[j] = str[j +1];
|
||||||
j++;
|
j++;
|
||||||
|
@ -529,7 +529,7 @@ void MakeValidMqtt(uint8_t option, char* str)
|
||||||
bool NewerVersion(char* version_str)
|
bool NewerVersion(char* version_str)
|
||||||
{
|
{
|
||||||
uint32_t version = 0;
|
uint32_t version = 0;
|
||||||
uint8_t i = 0;
|
uint32_t i = 0;
|
||||||
char *str_ptr;
|
char *str_ptr;
|
||||||
char* version_dup = strdup(version_str); // Duplicate the version_str as strtok_r will modify it.
|
char* version_dup = strdup(version_str); // Duplicate the version_str as strtok_r will modify it.
|
||||||
|
|
||||||
|
@ -676,7 +676,7 @@ uint32_t RoundSqrtInt(uint32_t num)
|
||||||
return s / 2;
|
return s / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* GetTextIndexed(char* destination, size_t destination_size, uint16_t index, const char* haystack)
|
char* GetTextIndexed(char* destination, size_t destination_size, uint32_t index, const char* haystack)
|
||||||
{
|
{
|
||||||
// Returns empty string if not found
|
// Returns empty string if not found
|
||||||
// Returns text of found
|
// Returns text of found
|
||||||
|
@ -1414,7 +1414,7 @@ void SetSyslog(uint8_t loglevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
void GetLog(uint8_t idx, char** entry_pp, size_t* len_p)
|
void GetLog(uint32_t idx, char** entry_pp, size_t* len_p)
|
||||||
{
|
{
|
||||||
char* entry_p = nullptr;
|
char* entry_p = nullptr;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
@ -1422,7 +1422,7 @@ void GetLog(uint8_t idx, char** entry_pp, size_t* len_p)
|
||||||
if (idx) {
|
if (idx) {
|
||||||
char* it = web_log;
|
char* it = web_log;
|
||||||
do {
|
do {
|
||||||
uint8_t cur_idx = *it;
|
uint32_t cur_idx = *it;
|
||||||
it++;
|
it++;
|
||||||
size_t tmp = strchrspn(it, '\1');
|
size_t tmp = strchrspn(it, '\1');
|
||||||
tmp++; // Skip terminating '\1'
|
tmp++; // Skip terminating '\1'
|
||||||
|
@ -1477,6 +1477,7 @@ void AddLog(uint8_t loglevel)
|
||||||
if (Settings.webserver && (loglevel <= Settings.weblog_level)) {
|
if (Settings.webserver && (loglevel <= Settings.weblog_level)) {
|
||||||
// Delimited, zero-terminated buffer of log lines.
|
// Delimited, zero-terminated buffer of log lines.
|
||||||
// Each entry has this format: [index][log data]['\1']
|
// Each entry has this format: [index][log data]['\1']
|
||||||
|
web_log_index &= 0xFF;
|
||||||
if (!web_log_index) web_log_index++; // Index 0 is not allowed as it is the end of char string
|
if (!web_log_index) web_log_index++; // Index 0 is not allowed as it is the end of char string
|
||||||
while (web_log_index == web_log[0] || // If log already holds the next index, remove it
|
while (web_log_index == web_log[0] || // If log already holds the next index, remove it
|
||||||
strlen(web_log) + strlen(log_data) + 13 > WEB_LOG_SIZE) // 13 = web_log_index + mxtime + '\1' + '\0'
|
strlen(web_log) + strlen(log_data) + 13 > WEB_LOG_SIZE) // 13 = web_log_index + mxtime + '\1' + '\0'
|
||||||
|
@ -1488,6 +1489,7 @@ void AddLog(uint8_t loglevel)
|
||||||
memmove(web_log, it, WEB_LOG_SIZE -(it-web_log)); // Move buffer forward to remove oldest log line
|
memmove(web_log, it, WEB_LOG_SIZE -(it-web_log)); // Move buffer forward to remove oldest log line
|
||||||
}
|
}
|
||||||
snprintf_P(web_log, sizeof(web_log), PSTR("%s%c%s%s\1"), web_log, web_log_index++, mxtime, log_data);
|
snprintf_P(web_log, sizeof(web_log), PSTR("%s%c%s%s\1"), web_log, web_log_index++, mxtime, log_data);
|
||||||
|
web_log_index &= 0xFF;
|
||||||
if (!web_log_index) web_log_index++; // Index 0 is not allowed as it is the end of char string
|
if (!web_log_index) web_log_index++; // Index 0 is not allowed as it is the end of char string
|
||||||
}
|
}
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
|
|
@ -797,7 +797,7 @@ void WSContentSendStyle(void)
|
||||||
WSContentSendStyle_P(nullptr);
|
WSContentSendStyle_P(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSContentButton(uint8_t title_index)
|
void WSContentButton(uint32_t title_index)
|
||||||
{
|
{
|
||||||
char action[4];
|
char action[4];
|
||||||
char title[100]; // Large to accomodate UTF-16 as used by Russian
|
char title[100]; // Large to accomodate UTF-16 as used by Russian
|
||||||
|
@ -816,7 +816,7 @@ void WSContentButton(uint8_t title_index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSContentSpaceButton(uint8_t title_index)
|
void WSContentSpaceButton(uint32_t title_index)
|
||||||
{
|
{
|
||||||
WSContentSend_P(PSTR("<div></div>")); // 5px padding
|
WSContentSend_P(PSTR("<div></div>")); // 5px padding
|
||||||
WSContentButton(title_index);
|
WSContentButton(title_index);
|
||||||
|
@ -842,7 +842,7 @@ void WSContentStop(void)
|
||||||
|
|
||||||
/*********************************************************************************************/
|
/*********************************************************************************************/
|
||||||
|
|
||||||
void WebRestart(uint8_t type)
|
void WebRestart(uint32_t type)
|
||||||
{
|
{
|
||||||
// type 0 = restart
|
// type 0 = restart
|
||||||
// type 1 = restart after config change
|
// type 1 = restart after config change
|
||||||
|
@ -963,7 +963,7 @@ void HandleRoot(void)
|
||||||
if (SONOFF_BRIDGE == my_module_type) {
|
if (SONOFF_BRIDGE == my_module_type) {
|
||||||
WSContentSend_P(HTTP_TABLE100);
|
WSContentSend_P(HTTP_TABLE100);
|
||||||
WSContentSend_P(PSTR("<tr>"));
|
WSContentSend_P(PSTR("<tr>"));
|
||||||
uint8_t idx = 0;
|
uint32_t idx = 0;
|
||||||
for (uint32_t i = 0; i < 4; i++) {
|
for (uint32_t i = 0; i < 4; i++) {
|
||||||
if (idx > 0) { WSContentSend_P(PSTR("</tr><tr>")); }
|
if (idx > 0) { WSContentSend_P(PSTR("</tr><tr>")); }
|
||||||
for (uint32_t j = 0; j < 4; j++) {
|
for (uint32_t j = 0; j < 4; j++) {
|
||||||
|
@ -1010,7 +1010,7 @@ bool HandleRootStatusRefresh(void)
|
||||||
WebGetArg("o", tmp, sizeof(tmp)); // 1 - 16 Device number for button Toggle or Fanspeed
|
WebGetArg("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);
|
||||||
uint8_t device = atoi(tmp);
|
uint32_t device = atoi(tmp);
|
||||||
#ifdef USE_SONOFF_IFAN
|
#ifdef USE_SONOFF_IFAN
|
||||||
if (IsModuleIfan()) {
|
if (IsModuleIfan()) {
|
||||||
if (device < 2) {
|
if (device < 2) {
|
||||||
|
@ -1049,11 +1049,11 @@ bool HandleRootStatusRefresh(void)
|
||||||
|
|
||||||
if (devices_present) {
|
if (devices_present) {
|
||||||
WSContentSend_P(PSTR("{t}<tr>"));
|
WSContentSend_P(PSTR("{t}<tr>"));
|
||||||
uint8_t fsize = (devices_present < 5) ? 70 - (devices_present * 8) : 32;
|
uint32_t fsize = (devices_present < 5) ? 70 - (devices_present * 8) : 32;
|
||||||
#ifdef USE_SONOFF_IFAN
|
#ifdef USE_SONOFF_IFAN
|
||||||
if (IsModuleIfan()) {
|
if (IsModuleIfan()) {
|
||||||
WSContentSend_P(HTTP_DEVICE_STATE, 36, (bitRead(power, 0)) ? "bold" : "normal", 54, GetStateText(bitRead(power, 0)));
|
WSContentSend_P(HTTP_DEVICE_STATE, 36, (bitRead(power, 0)) ? "bold" : "normal", 54, GetStateText(bitRead(power, 0)));
|
||||||
uint8_t fanspeed = GetFanspeed();
|
uint32_t fanspeed = GetFanspeed();
|
||||||
snprintf_P(svalue, sizeof(svalue), PSTR("%d"), fanspeed);
|
snprintf_P(svalue, sizeof(svalue), PSTR("%d"), fanspeed);
|
||||||
WSContentSend_P(HTTP_DEVICE_STATE, 64, (fanspeed) ? "bold" : "normal", 54, (fanspeed) ? svalue : GetStateText(0));
|
WSContentSend_P(HTTP_DEVICE_STATE, 64, (fanspeed) ? "bold" : "normal", 54, (fanspeed) ? svalue : GetStateText(0));
|
||||||
} else {
|
} else {
|
||||||
|
@ -1120,7 +1120,7 @@ void HandleTemplateConfiguration(void)
|
||||||
if (WebServer->hasArg("m")) {
|
if (WebServer->hasArg("m")) {
|
||||||
WSContentBegin(200, CT_PLAIN);
|
WSContentBegin(200, CT_PLAIN);
|
||||||
for (uint32_t i = 0; i < sizeof(kModuleNiceList); i++) { // "}2'%d'>%s (%d)}3" - "}2'0'>Sonoff Basic (1)}3"
|
for (uint32_t i = 0; i < sizeof(kModuleNiceList); i++) { // "}2'%d'>%s (%d)}3" - "}2'0'>Sonoff Basic (1)}3"
|
||||||
uint8_t midx = pgm_read_byte(kModuleNiceList + i);
|
uint32_t midx = pgm_read_byte(kModuleNiceList + i);
|
||||||
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, AnyModuleName(midx).c_str(), midx +1);
|
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, AnyModuleName(midx).c_str(), midx +1);
|
||||||
}
|
}
|
||||||
WSContentEnd();
|
WSContentEnd();
|
||||||
|
@ -1129,8 +1129,8 @@ void HandleTemplateConfiguration(void)
|
||||||
|
|
||||||
WebGetArg("t", stemp, sizeof(stemp)); // 0 - 69 Template number
|
WebGetArg("t", stemp, sizeof(stemp)); // 0 - 69 Template number
|
||||||
if (strlen(stemp)) {
|
if (strlen(stemp)) {
|
||||||
uint8_t module = atoi(stemp);
|
uint32_t module = atoi(stemp);
|
||||||
uint8_t module_save = Settings.module;
|
uint32_t module_save = Settings.module;
|
||||||
Settings.module = module;
|
Settings.module = module;
|
||||||
myio cmodule;
|
myio cmodule;
|
||||||
ModuleGpios(&cmodule);
|
ModuleGpios(&cmodule);
|
||||||
|
@ -1143,7 +1143,7 @@ void HandleTemplateConfiguration(void)
|
||||||
if (1 == i) {
|
if (1 == i) {
|
||||||
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, 255, D_SENSOR_USER, 255); // }2'255'>User (255)}3
|
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, 255, D_SENSOR_USER, 255); // }2'255'>User (255)}3
|
||||||
}
|
}
|
||||||
uint8_t midx = pgm_read_byte(kGpioNiceList + i);
|
uint32_t midx = pgm_read_byte(kGpioNiceList + i);
|
||||||
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, GetTextIndexed(stemp, sizeof(stemp), midx, kSensorNames), midx);
|
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, GetTextIndexed(stemp, sizeof(stemp), midx, kSensorNames), midx);
|
||||||
}
|
}
|
||||||
WSContentSend_P(PSTR("}1")); // Field separator
|
WSContentSend_P(PSTR("}1")); // Field separator
|
||||||
|
@ -1205,7 +1205,7 @@ void TemplateSaveSettings(void)
|
||||||
WebGetArg("s1", tmp, sizeof(tmp)); // NAME
|
WebGetArg("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);
|
||||||
|
|
||||||
uint8_t j = 0;
|
uint32_t j = 0;
|
||||||
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp); i++) {
|
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp); i++) {
|
||||||
if (6 == i) { j = 9; }
|
if (6 == i) { j = 9; }
|
||||||
if (8 == i) { j = 12; }
|
if (8 == i) { j = 12; }
|
||||||
|
@ -1217,14 +1217,14 @@ void TemplateSaveSettings(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
WebGetArg("g17", tmp, sizeof(tmp)); // FLAG - ADC0
|
WebGetArg("g17", tmp, sizeof(tmp)); // FLAG - ADC0
|
||||||
uint8_t flag = atoi(tmp);
|
uint32_t flag = atoi(tmp);
|
||||||
for (uint32_t i = 0; i < GPIO_FLAG_USED; i++) {
|
for (uint32_t i = 0; i < GPIO_FLAG_USED; i++) {
|
||||||
snprintf_P(webindex, sizeof(webindex), PSTR("c%d"), i);
|
snprintf_P(webindex, sizeof(webindex), PSTR("c%d"), i);
|
||||||
uint8_t state = WebServer->hasArg(webindex) << i +4; // FLAG
|
uint32_t state = WebServer->hasArg(webindex) << i +4; // FLAG
|
||||||
flag += state;
|
flag += state;
|
||||||
}
|
}
|
||||||
WebGetArg("g99", tmp, sizeof(tmp)); // BASE
|
WebGetArg("g99", tmp, sizeof(tmp)); // BASE
|
||||||
uint8_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);
|
||||||
ExecuteWebCommand(svalue, SRC_WEBGUI);
|
ExecuteWebCommand(svalue, SRC_WEBGUI);
|
||||||
|
@ -1243,13 +1243,13 @@ void HandleModuleConfiguration(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
char stemp[30]; // Sensor name
|
char stemp[30]; // Sensor name
|
||||||
uint8_t midx;
|
uint32_t midx;
|
||||||
myio cmodule;
|
myio cmodule;
|
||||||
ModuleGpios(&cmodule);
|
ModuleGpios(&cmodule);
|
||||||
|
|
||||||
if (WebServer->hasArg("m")) {
|
if (WebServer->hasArg("m")) {
|
||||||
WSContentBegin(200, CT_PLAIN);
|
WSContentBegin(200, CT_PLAIN);
|
||||||
uint8_t vidx = 0;
|
uint32_t vidx = 0;
|
||||||
for (uint32_t i = 0; i <= sizeof(kModuleNiceList); i++) { // "}2'%d'>%s (%d)}3" - "}2'255'>UserTemplate (0)}3" - "}2'0'>Sonoff Basic (1)}3"
|
for (uint32_t i = 0; i <= sizeof(kModuleNiceList); i++) { // "}2'%d'>%s (%d)}3" - "}2'255'>UserTemplate (0)}3" - "}2'0'>Sonoff Basic (1)}3"
|
||||||
if (0 == i) {
|
if (0 == i) {
|
||||||
midx = USER_MODULE;
|
midx = USER_MODULE;
|
||||||
|
@ -1326,7 +1326,7 @@ void ModuleSaveSettings(void)
|
||||||
char webindex[5]; // WebGetArg name
|
char webindex[5]; // WebGetArg name
|
||||||
|
|
||||||
WebGetArg("g99", tmp, sizeof(tmp));
|
WebGetArg("g99", tmp, sizeof(tmp));
|
||||||
uint8_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;
|
||||||
SetModuleType();
|
SetModuleType();
|
||||||
|
@ -1361,7 +1361,7 @@ const char kEscapeCode[] PROGMEM = "&|>|<|"|'";
|
||||||
|
|
||||||
String HtmlEscape(const String unescaped) {
|
String HtmlEscape(const String unescaped) {
|
||||||
char escaped[10];
|
char escaped[10];
|
||||||
uint16_t ulen = unescaped.length();
|
size_t ulen = unescaped.length();
|
||||||
String result = "";
|
String result = "";
|
||||||
for (size_t i = 0; i < ulen; i++) {
|
for (size_t i = 0; i < ulen; i++) {
|
||||||
char c = unescaped[i];
|
char c = unescaped[i];
|
||||||
|
@ -1521,7 +1521,7 @@ void HandleLoggingConfiguration(void)
|
||||||
char stemp2[32];
|
char stemp2[32];
|
||||||
uint8_t dlevel[3] = { LOG_LEVEL_INFO, LOG_LEVEL_INFO, LOG_LEVEL_NONE };
|
uint8_t dlevel[3] = { LOG_LEVEL_INFO, LOG_LEVEL_INFO, LOG_LEVEL_NONE };
|
||||||
for (uint32_t idx = 0; idx < 3; idx++) {
|
for (uint32_t idx = 0; idx < 3; idx++) {
|
||||||
uint8_t llevel = (0==idx)?Settings.seriallog_level:(1==idx)?Settings.weblog_level:Settings.syslog_level;
|
uint32_t llevel = (0==idx)?Settings.seriallog_level:(1==idx)?Settings.weblog_level:Settings.syslog_level;
|
||||||
WSContentSend_P(PSTR("<p><b>%s</b> (%s)<br><select id='l%d'>"),
|
WSContentSend_P(PSTR("<p><b>%s</b> (%s)<br><select id='l%d'>"),
|
||||||
GetTextIndexed(stemp1, sizeof(stemp1), idx, kLoggingOptions),
|
GetTextIndexed(stemp1, sizeof(stemp1), idx, kLoggingOptions),
|
||||||
GetTextIndexed(stemp2, sizeof(stemp2), dlevel[idx], kLoggingLevels),
|
GetTextIndexed(stemp2, sizeof(stemp2), dlevel[idx], kLoggingLevels),
|
||||||
|
@ -1584,7 +1584,7 @@ void HandleOtherConfiguration(void)
|
||||||
strlcpy(stemp, mqtt_data, sizeof(stemp)); // Get JSON template
|
strlcpy(stemp, mqtt_data, sizeof(stemp)); // Get JSON template
|
||||||
WSContentSend_P(HTTP_FORM_OTHER, stemp, (USER_MODULE == Settings.module) ? " checked disabled" : "", (Settings.flag.mqtt_enabled) ? " checked" : "");
|
WSContentSend_P(HTTP_FORM_OTHER, stemp, (USER_MODULE == Settings.module) ? " checked disabled" : "", (Settings.flag.mqtt_enabled) ? " checked" : "");
|
||||||
|
|
||||||
uint8_t maxfn = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : (!devices_present) ? 1 : devices_present;
|
uint32_t maxfn = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : (!devices_present) ? 1 : devices_present;
|
||||||
#ifdef USE_SONOFF_IFAN
|
#ifdef USE_SONOFF_IFAN
|
||||||
if (IsModuleIfan()) { maxfn = 1; }
|
if (IsModuleIfan()) { maxfn = 1; }
|
||||||
#endif // USE_SONOFF_IFAN
|
#endif // USE_SONOFF_IFAN
|
||||||
|
@ -1770,7 +1770,7 @@ void HandleInformation(void)
|
||||||
WSContentSend_P(PSTR("}1" D_FLASH_WRITE_COUNT "}2%d at 0x%X"), Settings.save_flag, GetSettingsAddress());
|
WSContentSend_P(PSTR("}1" D_FLASH_WRITE_COUNT "}2%d at 0x%X"), Settings.save_flag, GetSettingsAddress());
|
||||||
WSContentSend_P(PSTR("}1" D_BOOT_COUNT "}2%d"), Settings.bootcount);
|
WSContentSend_P(PSTR("}1" D_BOOT_COUNT "}2%d"), Settings.bootcount);
|
||||||
WSContentSend_P(PSTR("}1" D_RESTART_REASON "}2%s"), GetResetReason().c_str());
|
WSContentSend_P(PSTR("}1" D_RESTART_REASON "}2%s"), GetResetReason().c_str());
|
||||||
uint8_t maxfn = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : devices_present;
|
uint32_t maxfn = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : devices_present;
|
||||||
#ifdef USE_SONOFF_IFAN
|
#ifdef USE_SONOFF_IFAN
|
||||||
if (IsModuleIfan()) { maxfn = 1; }
|
if (IsModuleIfan()) { maxfn = 1; }
|
||||||
#endif // USE_SONOFF_IFAN
|
#endif // USE_SONOFF_IFAN
|
||||||
|
@ -2089,9 +2089,9 @@ void HandleUploadLoop(void)
|
||||||
bool valid_settings = false;
|
bool valid_settings = false;
|
||||||
unsigned long buffer_version = settings_buffer[11] << 24 | settings_buffer[10] << 16 | settings_buffer[9] << 8 | settings_buffer[8];
|
unsigned long buffer_version = settings_buffer[11] << 24 | settings_buffer[10] << 16 | settings_buffer[9] << 8 | settings_buffer[8];
|
||||||
if (buffer_version > 0x06000000) {
|
if (buffer_version > 0x06000000) {
|
||||||
uint16_t buffer_size = settings_buffer[3] << 8 | settings_buffer[2];
|
uint32_t buffer_size = settings_buffer[3] << 8 | settings_buffer[2];
|
||||||
uint16_t buffer_crc = settings_buffer[15] << 8 | settings_buffer[14];
|
uint32_t buffer_crc = settings_buffer[15] << 8 | settings_buffer[14];
|
||||||
uint16_t crc = 0;
|
uint32_t crc = 0;
|
||||||
for (uint32_t i = 0; i < buffer_size; i++) {
|
for (uint32_t i = 0; i < buffer_size; i++) {
|
||||||
if ((i < 14) || (i > 15)) { crc += settings_buffer[i]*(i+1); } // Skip crc
|
if ((i < 14) || (i > 15)) { crc += settings_buffer[i]*(i+1); } // Skip crc
|
||||||
}
|
}
|
||||||
|
@ -2152,23 +2152,23 @@ void HandleHttpCommand(void)
|
||||||
|
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_COMMAND));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_COMMAND));
|
||||||
|
|
||||||
uint8_t valid = 1;
|
bool valid = true;
|
||||||
if (Settings.web_password[0] != 0) {
|
if (Settings.web_password[0] != 0) {
|
||||||
char tmp1[sizeof(Settings.web_password)];
|
char tmp1[sizeof(Settings.web_password)];
|
||||||
WebGetArg("user", tmp1, sizeof(tmp1));
|
WebGetArg("user", tmp1, sizeof(tmp1));
|
||||||
char tmp2[sizeof(Settings.web_password)];
|
char tmp2[sizeof(Settings.web_password)];
|
||||||
WebGetArg("password", tmp2, sizeof(tmp2));
|
WebGetArg("password", tmp2, sizeof(tmp2));
|
||||||
if (!(!strcmp(tmp1, WEB_USERNAME) && !strcmp(tmp2, Settings.web_password))) { valid = 0; }
|
if (!(!strcmp(tmp1, WEB_USERNAME) && !strcmp(tmp2, Settings.web_password))) { valid = false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
WSContentBegin(200, CT_JSON);
|
WSContentBegin(200, CT_JSON);
|
||||||
if (valid) {
|
if (valid) {
|
||||||
uint8_t curridx = web_log_index;
|
uint32_t curridx = web_log_index;
|
||||||
String svalue = WebServer->arg("cmnd");
|
String svalue = WebServer->arg("cmnd");
|
||||||
if (svalue.length() && (svalue.length() < INPUT_BUFFER_SIZE)) {
|
if (svalue.length() && (svalue.length() < INPUT_BUFFER_SIZE)) {
|
||||||
ExecuteWebCommand((char*)svalue.c_str(), SRC_WEBCOMMAND);
|
ExecuteWebCommand((char*)svalue.c_str(), SRC_WEBCOMMAND);
|
||||||
if (web_log_index != curridx) {
|
if (web_log_index != curridx) {
|
||||||
uint8_t counter = curridx;
|
uint32_t counter = curridx;
|
||||||
WSContentSend_P(PSTR("{"));
|
WSContentSend_P(PSTR("{"));
|
||||||
bool cflg = false;
|
bool cflg = false;
|
||||||
do {
|
do {
|
||||||
|
@ -2188,6 +2188,7 @@ void HandleHttpCommand(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
counter++;
|
counter++;
|
||||||
|
counter &= 0xFF;
|
||||||
if (!counter) counter++; // Skip 0 as it is not allowed
|
if (!counter) counter++; // Skip 0 as it is not allowed
|
||||||
} while (counter != web_log_index);
|
} while (counter != web_log_index);
|
||||||
WSContentSend_P(PSTR("}"));
|
WSContentSend_P(PSTR("}"));
|
||||||
|
@ -2227,7 +2228,7 @@ void HandleConsole(void)
|
||||||
void HandleConsoleRefresh(void)
|
void HandleConsoleRefresh(void)
|
||||||
{
|
{
|
||||||
bool cflg = true;
|
bool cflg = true;
|
||||||
uint8_t counter = 0; // Initial start, should never be 0 again
|
uint32_t counter = 0; // Initial start, should never be 0 again
|
||||||
|
|
||||||
String svalue = WebServer->arg("c1");
|
String svalue = WebServer->arg("c1");
|
||||||
if (svalue.length() && (svalue.length() < INPUT_BUFFER_SIZE)) {
|
if (svalue.length() && (svalue.length() < INPUT_BUFFER_SIZE)) {
|
||||||
|
@ -2262,6 +2263,7 @@ void HandleConsoleRefresh(void)
|
||||||
cflg = true;
|
cflg = true;
|
||||||
}
|
}
|
||||||
counter++;
|
counter++;
|
||||||
|
counter &= 0xFF;
|
||||||
if (!counter) { counter++; } // Skip log index 0 as it is not allowed
|
if (!counter) { counter++; } // Skip log index 0 as it is not allowed
|
||||||
} while (counter != web_log_index);
|
} while (counter != web_log_index);
|
||||||
}
|
}
|
||||||
|
@ -2399,7 +2401,7 @@ int WebSend(char *buffer)
|
||||||
/*
|
/*
|
||||||
// Return received data to the user - Adds 900+ bytes to the code
|
// Return received data to the user - Adds 900+ bytes to the code
|
||||||
String result = http.getString(); // File found at server - may need lot of ram or trigger out of memory!
|
String result = http.getString(); // File found at server - may need lot of ram or trigger out of memory!
|
||||||
uint16_t j = 0;
|
uint32_t j = 0;
|
||||||
for (uint32_t i = 0; i < result.length(); i++) {
|
for (uint32_t i = 0; i < result.length(); i++) {
|
||||||
char text = result.charAt(i);
|
char text = result.charAt(i);
|
||||||
if (text > 31) { // Remove control characters like linefeed
|
if (text > 31) { // Remove control characters like linefeed
|
||||||
|
@ -2493,7 +2495,7 @@ bool WebCommand(void)
|
||||||
}
|
}
|
||||||
else if (CMND_WEBSEND == command_code) {
|
else if (CMND_WEBSEND == command_code) {
|
||||||
if (XdrvMailbox.data_len > 0) {
|
if (XdrvMailbox.data_len > 0) {
|
||||||
uint8_t result = WebSend(XdrvMailbox.data);
|
uint32_t result = WebSend(XdrvMailbox.data);
|
||||||
char stemp1[20];
|
char stemp1[20];
|
||||||
Response_P(S_JSON_COMMAND_SVALUE, command, GetTextIndexed(stemp1, sizeof(stemp1), result, kWebSendStatus));
|
Response_P(S_JSON_COMMAND_SVALUE, command, GetTextIndexed(stemp1, sizeof(stemp1), result, kWebSendStatus));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue