From e5ecffe4dd0e6403fadadf165a82bccce2cdd530 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 3 Aug 2019 13:01:34 +0200 Subject: [PATCH] Refactor commands Refactor commands --- sonoff/support_command.ino | 124 +++++++++++++++++++------------ sonoff/xdrv_01_webserver.ino | 12 +-- sonoff/xdrv_02_mqtt.ino | 40 +++++----- sonoff/xdrv_04_light.ino | 34 ++++----- sonoff/xdrv_05_irremote.ino | 8 +- sonoff/xdrv_06_snfbridge.ino | 12 +-- sonoff/xdrv_08_serial_bridge.ino | 4 +- sonoff/xdrv_09_timers.ino | 8 +- sonoff/xdrv_10_rules.ino | 20 ++--- sonoff/xdrv_11_knx.ino | 12 +-- sonoff/xdrv_22_sonoff_ifan.ino | 5 +- sonoff/xdrv_99_debug.ino | 27 ++++--- sonoff/xsns_01_counter.ino | 9 +-- 13 files changed, 172 insertions(+), 143 deletions(-) diff --git a/sonoff/support_command.ino b/sonoff/support_command.ino index c05731545..1e84f9fce 100644 --- a/sonoff/support_command.ino +++ b/sonoff/support_command.ino @@ -49,6 +49,38 @@ void (* const TasmotaCommand[])(void) PROGMEM = { /********************************************************************************************/ +void ResponseCmndNumber(int value) +{ + Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, value); +} + +void ResponseCmndIdxNumber(int value) +{ + Response_P(S_JSON_COMMAND_INDEX_NVALUE, XdrvMailbox.command, XdrvMailbox.index, value); +} + +void ResponseCmndChar(const char* value) +{ + Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, value); +} + +void ResponseCmndStateText(uint32_t value) +{ + ResponseCmndChar(GetStateText(value)); +} + +void ResponseCmndDone(void) +{ + ResponseCmndChar(D_JSON_DONE); +} + +void ResponseCmndIdxChar(const char* value) +{ + Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, value); +} + +/********************************************************************************************/ + void ExecuteCommand(char *cmnd, uint32_t source) { char *start; @@ -202,12 +234,12 @@ void CmndBacklog(void) } blcommand = strtok(nullptr, ";"); } -// Response_P(S_JSON_COMMAND_SVALUE, command, D_JSON_APPENDED); +// ResponseCmndChar(D_JSON_APPENDED); mqtt_data[0] = '\0'; } else { bool blflag = (backlog_pointer == backlog_index); backlog_pointer = backlog_index; - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, blflag ? D_JSON_EMPTY : D_JSON_ABORTED); + ResponseCmndChar(blflag ? D_JSON_EMPTY : D_JSON_ABORTED); } } @@ -219,7 +251,7 @@ void CmndDelay(void) uint32_t bl_delay = 0; long bl_delta = TimePassedSince(backlog_delay); if (bl_delta < 0) { bl_delay = (bl_delta *-1) / 100; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, bl_delay); + ResponseCmndNumber(bl_delay); } void CmndPower(void) @@ -400,7 +432,7 @@ void CmndOtaUrl(void) if ((XdrvMailbox.data_len > 0) && (XdrvMailbox.data_len < sizeof(Settings.ota_url))) { strlcpy(Settings.ota_url, (SC_DEFAULT == Shortcut()) ? OTA_URL : XdrvMailbox.data, sizeof(Settings.ota_url)); } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, Settings.ota_url); + ResponseCmndChar(Settings.ota_url); } void CmndSeriallog(void) @@ -417,14 +449,14 @@ void CmndRestart(void) switch (XdrvMailbox.payload) { case 1: restart_flag = 2; - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, D_JSON_RESTARTING); + ResponseCmndChar(D_JSON_RESTARTING); break; case 99: AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_RESTARTING)); EspRestart(); break; default: - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, D_JSON_ONE_TO_RESTART); + ResponseCmndChar(D_JSON_ONE_TO_RESTART); } } @@ -446,7 +478,7 @@ void CmndPowerOnState(void) } } } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.poweronstate); + ResponseCmndNumber(Settings.poweronstate); } } @@ -467,7 +499,7 @@ void CmndBlinktime(void) Settings.blinktime = XdrvMailbox.payload; if (blink_timer > 0) { blink_timer = millis() + (100 * XdrvMailbox.payload); } } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.blinktime); + ResponseCmndNumber(Settings.blinktime); } void CmndBlinkcount(void) @@ -476,7 +508,7 @@ void CmndBlinkcount(void) Settings.blinkcount = XdrvMailbox.payload; // 0 - 65535 if (blink_counter) { blink_counter = Settings.blinkcount *2; } } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.blinkcount); + ResponseCmndNumber(Settings.blinkcount); } void CmndSavedata(void) @@ -490,7 +522,7 @@ void CmndSavedata(void) if (Settings.save_data > 1) { snprintf_P(stemp1, sizeof(stemp1), PSTR(D_JSON_EVERY " %d " D_UNIT_SECOND), Settings.save_data); } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, (Settings.save_data > 1) ? stemp1 : GetStateText(Settings.save_data)); + ResponseCmndChar((Settings.save_data > 1) ? stemp1 : GetStateText(Settings.save_data)); } void CmndSetoption(void) @@ -593,7 +625,7 @@ void CmndSetoption(void) if (ptype < 99) { char stemp1[TOPSZ]; if (2 == ptype) { snprintf_P(stemp1, sizeof(stemp1), PSTR("%d"), Settings.param[pindex]); } - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, (2 == ptype) ? stemp1 : (1 == ptype) ? GetStateText(bitRead(Settings.flag3.data, pindex)) : GetStateText(bitRead(Settings.flag.data, pindex))); + ResponseCmndIdxChar((2 == ptype) ? stemp1 : (1 == ptype) ? GetStateText(bitRead(Settings.flag3.data, pindex)) : GetStateText(bitRead(Settings.flag.data, pindex))); } } } @@ -603,7 +635,7 @@ void CmndTemperatureResolution(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3)) { Settings.flag2.temperature_resolution = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.flag2.temperature_resolution); + ResponseCmndNumber(Settings.flag2.temperature_resolution); } void CmndHumidityResolution(void) @@ -611,7 +643,7 @@ void CmndHumidityResolution(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3)) { Settings.flag2.humidity_resolution = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.flag2.humidity_resolution); + ResponseCmndNumber(Settings.flag2.humidity_resolution); } void CmndPressureResolution(void) @@ -619,7 +651,7 @@ void CmndPressureResolution(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3)) { Settings.flag2.pressure_resolution = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.flag2.pressure_resolution); + ResponseCmndNumber(Settings.flag2.pressure_resolution); } void CmndPowerResolution(void) @@ -627,7 +659,7 @@ void CmndPowerResolution(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3)) { Settings.flag2.wattage_resolution = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.flag2.wattage_resolution); + ResponseCmndNumber(Settings.flag2.wattage_resolution); } void CmndVoltageResolution(void) @@ -635,7 +667,7 @@ void CmndVoltageResolution(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3)) { Settings.flag2.voltage_resolution = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.flag2.voltage_resolution); + ResponseCmndNumber(Settings.flag2.voltage_resolution); } void CmndFrequencyResolution(void) @@ -643,7 +675,7 @@ void CmndFrequencyResolution(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3)) { Settings.flag2.frequency_resolution = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.flag2.frequency_resolution); + ResponseCmndNumber(Settings.flag2.frequency_resolution); } void CmndCurrentResolution(void) @@ -651,7 +683,7 @@ void CmndCurrentResolution(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3)) { Settings.flag2.current_resolution = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.flag2.current_resolution); + ResponseCmndNumber(Settings.flag2.current_resolution); } void CmndEnergyResolution(void) @@ -659,7 +691,7 @@ void CmndEnergyResolution(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 5)) { Settings.flag2.energy_resolution = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.flag2.energy_resolution); + ResponseCmndNumber(Settings.flag2.energy_resolution); } void CmndWeightResolution(void) @@ -667,7 +699,7 @@ void CmndWeightResolution(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3)) { Settings.flag2.weight_resolution = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.flag2.weight_resolution); + ResponseCmndNumber(Settings.flag2.weight_resolution); } void CmndModule(void) @@ -754,7 +786,7 @@ void CmndGpio(void) if (jsflg) { ResponseJsonEnd(); } else { - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, D_JSON_NOT_SUPPORTED); + ResponseCmndChar(D_JSON_NOT_SUPPORTED); } } } @@ -825,7 +857,7 @@ void CmndTemplate(void) if (JsonTemplate(XdrvMailbox.data)) { // Free 336 bytes StaticJsonBuffer stack space by moving code to function if (USER_MODULE == Settings.module) { restart_flag = 2; } } else { - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, D_JSON_INVALID_JSON); + ResponseCmndChar(D_JSON_INVALID_JSON); error = true; } } @@ -851,7 +883,7 @@ void CmndPwmfrequency(void) Settings.pwm_frequency = (1 == XdrvMailbox.payload) ? PWM_FREQ : XdrvMailbox.payload; analogWriteFreq(Settings.pwm_frequency); // Default is 1000 (core_esp8266_wiring_pwm.c) } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.pwm_frequency); + ResponseCmndNumber(Settings.pwm_frequency); } void CmndPwmrange(void) @@ -865,7 +897,7 @@ void CmndPwmrange(void) } analogWriteRange(Settings.pwm_range); // Default is 1023 (Arduino.h) } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.pwm_range); + ResponseCmndNumber(Settings.pwm_range); } void CmndButtonDebounce(void) @@ -873,7 +905,7 @@ void CmndButtonDebounce(void) if ((XdrvMailbox.payload > 39) && (XdrvMailbox.payload < 1001)) { Settings.button_debounce = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.button_debounce); + ResponseCmndNumber(Settings.button_debounce); } void CmndSwitchDebounce(void) @@ -881,7 +913,7 @@ void CmndSwitchDebounce(void) if ((XdrvMailbox.payload > 39) && (XdrvMailbox.payload < 1001)) { Settings.switch_debounce = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.switch_debounce); + ResponseCmndNumber(Settings.switch_debounce); } void CmndBaudrate(void) @@ -891,7 +923,7 @@ void CmndBaudrate(void) baudrate = XdrvMailbox.payload * 1200; SetSerialBaudrate(baudrate); } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.baudrate * 1200); + ResponseCmndNumber(Settings.baudrate * 1200); } void CmndSerialSend(void) @@ -916,7 +948,7 @@ void CmndSerialSend(void) else if (5 == XdrvMailbox.index) { SerialSendRaw(RemoveSpace(XdrvMailbox.data)); // "AA004566" as hex values } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, D_JSON_DONE); + ResponseCmndDone(); } } } @@ -932,7 +964,7 @@ void CmndSerialDelimiter(void) Settings.serial_delimiter = XdrvMailbox.data[0]; } } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.serial_delimiter); + ResponseCmndNumber(Settings.serial_delimiter); } void CmndSyslog(void) @@ -948,7 +980,7 @@ void CmndLoghost(void) if ((XdrvMailbox.data_len > 0) && (XdrvMailbox.data_len < sizeof(Settings.syslog_host))) { strlcpy(Settings.syslog_host, (SC_DEFAULT == Shortcut()) ? SYS_LOG_HOST : XdrvMailbox.data, sizeof(Settings.syslog_host)); } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, Settings.syslog_host); + ResponseCmndChar(Settings.syslog_host); } void CmndLogport(void) @@ -956,7 +988,7 @@ void CmndLogport(void) if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 65536)) { Settings.syslog_port = (1 == XdrvMailbox.payload) ? SYS_LOG_PORT : XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.syslog_port); + ResponseCmndNumber(Settings.syslog_port); } void CmndIpAddress(void) @@ -986,7 +1018,7 @@ void CmndNtpServer(void) // restart_flag = 2; // Issue #3890 ntp_force_sync = true; } - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, Settings.ntp_server[XdrvMailbox.index -1]); + ResponseCmndIdxChar(Settings.ntp_server[XdrvMailbox.index -1]); } } @@ -1016,7 +1048,7 @@ void CmndSsid(void) Settings.sta_active = XdrvMailbox.index -1; restart_flag = 2; } - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, Settings.sta_ssid[XdrvMailbox.index -1]); + ResponseCmndIdxChar(Settings.sta_ssid[XdrvMailbox.index -1]); } } @@ -1029,7 +1061,7 @@ void CmndPassword(void) sizeof(Settings.sta_pwd[0])); Settings.sta_active = XdrvMailbox.index -1; restart_flag = 2; - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, Settings.sta_pwd[XdrvMailbox.index -1]); + ResponseCmndIdxChar(Settings.sta_pwd[XdrvMailbox.index -1]); } else { Response_P(S_JSON_COMMAND_INDEX_ASTERISK, XdrvMailbox.command, XdrvMailbox.index); } @@ -1045,7 +1077,7 @@ void CmndHostname(void) } restart_flag = 2; } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, Settings.hostname); + ResponseCmndChar(Settings.hostname); } void CmndWifiConfig(void) @@ -1078,7 +1110,7 @@ void CmndFriendlyname(void) } strlcpy(Settings.friendlyname[XdrvMailbox.index -1], (SC_DEFAULT == Shortcut()) ? stemp1 : XdrvMailbox.data, sizeof(Settings.friendlyname[XdrvMailbox.index -1])); } - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, Settings.friendlyname[XdrvMailbox.index -1]); + ResponseCmndIdxChar(Settings.friendlyname[XdrvMailbox.index -1]); } } @@ -1088,7 +1120,7 @@ void CmndSwitchMode(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < MAX_SWITCH_OPTION)) { Settings.switchmode[XdrvMailbox.index -1] = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_INDEX_NVALUE, XdrvMailbox.command, XdrvMailbox.index, Settings.switchmode[XdrvMailbox.index-1]); + ResponseCmndIdxNumber(Settings.switchmode[XdrvMailbox.index-1]); } } @@ -1160,7 +1192,7 @@ void CmndInterlock(void) ResponseAppend_P(PSTR("\"}")); } else { Settings.flag.interlock = 0; - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, GetStateText(Settings.flag.interlock)); + ResponseCmndStateText(Settings.flag.interlock); } } @@ -1179,14 +1211,14 @@ void CmndReset(void) switch (XdrvMailbox.payload) { case 1: restart_flag = 211; - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command , D_JSON_RESET_AND_RESTARTING); + ResponseCmndChar(D_JSON_RESET_AND_RESTARTING); break; case 2 ... 6: restart_flag = 210 + XdrvMailbox.payload; Response_P(PSTR("{\"" D_CMND_RESET "\":\"" D_JSON_ERASE ", " D_JSON_RESET_AND_RESTARTING "\"}")); break; default: - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, D_JSON_ONE_TO_RESET); + ResponseCmndChar(D_JSON_ONE_TO_RESET); } } @@ -1219,11 +1251,11 @@ void CmndTimezone(void) ntp_force_sync = true; } if (99 == Settings.timezone) { - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.timezone); + ResponseCmndNumber(Settings.timezone); } else { char stemp1[TOPSZ]; snprintf_P(stemp1, sizeof(stemp1), PSTR("%+03d:%02d"), Settings.timezone, Settings.timezone_minutes); - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, stemp1); + ResponseCmndChar(stemp1); } } @@ -1283,7 +1315,7 @@ void CmndAltitude(void) if ((XdrvMailbox.data_len > 0) && ((XdrvMailbox.payload >= -30000) && (XdrvMailbox.payload <= 30000))) { Settings.altitude = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.altitude); + ResponseCmndNumber(Settings.altitude); } void CmndLedPower(void) @@ -1318,7 +1350,7 @@ void CmndLedPower(void) if (99 == pin[GPIO_LEDLNK]) { state = bitRead(Settings.ledstate, 3); } - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, GetStateText(state)); + ResponseCmndIdxChar(GetStateText(state)); } } @@ -1331,7 +1363,7 @@ void CmndLedState(void) SetLedLink(0); } } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.ledstate); + ResponseCmndNumber(Settings.ledstate); } void CmndLedMask(void) @@ -1341,7 +1373,7 @@ void CmndLedMask(void) } char stemp1[TOPSZ]; snprintf_P(stemp1, sizeof(stemp1), PSTR("%d (0x%04X)"), Settings.ledmask, Settings.ledmask); - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, stemp1); + ResponseCmndChar(stemp1); } #ifdef USE_I2C diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index c48d145c5..591fa8da2 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -2487,7 +2487,7 @@ void CmndEmulation(void) Settings.flag2.emulation = XdrvMailbox.payload; restart_flag = 2; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.flag2.emulation); + ResponseCmndNumber(Settings.flag2.emulation); } #endif // USE_EMULATION @@ -2500,7 +2500,7 @@ void CmndWebServer(void) 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, my_hostname, WiFi.localIP().toString().c_str()); } else { - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, GetStateText(0)); + ResponseCmndStateText(0); } } @@ -2508,7 +2508,7 @@ void CmndWebPassword(void) { if ((XdrvMailbox.data_len > 0) && (XdrvMailbox.data_len < sizeof(Settings.web_password))) { strlcpy(Settings.web_password, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? WEB_PASSWORD : XdrvMailbox.data, sizeof(Settings.web_password)); - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, Settings.web_password); + ResponseCmndChar(Settings.web_password); } else { Response_P(S_JSON_COMMAND_ASTERISK, XdrvMailbox.command); } @@ -2519,7 +2519,7 @@ void CmndWeblog(void) if ((XdrvMailbox.payload >= LOG_LEVEL_NONE) && (XdrvMailbox.payload <= LOG_LEVEL_ALL)) { Settings.weblog_level = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.weblog_level); + ResponseCmndNumber(Settings.weblog_level); } void CmndWebRefresh(void) @@ -2527,7 +2527,7 @@ void CmndWebRefresh(void) if ((XdrvMailbox.payload > 999) && (XdrvMailbox.payload <= 10000)) { Settings.web_refresh = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.web_refresh); + ResponseCmndNumber(Settings.web_refresh); } void CmndWebSend(void) @@ -2535,7 +2535,7 @@ void CmndWebSend(void) if (XdrvMailbox.data_len > 0) { uint32_t result = WebSend(XdrvMailbox.data); char stemp1[20]; - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, GetTextIndexed(stemp1, sizeof(stemp1), result, kWebSendStatus)); + ResponseCmndChar(GetTextIndexed(stemp1, sizeof(stemp1), result, kWebSendStatus)); } } diff --git a/sonoff/xdrv_02_mqtt.ino b/sonoff/xdrv_02_mqtt.ino index 13dab5719..7d7976ea8 100644 --- a/sonoff/xdrv_02_mqtt.ino +++ b/sonoff/xdrv_02_mqtt.ino @@ -684,7 +684,7 @@ void CmndMqttFingerprint(void) for (uint32_t i = 0; i < sizeof(Settings.mqtt_fingerprint[XdrvMailbox.index -1]); i++) { snprintf_P(fingerprint, sizeof(fingerprint), PSTR("%s%s%02X"), fingerprint, (i) ? " " : "", Settings.mqtt_fingerprint[XdrvMailbox.index -1][i]); } - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, fingerprint); + ResponseCmndIdxChar(fingerprint); } } #endif @@ -696,14 +696,14 @@ void CmndMqttUser(void) strlcpy(Settings.mqtt_user, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? MQTT_USER : XdrvMailbox.data, sizeof(Settings.mqtt_user)); restart_flag = 2; } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, Settings.mqtt_user); + ResponseCmndChar(Settings.mqtt_user); } void CmndMqttPassword(void) { if ((XdrvMailbox.data_len > 0) && (XdrvMailbox.data_len < sizeof(Settings.mqtt_pwd))) { strlcpy(Settings.mqtt_pwd, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? MQTT_PASS : XdrvMailbox.data, sizeof(Settings.mqtt_pwd)); - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, Settings.mqtt_pwd); + ResponseCmndChar(Settings.mqtt_pwd); restart_flag = 2; } else { Response_P(S_JSON_COMMAND_ASTERISK, XdrvMailbox.command); @@ -718,13 +718,13 @@ void CmndMqttHost(void) setLongMqttHost((SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? MQTT_HOST : XdrvMailbox.data); restart_flag = 2; } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, AWS_endpoint); + ResponseCmndChar(AWS_endpoint); #else if ((XdrvMailbox.data_len > 0) && (XdrvMailbox.data_len < sizeof(Settings.mqtt_host))) { strlcpy(Settings.mqtt_host, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? MQTT_HOST : XdrvMailbox.data, sizeof(Settings.mqtt_host)); restart_flag = 2; } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, Settings.mqtt_host); + ResponseCmndChar(Settings.mqtt_host); #endif } @@ -734,7 +734,7 @@ void CmndMqttPort(void) Settings.mqtt_port = (1 == XdrvMailbox.payload) ? MQTT_PORT : XdrvMailbox.payload; restart_flag = 2; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.mqtt_port); + ResponseCmndNumber(Settings.mqtt_port); } void CmndMqttRetry(void) @@ -743,7 +743,7 @@ void CmndMqttRetry(void) Settings.mqtt_retry = XdrvMailbox.payload; mqtt_retry_counter = Settings.mqtt_retry; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.mqtt_retry); + ResponseCmndNumber(Settings.mqtt_retry); } void CmndStateText(void) @@ -755,7 +755,7 @@ void CmndStateText(void) } strlcpy(Settings.state_text[XdrvMailbox.index -1], XdrvMailbox.data, sizeof(Settings.state_text[0])); } - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, GetStateText(XdrvMailbox.index -1)); + ResponseCmndIdxChar(GetStateText(XdrvMailbox.index -1)); } } @@ -765,7 +765,7 @@ void CmndMqttClient(void) strlcpy(Settings.mqtt_client, (SC_DEFAULT == Shortcut()) ? MQTT_CLIENT_ID : XdrvMailbox.data, sizeof(Settings.mqtt_client)); restart_flag = 2; } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, Settings.mqtt_client); + ResponseCmndChar(Settings.mqtt_client); } void CmndFullTopic(void) @@ -782,7 +782,7 @@ void CmndFullTopic(void) restart_flag = 2; } } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, Settings.mqtt_fulltopic); + ResponseCmndChar(Settings.mqtt_fulltopic); } void CmndPrefix(void) @@ -794,7 +794,7 @@ void CmndPrefix(void) // if (Settings.mqtt_prefix[XdrvMailbox.index -1][strlen(Settings.mqtt_prefix[XdrvMailbox.index -1])] == '/') Settings.mqtt_prefix[XdrvMailbox.index -1][strlen(Settings.mqtt_prefix[XdrvMailbox.index -1])] = 0; restart_flag = 2; } - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, Settings.mqtt_prefix[XdrvMailbox.index -1]); + ResponseCmndIdxChar(Settings.mqtt_prefix[XdrvMailbox.index -1]); } } @@ -812,7 +812,7 @@ void CmndPublish(void) mqtt_data[0] = '\0'; } MqttPublishDirect(stemp1, (XdrvMailbox.index == 2)); -// Response_P(S_JSON_COMMAND_SVALUE, command, D_JSON_DONE); +// ResponseCmndDone(); mqtt_data[0] = '\0'; } } @@ -826,7 +826,7 @@ void CmndGroupTopic(void) strlcpy(Settings.mqtt_grptopic, (SC_DEFAULT == Shortcut()) ? MQTT_GRPTOPIC : XdrvMailbox.data, sizeof(Settings.mqtt_grptopic)); restart_flag = 2; } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, Settings.mqtt_grptopic); + ResponseCmndChar(Settings.mqtt_grptopic); } void CmndTopic(void) @@ -843,7 +843,7 @@ void CmndTopic(void) restart_flag = 2; } } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, Settings.mqtt_topic); + ResponseCmndChar(Settings.mqtt_topic); } void CmndButtonTopic(void) @@ -858,7 +858,7 @@ void CmndButtonTopic(void) default: strlcpy(Settings.button_topic, XdrvMailbox.data, sizeof(Settings.button_topic)); } } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, Settings.button_topic); + ResponseCmndChar(Settings.button_topic); } void CmndSwitchTopic(void) @@ -873,7 +873,7 @@ void CmndSwitchTopic(void) default: strlcpy(Settings.switch_topic, XdrvMailbox.data, sizeof(Settings.switch_topic)); } } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, Settings.switch_topic); + ResponseCmndChar(Settings.switch_topic); } void CmndButtonRetain(void) @@ -886,7 +886,7 @@ void CmndButtonRetain(void) } Settings.flag.mqtt_button_retain = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, GetStateText(Settings.flag.mqtt_button_retain)); + ResponseCmndStateText(Settings.flag.mqtt_button_retain); } void CmndSwitchRetain(void) @@ -899,7 +899,7 @@ void CmndSwitchRetain(void) } Settings.flag.mqtt_switch_retain = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, GetStateText(Settings.flag.mqtt_switch_retain)); + ResponseCmndStateText(Settings.flag.mqtt_switch_retain); } void CmndPowerRetain(void) @@ -916,7 +916,7 @@ void CmndPowerRetain(void) } Settings.flag.mqtt_power_retain = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, GetStateText(Settings.flag.mqtt_power_retain)); + ResponseCmndStateText(Settings.flag.mqtt_power_retain); } void CmndSensorRetain(void) @@ -929,7 +929,7 @@ void CmndSensorRetain(void) } Settings.flag.mqtt_sensor_retain = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, GetStateText(Settings.flag.mqtt_sensor_retain)); + ResponseCmndStateText(Settings.flag.mqtt_sensor_retain); } /*********************************************************************************************\ diff --git a/sonoff/xdrv_04_light.ino b/sonoff/xdrv_04_light.ino index 3889ad475..dc223c327 100644 --- a/sonoff/xdrv_04_light.ino +++ b/sonoff/xdrv_04_light.ino @@ -2069,7 +2069,7 @@ void CmndSupportColor(void) } char scolor[LIGHT_COLOR_SIZE]; if (!valid_entry && (XdrvMailbox.index <= 2)) { - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, LightGetColor(scolor)); + ResponseCmndChar(LightGetColor(scolor)); } if (XdrvMailbox.index >= 3) { scolor[0] = '\0'; @@ -2080,7 +2080,7 @@ void CmndSupportColor(void) snprintf_P(scolor, sizeof(scolor), PSTR("%s%02X"), scolor, Settings.ws_color[XdrvMailbox.index -3][i]); } } - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, scolor); + ResponseCmndIdxChar(scolor); } if (coldim) { LightPreparePower(); @@ -2125,7 +2125,7 @@ void CmndChannel(void) light_controller.changeChannels(light_current_color); coldim = true; } - Response_P(S_JSON_COMMAND_INDEX_NVALUE, XdrvMailbox.command, XdrvMailbox.index, light_current_color[XdrvMailbox.index -1] * 100 / 255); + ResponseCmndIdxNumber(light_current_color[XdrvMailbox.index -1] * 100 / 255); if (coldim) { LightPreparePower(); } @@ -2204,7 +2204,7 @@ void CmndLed(void) Ws2812ForceUpdate(); } char scolor[LIGHT_COLOR_SIZE]; - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, Ws2812GetColor(XdrvMailbox.index, scolor)); + ResponseCmndIdxChar(Ws2812GetColor(XdrvMailbox.index, scolor)); } } @@ -2217,7 +2217,7 @@ void CmndPixels(void) Ws2812Clear(); light_update = 1; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.light_pixels); + ResponseCmndNumber(Settings.light_pixels); } } @@ -2227,7 +2227,7 @@ void CmndRotation(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < Settings.light_pixels)) { Settings.light_rotation = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.light_rotation); + ResponseCmndNumber(Settings.light_rotation); } } @@ -2238,12 +2238,12 @@ void CmndWidth(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 4)) { Settings.light_width = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.light_width); + ResponseCmndNumber(Settings.light_width); } else { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32)) { Settings.ws_width[XdrvMailbox.index -2] = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_INDEX_NVALUE, XdrvMailbox.command, XdrvMailbox.index, Settings.ws_width[XdrvMailbox.index -2]); + ResponseCmndIdxNumber(Settings.ws_width[XdrvMailbox.index -2]); } } } @@ -2271,7 +2271,7 @@ void CmndScheme(void) // Publish state message for Hass if (Settings.flag3.hass_tele_on_power) { MqttPublishTeleState(); } } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.light_scheme); + ResponseCmndNumber(Settings.light_scheme); } } @@ -2283,7 +2283,7 @@ void CmndWakeup(void) light_wakeup_active = 3; Settings.light_scheme = LS_WAKEUP; LightPowerOn(); - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, D_JSON_STARTED); + ResponseCmndChar(D_JSON_STARTED); } void CmndColorTemperature(void) @@ -2302,7 +2302,7 @@ void CmndColorTemperature(void) light_controller.changeCTB(XdrvMailbox.payload, light_state.getBri()); LightPreparePower(); } else { - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, ct); + ResponseCmndNumber(ct); } } } @@ -2323,7 +2323,7 @@ void CmndDimmer(void) light_update = 1; LightPreparePower(); } else { - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.light_dimmer); + ResponseCmndNumber(Settings.light_dimmer); } } @@ -2341,7 +2341,7 @@ void CmndLedTable(void) } light_update = 1; } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, GetStateText(Settings.light_correction)); + ResponseCmndStateText(Settings.light_correction); } void CmndRgbwwTable(void) @@ -2368,7 +2368,7 @@ void CmndRgbwwTable(void) for (uint32_t i = 0; i < LST_RGBWC; i++) { snprintf_P(scolor, sizeof(scolor), PSTR("%s%s%d"), scolor, (i > 0) ? "," : "", Settings.rgbwwTable[i]); } - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, scolor); + ResponseCmndIdxChar(scolor); } void CmndFade(void) @@ -2382,7 +2382,7 @@ void CmndFade(void) Settings.light_fade ^= 1; break; } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, GetStateText(Settings.light_fade)); + ResponseCmndStateText(Settings.light_fade); } void CmndSpeed(void) @@ -2398,7 +2398,7 @@ void CmndSpeed(void) if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload <= STATES)) { Settings.light_speed = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.light_speed); + ResponseCmndNumber(Settings.light_speed); } void CmndWakeupDuration(void) @@ -2407,7 +2407,7 @@ void CmndWakeupDuration(void) Settings.light_wakeup = XdrvMailbox.payload; light_wakeup_active = 0; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.light_wakeup); + ResponseCmndNumber(Settings.light_wakeup); } void CmndUndocA(void) diff --git a/sonoff/xdrv_05_irremote.ino b/sonoff/xdrv_05_irremote.ino index 29f4bbbc3..1017cba7e 100644 --- a/sonoff/xdrv_05_irremote.ino +++ b/sonoff/xdrv_05_irremote.ino @@ -966,7 +966,7 @@ uint32_t IrRemoteCmndIrSendJson(void) #endif // USE_IR_SEND_PIONEER default: irsend_active = false; - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, D_JSON_PROTOCOL_NOT_SUPPORTED); + ResponseCmndChar(D_JSON_PROTOCOL_NOT_SUPPORTED); } return IE_NO_ERROR; @@ -991,10 +991,10 @@ void IrRemoteCmndResponse(uint32_t error) { switch (error) { case IE_INVALID_RAWDATA: - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, D_JSON_INVALID_RAWDATA); + ResponseCmndChar(D_JSON_INVALID_RAWDATA); break; case IE_INVALID_JSON: - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, D_JSON_INVALID_JSON); + ResponseCmndChar(D_JSON_INVALID_JSON); break; case IE_SYNTAX_IRSEND: Response_P(PSTR("{\"" D_CMND_IRSEND "\":\"" D_JSON_NO " " D_JSON_IR_PROTOCOL ", " D_JSON_IR_BITS " " D_JSON_OR " " D_JSON_IR_DATA "\"}")); @@ -1005,7 +1005,7 @@ void IrRemoteCmndResponse(uint32_t error) break; #endif // USE_IR_HVAC default: // IE_NO_ERROR - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, D_JSON_DONE); + ResponseCmndDone(); } } diff --git a/sonoff/xdrv_06_snfbridge.ino b/sonoff/xdrv_06_snfbridge.ino index 2948dabfc..01edfea76 100644 --- a/sonoff/xdrv_06_snfbridge.ino +++ b/sonoff/xdrv_06_snfbridge.ino @@ -501,11 +501,11 @@ void CmndRfKey(void) sonoff_bridge_learn_active = 0; if (2 == XdrvMailbox.payload) { // Learn RF data SonoffBridgeLearn(XdrvMailbox.index); - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, D_JSON_START_LEARNING); + ResponseCmndIdxChar(D_JSON_START_LEARNING); } else if (3 == XdrvMailbox.payload) { // Unlearn RF data Settings.rf_code[XdrvMailbox.index][0] = 0; // Reset sync_time MSB - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, D_JSON_SET_TO_DEFAULT); + ResponseCmndIdxChar(D_JSON_SET_TO_DEFAULT); } else if (4 == XdrvMailbox.payload) { // Save RF data provided by RFSync, RfLow, RfHigh and last RfCode for (uint32_t i = 0; i < 6; i++) { @@ -514,7 +514,7 @@ void CmndRfKey(void) Settings.rf_code[XdrvMailbox.index][6] = (sonoff_bridge_last_send_code >> 16) & 0xff; Settings.rf_code[XdrvMailbox.index][7] = (sonoff_bridge_last_send_code >> 8) & 0xff; Settings.rf_code[XdrvMailbox.index][8] = sonoff_bridge_last_send_code & 0xff; - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, D_JSON_SAVED); + ResponseCmndIdxChar(D_JSON_SAVED); } else if (5 == XdrvMailbox.payload) { // Show default or learned RF data uint8_t key = XdrvMailbox.index; uint8_t index = (0 == Settings.rf_code[key][0]) ? 0 : key; // Use default if sync_time MSB = 0 @@ -533,10 +533,10 @@ void CmndRfKey(void) } else { if ((1 == XdrvMailbox.payload) || (0 == Settings.rf_code[XdrvMailbox.index][0])) { // Test sync_time MSB SonoffBridgeSend(0, XdrvMailbox.index); // Send default RF data - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, D_JSON_DEFAULT_SENT); + ResponseCmndIdxChar(D_JSON_DEFAULT_SENT); } else { SonoffBridgeSend(XdrvMailbox.index, 0); // Send learned RF data - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, D_JSON_LEARNED_SENT); + ResponseCmndIdxChar(D_JSON_LEARNED_SENT); } } } else { @@ -574,7 +574,7 @@ void CmndRfRaw(void) sonoff_bridge_receive_raw_flag = 1; } } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, GetStateText(sonoff_bridge_receive_raw_flag)); + ResponseCmndStateText(sonoff_bridge_receive_raw_flag); } /*********************************************************************************************/ diff --git a/sonoff/xdrv_08_serial_bridge.ino b/sonoff/xdrv_08_serial_bridge.ino index e835ce256..accee8415 100644 --- a/sonoff/xdrv_08_serial_bridge.ino +++ b/sonoff/xdrv_08_serial_bridge.ino @@ -138,7 +138,7 @@ void CmndSSerialSend(void) codes += 2; } } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, D_JSON_DONE); + ResponseCmndDone(); } } } @@ -149,7 +149,7 @@ void CmndSBaudrate(void) Settings.sbaudrate /= 1200; // Make it a valid baudrate SerialBridgeSerial->begin(Settings.sbaudrate * 1200); // Reinitialize serial port with new baud rate } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.sbaudrate * 1200); + ResponseCmndNumber(Settings.sbaudrate * 1200); } /*********************************************************************************************\ diff --git a/sonoff/xdrv_09_timers.ino b/sonoff/xdrv_09_timers.ino index 7063211c6..193456df5 100644 --- a/sonoff/xdrv_09_timers.ino +++ b/sonoff/xdrv_09_timers.ino @@ -249,7 +249,7 @@ uint16_t SunMinutes(uint32_t dawn) /*******************************************************************************************/ -void TimerSetRandomWindow(uint8_t index) +void TimerSetRandomWindow(uint32_t index) { timer_window[index] = 0; if (Settings.timer[index].window) { @@ -461,7 +461,7 @@ void CmndTimers(void) } } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, GetStateText(Settings.flag3.timers_enable)); + ResponseCmndStateText(Settings.flag3.timers_enable); MqttPublishPrefixTopic_P(RESULT_OR_STAT, XdrvMailbox.command); uint32_t jsflg = 0; @@ -491,7 +491,7 @@ void CmndLongitude(void) } char lbuff[33]; dtostrfd(((float)Settings.longitude) /1000000, 6, lbuff); - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, lbuff); + ResponseCmndChar(lbuff); } void CmndLatitude(void) @@ -501,7 +501,7 @@ void CmndLatitude(void) } char lbuff[33]; dtostrfd(((float)Settings.latitude) /1000000, 6, lbuff); - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, lbuff); + ResponseCmndChar(lbuff); } #endif // USE_SUNRISE diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index ef5d1911e..f2734fe63 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -761,7 +761,7 @@ void CmndSubscribe(void) + subscription_item.Key + "; "); } } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, events.c_str()); + ResponseCmndChar(events.c_str()); } /********************************************************************************************/ @@ -800,7 +800,7 @@ void CmndUnsubscribe(void) subscriptions.remove(0); } } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, events.c_str()); + ResponseCmndChar(events.c_str()); } #endif // SUPPORT_MQTT_EVENT @@ -1188,7 +1188,7 @@ void CmndEvent(void) if (XdrvMailbox.data_len > 0) { strlcpy(event_data, XdrvMailbox.data, sizeof(event_data)); } - Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, D_JSON_DONE); + ResponseCmndDone(); } void CmndVariable(void) @@ -1209,7 +1209,7 @@ void CmndVariable(void) #endif // USE_EXPRESSION bitSet(vars_event, XdrvMailbox.index -1); } - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, vars[XdrvMailbox.index -1]); + ResponseCmndIdxChar(vars[XdrvMailbox.index -1]); } } } @@ -1232,7 +1232,7 @@ void CmndMemory(void) #endif // USE_EXPRESSION bitSet(mems_event, XdrvMailbox.index -1); } - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, Settings.mems[XdrvMailbox.index -1]); + ResponseCmndIdxChar(Settings.mems[XdrvMailbox.index -1]); } } } @@ -1242,7 +1242,7 @@ void CmndCalcResolution(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 7)) { Settings.flag2.calc_resolution = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.flag2.calc_resolution); + ResponseCmndNumber(Settings.flag2.calc_resolution); } void CmndAddition(void) @@ -1253,7 +1253,7 @@ void CmndAddition(void) dtostrfd(tempvar, Settings.flag2.calc_resolution, vars[XdrvMailbox.index -1]); bitSet(vars_event, XdrvMailbox.index -1); } - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, vars[XdrvMailbox.index -1]); + ResponseCmndIdxChar(vars[XdrvMailbox.index -1]); } } @@ -1265,7 +1265,7 @@ void CmndSubtract(void) dtostrfd(tempvar, Settings.flag2.calc_resolution, vars[XdrvMailbox.index -1]); bitSet(vars_event, XdrvMailbox.index -1); } - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, vars[XdrvMailbox.index -1]); + ResponseCmndIdxChar(vars[XdrvMailbox.index -1]); } } @@ -1277,7 +1277,7 @@ void CmndMultiply(void) dtostrfd(tempvar, Settings.flag2.calc_resolution, vars[XdrvMailbox.index -1]); bitSet(vars_event, XdrvMailbox.index -1); } - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, vars[XdrvMailbox.index -1]); + ResponseCmndIdxChar(vars[XdrvMailbox.index -1]); } } @@ -1298,7 +1298,7 @@ void CmndScale(void) bitSet(vars_event, XdrvMailbox.index -1); } } - Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, vars[XdrvMailbox.index -1]); + ResponseCmndIdxChar(vars[XdrvMailbox.index -1]); } } diff --git a/sonoff/xdrv_11_knx.ino b/sonoff/xdrv_11_knx.ino index bb42fd4bb..33409f7b5 100644 --- a/sonoff/xdrv_11_knx.ino +++ b/sonoff/xdrv_11_knx.ino @@ -1017,7 +1017,7 @@ void CmndKnxTxCmnd(void) i = KNX_GA_Search(XdrvMailbox.index + KNX_SLOT1 -1, i + 1); } - Response_P (S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, XdrvMailbox.data ); + ResponseCmndIdxChar (XdrvMailbox.data ); } } @@ -1046,7 +1046,7 @@ void CmndKnxTxVal(void) i = KNX_GA_Search(XdrvMailbox.index + KNX_SLOT1 -1, i + 1); } - Response_P (S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, XdrvMailbox.data ); + ResponseCmndIdxChar (XdrvMailbox.data ); } } @@ -1055,7 +1055,7 @@ void CmndKnxEnabled(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) { Settings.flag.knx_enabled = XdrvMailbox.payload; } - Response_P (S_JSON_COMMAND_SVALUE, XdrvMailbox.command, GetStateText(Settings.flag.knx_enabled) ); + ResponseCmndChar (GetStateText(Settings.flag.knx_enabled) ); } void CmndKnxEnhanced(void) @@ -1063,7 +1063,7 @@ void CmndKnxEnhanced(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) { Settings.flag.knx_enable_enhancement = XdrvMailbox.payload; } - Response_P (S_JSON_COMMAND_SVALUE, XdrvMailbox.command, GetStateText(Settings.flag.knx_enable_enhancement) ); + ResponseCmndChar (GetStateText(Settings.flag.knx_enable_enhancement) ); } void CmndKnxPa(void) @@ -1139,7 +1139,7 @@ void CmndKnxGa(void) KNX_addr.ga.area, KNX_addr.ga.line, KNX_addr.ga.member ); } } else { - Response_P (S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.knx_GA_registered ); + ResponseCmndNumber (Settings.knx_GA_registered ); } } } @@ -1190,7 +1190,7 @@ void CmndKnxCb(void) KNX_addr.ga.area, KNX_addr.ga.line, KNX_addr.ga.member ); } } else { - Response_P (S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.knx_CB_registered ); + ResponseCmndNumber (Settings.knx_CB_registered ); } } } diff --git a/sonoff/xdrv_22_sonoff_ifan.ino b/sonoff/xdrv_22_sonoff_ifan.ino index 2d4a832af..4ce187979 100644 --- a/sonoff/xdrv_22_sonoff_ifan.ino +++ b/sonoff/xdrv_22_sonoff_ifan.ino @@ -189,10 +189,9 @@ const char kSonoffIfanCommands[] PROGMEM = D_CMND_FANSPEED; bool SonoffIfanCommand(void) { - char command [CMDSZ]; bool serviced = true; - int command_code = GetCommandCode(command, sizeof(command), XdrvMailbox.topic, kSonoffIfanCommands); + int command_code = GetCommandCode(XdrvMailbox.command, CMDSZ, XdrvMailbox.topic, kSonoffIfanCommands); if (-1 == command_code) { serviced = false; // Unknown command } @@ -210,7 +209,7 @@ bool SonoffIfanCommand(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < MAX_FAN_SPEED)) { SonoffIFanSetFanspeed(XdrvMailbox.payload, true); } - Response_P(S_JSON_COMMAND_NVALUE, command, GetFanspeed()); + ResponseCmndNumber(GetFanspeed()); } else serviced = false; // Unknown command return serviced; diff --git a/sonoff/xdrv_99_debug.ino b/sonoff/xdrv_99_debug.ino index 015bb5de4..9ac1e3ea3 100644 --- a/sonoff/xdrv_99_debug.ino +++ b/sonoff/xdrv_99_debug.ino @@ -408,37 +408,36 @@ void SetFlashMode(uint8_t mode) bool DebugCommand(void) { - char command[CMDSZ]; bool serviced = true; - int command_code = GetCommandCode(command, sizeof(command), XdrvMailbox.topic, kDebugCommands); + int command_code = GetCommandCode(XdrvMailbox.command, CMDSZ, XdrvMailbox.topic, kDebugCommands); if (-1 == command_code) { serviced = false; // Unknown command } else if (CMND_HELP == command_code) { AddLog_P(LOG_LEVEL_INFO, kDebugCommands); - Response_P(S_JSON_COMMAND_SVALUE, command, D_JSON_DONE); + ResponseCmndDone(); } else if (CMND_RTCDUMP == command_code) { DebugRtcDump(XdrvMailbox.data); - Response_P(S_JSON_COMMAND_SVALUE, command, D_JSON_DONE); + ResponseCmndDone(); } else if (CMND_CFGDUMP == command_code) { DebugCfgDump(XdrvMailbox.data); - Response_P(S_JSON_COMMAND_SVALUE, command, D_JSON_DONE); + ResponseCmndDone(); } else if (CMND_CFGPEEK == command_code) { DebugCfgPeek(XdrvMailbox.data); - Response_P(S_JSON_COMMAND_SVALUE, command, D_JSON_DONE); + ResponseCmndDone(); } else if (CMND_CFGPOKE == command_code) { DebugCfgPoke(XdrvMailbox.data); - Response_P(S_JSON_COMMAND_SVALUE, command, D_JSON_DONE); + ResponseCmndDone(); } #ifdef USE_DEBUG_SETTING_NAMES else if (CMND_CFGSHOW == command_code) { DebugCfgShow(XdrvMailbox.payload); - Response_P(S_JSON_COMMAND_SVALUE, command, D_JSON_DONE); + ResponseCmndDone(); } #endif // USE_DEBUG_SETTING_NAMES #ifdef USE_WEBSERVER @@ -446,13 +445,13 @@ bool DebugCommand(void) if (XdrvMailbox.data_len > 0) { config_xor_on_set = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, command, config_xor_on_set); + ResponseCmndNumber(config_xor_on_set); } #endif // USE_WEBSERVER #ifdef DEBUG_THEO else if (CMND_EXCEPTION == command_code) { if (XdrvMailbox.data_len > 0) ExceptionTest(XdrvMailbox.payload); - Response_P(S_JSON_COMMAND_SVALUE, command, D_JSON_DONE); + ResponseCmndDone(); } #endif // DEBUG_THEO else if (CMND_CPUCHECK == command_code) { @@ -460,26 +459,26 @@ bool DebugCommand(void) CPU_load_check = XdrvMailbox.payload; CPU_last_millis = CPU_last_loop_time; } - Response_P(S_JSON_COMMAND_NVALUE, command, CPU_load_check); + ResponseCmndNumber(CPU_load_check); } else if (CMND_FREEMEM == command_code) { if (XdrvMailbox.data_len > 0) { CPU_show_freemem = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, command, CPU_show_freemem); + ResponseCmndNumber(CPU_show_freemem); } else if ((CMND_SETSENSOR == command_code) && (XdrvMailbox.index < MAX_XSNS_DRIVERS)) { if ((XdrvMailbox.payload >= 0) && XsnsPresent(XdrvMailbox.index)) { bitWrite(Settings.sensors[XdrvMailbox.index / 32], XdrvMailbox.index % 32, XdrvMailbox.payload &1); if (1 == XdrvMailbox.payload) { restart_flag = 2; } // To safely re-enable a sensor currently most sensor need to follow complete restart init cycle } - Response_P(S_JSON_COMMAND_XVALUE, command, XsnsGetSensors().c_str()); + Response_P(S_JSON_COMMAND_XVALUE, XdrvMailbox.command, XsnsGetSensors().c_str()); } else if (CMND_FLASHMODE == command_code) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3)) { SetFlashMode(XdrvMailbox.payload); } - Response_P(S_JSON_COMMAND_NVALUE, command, ESP.getFlashChipMode()); + ResponseCmndNumber(ESP.getFlashChipMode()); } else serviced = false; // Unknown command diff --git a/sonoff/xsns_01_counter.ino b/sonoff/xsns_01_counter.ino index c67a18de7..365e56447 100644 --- a/sonoff/xsns_01_counter.ino +++ b/sonoff/xsns_01_counter.ino @@ -154,10 +154,9 @@ const char kCounterCommands[] PROGMEM = D_CMND_COUNTER "|" D_CMND_COUNTERTYPE "| bool CounterCommand(void) { - char command[CMDSZ]; bool serviced = true; - int command_code = GetCommandCode(command, sizeof(command), XdrvMailbox.topic, kCounterCommands); + int command_code = GetCommandCode(XdrvMailbox.command, CMDSZ, XdrvMailbox.topic, kCounterCommands); if (CMND_COUNTER == command_code) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_COUNTERS)) { if ((XdrvMailbox.data_len > 0) && (pin[GPIO_CNTR1 + XdrvMailbox.index -1] < 99)) { @@ -169,7 +168,7 @@ bool CounterCommand(void) Settings.pulse_counter[XdrvMailbox.index -1] = XdrvMailbox.payload; } } - Response_P(S_JSON_COMMAND_INDEX_LVALUE, command, XdrvMailbox.index, RtcSettings.pulse_counter[XdrvMailbox.index -1]); + Response_P(S_JSON_COMMAND_INDEX_LVALUE, XdrvMailbox.command, XdrvMailbox.index, RtcSettings.pulse_counter[XdrvMailbox.index -1]); } } else if (CMND_COUNTERTYPE == command_code) { @@ -179,14 +178,14 @@ bool CounterCommand(void) RtcSettings.pulse_counter[XdrvMailbox.index -1] = 0; Settings.pulse_counter[XdrvMailbox.index -1] = 0; } - Response_P(S_JSON_COMMAND_INDEX_NVALUE, command, XdrvMailbox.index, bitRead(Settings.pulse_counter_type, XdrvMailbox.index -1)); + ResponseCmndIdxNumber(bitRead(Settings.pulse_counter_type, XdrvMailbox.index -1)); } } else if (CMND_COUNTERDEBOUNCE == command_code) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32001)) { Settings.pulse_counter_debounce = XdrvMailbox.payload; } - Response_P(S_JSON_COMMAND_NVALUE, command, Settings.pulse_counter_debounce); + ResponseCmndNumber(Settings.pulse_counter_debounce); } else serviced = false; // Unknown command