diff --git a/sonoff/i18n.h b/sonoff/i18n.h index 15f536471..f61d3d40a 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -233,9 +233,6 @@ #define D_CMND_PWM "PWM" #define D_CMND_PWMFREQUENCY "PWMFrequency" #define D_CMND_PWMRANGE "PWMRange" -#define D_CMND_COUNTER "Counter" -#define D_CMND_COUNTERTYPE "CounterType" -#define D_CMND_COUNTERDEBOUNCE "CounterDebounce" #define D_CMND_BUTTONDEBOUNCE "ButtonDebounce" #define D_CMND_SWITCHDEBOUNCE "SwitchDebounce" #define D_CMND_SLEEP "Sleep" @@ -411,14 +408,6 @@ #define D_JSON_RFRECEIVED "RfReceived" #define D_CMND_RFRAW "RfRaw" -// Commands xdrv_07_domoticz.ino -#define D_CMND_DOMOTICZ "Domoticz" -#define D_CMND_IDX "Idx" -#define D_CMND_KEYIDX "KeyIdx" -#define D_CMND_SWITCHIDX "SwitchIdx" -#define D_CMND_SENSORIDX "SensorIdx" -#define D_CMND_UPDATETIMER "UpdateTimer" - // Commands xdrv_08_serial_bridge.ino #define D_CMND_SSERIALSEND "SSerialSend" #define D_CMND_SBAUDRATE "SBaudrate" @@ -439,9 +428,6 @@ #define D_CMND_LATITUDE "Latitude" #define D_CMND_LONGITUDE "Longitude" -// Commands xdrv_23_zigbee.ino -#define D_CMND_ZIGBEEZNPSEND "ZigbeeZNPSend" - #define D_JSON_ZIGBEEZNPRECEIVED "ZigbeeZNPReceived" /********************************************************************************************/ #define D_ASTERISK_PWD "****" diff --git a/sonoff/support.ino b/sonoff/support.ino index 92d6365de..9a2fee883 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -740,9 +740,11 @@ bool DecodeCommand(const char* haystack, void (* const MyCommand[])(void)) { bool result = false; - int command_code = GetCommandCode(XdrvMailbox.command, CMDSZ, XdrvMailbox.topic, haystack); - if (command_code >= 0) { - MyCommand[command_code](); + GetTextIndexed(XdrvMailbox.command, CMDSZ, 0, haystack); // Get prefix if available + int prefix_length = strlen(XdrvMailbox.command); + int command_code = GetCommandCode(XdrvMailbox.command + prefix_length, CMDSZ, XdrvMailbox.topic + prefix_length, haystack); + if (command_code > 0) { // Skip prefix + MyCommand[command_code -1](); result = true; } return result; diff --git a/sonoff/support_command.ino b/sonoff/support_command.ino index 11c6b3d58..9307be436 100644 --- a/sonoff/support_command.ino +++ b/sonoff/support_command.ino @@ -17,7 +17,7 @@ along with this program. If not, see . */ -const char kTasmotaCommands[] PROGMEM = +const char kTasmotaCommands[] PROGMEM = "|" // No prefix D_CMND_BACKLOG "|" D_CMND_DELAY "|" D_CMND_POWER "|" D_CMND_STATUS "|" D_CMND_STATE "|" D_CMND_SLEEP "|" D_CMND_UPGRADE "|" D_CMND_UPLOAD "|" D_CMND_OTAURL "|" D_CMND_SERIALLOG "|" D_CMND_RESTART "|" D_CMND_POWERONSTATE "|" D_CMND_PULSETIME "|" D_CMND_BLINKTIME "|" D_CMND_BLINKCOUNT "|" D_CMND_SAVEDATA "|" D_CMND_SETOPTION "|" D_CMND_TEMPERATURE_RESOLUTION "|" D_CMND_HUMIDITY_RESOLUTION "|" D_CMND_PRESSURE_RESOLUTION "|" D_CMND_POWER_RESOLUTION "|" diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index 6712a2579..d1e76209d 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -2463,7 +2463,7 @@ bool JsonWebColor(const char* dataBuf) const char kWebSendStatus[] PROGMEM = D_JSON_DONE "|" D_JSON_WRONG_PARAMETERS "|" D_JSON_CONNECT_FAILED "|" D_JSON_HOST_NOT_FOUND ; -const char kWebCommands[] PROGMEM = +const char kWebCommands[] PROGMEM = "|" // No prefix #ifdef USE_EMULATION D_CMND_EMULATION "|" #endif diff --git a/sonoff/xdrv_02_mqtt.ino b/sonoff/xdrv_02_mqtt.ino index fb631024e..a9660b2ff 100644 --- a/sonoff/xdrv_02_mqtt.ino +++ b/sonoff/xdrv_02_mqtt.ino @@ -28,7 +28,7 @@ WiFiClient EspClient; // Wifi Client #endif -const char kMqttCommands[] PROGMEM = +const char kMqttCommands[] PROGMEM = "|" // No prefix #if defined(USE_MQTT_TLS) && !defined(USE_MQTT_TLS_CA_CERT) D_CMND_MQTTFINGERPRINT "|" #endif diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index 9809eb81c..b331c98cd 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -41,7 +41,7 @@ enum EnergyCommands { CMND_POWERCAL, CMND_VOLTAGECAL, CMND_CURRENTCAL, CMND_POWERSET, CMND_VOLTAGESET, CMND_CURRENTSET, CMND_FREQUENCYSET }; -const char kEnergyCommands[] PROGMEM = +const char kEnergyCommands[] PROGMEM = "|" // No prefix D_CMND_POWERCAL "|" D_CMND_VOLTAGECAL "|" D_CMND_CURRENTCAL "|" D_CMND_POWERSET "|" D_CMND_VOLTAGESET "|" D_CMND_CURRENTSET "|" D_CMND_FREQUENCYSET "|" #ifdef USE_ENERGY_MARGIN_DETECTION diff --git a/sonoff/xdrv_04_light.ino b/sonoff/xdrv_04_light.ino index 5a2f1a6f7..deb4d0109 100644 --- a/sonoff/xdrv_04_light.ino +++ b/sonoff/xdrv_04_light.ino @@ -131,7 +131,7 @@ const uint8_t LIGHT_COLOR_SIZE = 25; // Char array scolor size const uint8_t WS2812_SCHEMES = 7; // Number of additional WS2812 schemes supported by xdrv_ws2812.ino -const char kLightCommands[] PROGMEM = +const char kLightCommands[] PROGMEM = "|" // No prefix #ifdef USE_WS2812 D_CMND_LED "|" D_CMND_PIXELS "|" D_CMND_ROTATION "|" D_CMND_WIDTH "|" #endif // USE_WS2812 diff --git a/sonoff/xdrv_05_irremote.ino b/sonoff/xdrv_05_irremote.ino index dce86f104..ad48c5c8e 100644 --- a/sonoff/xdrv_05_irremote.ino +++ b/sonoff/xdrv_05_irremote.ino @@ -28,7 +28,7 @@ enum IrErrors { IE_NO_ERROR, IE_INVALID_RAWDATA, IE_INVALID_JSON, IE_SYNTAX_IRSEND, IE_SYNTAX_IRHVAC }; -const char kIrRemoteCommands[] PROGMEM = +const char kIrRemoteCommands[] PROGMEM = "|" // No prefix #ifdef USE_IR_HVAC D_CMND_IRHVAC "|" #endif diff --git a/sonoff/xdrv_06_snfbridge.ino b/sonoff/xdrv_06_snfbridge.ino index 01edfea76..4818c7be2 100644 --- a/sonoff/xdrv_06_snfbridge.ino +++ b/sonoff/xdrv_06_snfbridge.ino @@ -27,7 +27,7 @@ const uint32_t SFB_TIME_AVOID_DUPLICATE = 2000; // Milliseconds enum SonoffBridgeCommands { CMND_RFSYNC, CMND_RFLOW, CMND_RFHIGH, CMND_RFHOST, CMND_RFCODE }; -const char kSonoffBridgeCommands[] PROGMEM = +const char kSonoffBridgeCommands[] PROGMEM = "|" // No prefix D_CMND_RFSYNC "|" D_CMND_RFLOW "|" D_CMND_RFHIGH "|" D_CMND_RFHOST "|" D_CMND_RFCODE "|" D_CMND_RFKEY "|" D_CMND_RFRAW; void (* const SonoffBridgeCommand[])(void) PROGMEM = { diff --git a/sonoff/xdrv_07_domoticz.ino b/sonoff/xdrv_07_domoticz.ino index a74feda5c..2acd60a0d 100644 --- a/sonoff/xdrv_07_domoticz.ino +++ b/sonoff/xdrv_07_domoticz.ino @@ -21,14 +21,21 @@ #define XDRV_07 7 -const char DOMOTICZ_MESSAGE[] PROGMEM = "{\"idx\":%d,\"nvalue\":%d,\"svalue\":\"%s\",\"Battery\":%d,\"RSSI\":%d}"; +#define D_PRFX_DOMOTICZ "Domoticz" +#define D_CMND_IDX "Idx" +#define D_CMND_KEYIDX "KeyIdx" +#define D_CMND_SWITCHIDX "SwitchIdx" +#define D_CMND_SENSORIDX "SensorIdx" +#define D_CMND_UPDATETIMER "UpdateTimer" -const char kDomoticzCommands[] PROGMEM = +const char kDomoticzCommands[] PROGMEM = D_PRFX_DOMOTICZ "|" // Prefix D_CMND_IDX "|" D_CMND_KEYIDX "|" D_CMND_SWITCHIDX "|" D_CMND_SENSORIDX "|" D_CMND_UPDATETIMER ; void (* const DomoticzCommand[])(void) PROGMEM = { &CmndDomoticzIdx, &CmndDomoticzKeyIdx, &CmndDomoticzSwitchIdx, &CmndDomoticzSensorIdx, &CmndDomoticzUpdateTimer }; +const char DOMOTICZ_MESSAGE[] PROGMEM = "{\"idx\":%d,\"nvalue\":%d,\"svalue\":\"%s\",\"Battery\":%d,\"RSSI\":%d}"; + //enum DomoticzSensors {DZ_TEMP, DZ_TEMP_HUM, DZ_TEMP_HUM_BARO, DZ_POWER_ENERGY, DZ_ILLUMINANCE, DZ_COUNT, DZ_VOLTAGE, DZ_CURRENT, DZ_AIRQUALITY, DZ_MAX_SENSORS}; #if MAX_DOMOTICZ_SNS_IDX < DZ_MAX_SENSORS @@ -381,13 +388,6 @@ void DomoticzSensorPowerEnergy(int power, char *energy) * Commands \*********************************************************************************************/ -void ResponseDomoticzCmndIdxNumber(uint32_t value) -{ - Response_P(PSTR("{\"" D_CMND_DOMOTICZ "%s%d\":%d}"), XdrvMailbox.command, XdrvMailbox.index, value); -} - -/*********************************************************************************************/ - void CmndDomoticzIdx(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_DOMOTICZ_IDX)) { @@ -395,7 +395,7 @@ void CmndDomoticzIdx(void) Settings.domoticz_relay_idx[XdrvMailbox.index -1] = XdrvMailbox.payload; restart_flag = 2; } - ResponseDomoticzCmndIdxNumber(Settings.domoticz_relay_idx[XdrvMailbox.index -1]); + ResponseCmndIdxNumber(Settings.domoticz_relay_idx[XdrvMailbox.index -1]); } } @@ -405,7 +405,7 @@ void CmndDomoticzKeyIdx(void) if (XdrvMailbox.payload >= 0) { Settings.domoticz_key_idx[XdrvMailbox.index -1] = XdrvMailbox.payload; } - ResponseDomoticzCmndIdxNumber(Settings.domoticz_key_idx[XdrvMailbox.index -1]); + ResponseCmndIdxNumber(Settings.domoticz_key_idx[XdrvMailbox.index -1]); } } @@ -415,7 +415,7 @@ void CmndDomoticzSwitchIdx(void) if (XdrvMailbox.payload >= 0) { Settings.domoticz_switch_idx[XdrvMailbox.index -1] = XdrvMailbox.payload; } - ResponseDomoticzCmndIdxNumber(Settings.domoticz_switch_idx[XdrvMailbox.index -1]); + ResponseCmndIdxNumber(Settings.domoticz_switch_idx[XdrvMailbox.index -1]); } } @@ -425,7 +425,7 @@ void CmndDomoticzSensorIdx(void) if (XdrvMailbox.payload >= 0) { Settings.domoticz_sensor_idx[XdrvMailbox.index -1] = XdrvMailbox.payload; } - ResponseDomoticzCmndIdxNumber(Settings.domoticz_sensor_idx[XdrvMailbox.index -1]); + ResponseCmndIdxNumber(Settings.domoticz_sensor_idx[XdrvMailbox.index -1]); } } @@ -434,7 +434,7 @@ void CmndDomoticzUpdateTimer(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 3601)) { Settings.domoticz_update_timer = XdrvMailbox.payload; } - Response_P(PSTR("{\"" D_CMND_DOMOTICZ "%s\":%d}"), XdrvMailbox.command, Settings.domoticz_update_timer); + ResponseCmndNumber(Settings.domoticz_update_timer); } /*********************************************************************************************\ @@ -575,10 +575,7 @@ bool Xdrv07(uint8_t function) // DomoticzSendSensor(); break; case FUNC_COMMAND: - if (!strncasecmp_P(XdrvMailbox.topic, PSTR(D_CMND_DOMOTICZ), strlen(D_CMND_DOMOTICZ))) { // Prefix - XdrvMailbox.topic += strlen(D_CMND_DOMOTICZ); - result = DecodeCommand(kDomoticzCommands, DomoticzCommand); - } + result = DecodeCommand(kDomoticzCommands, DomoticzCommand); break; } } diff --git a/sonoff/xdrv_08_serial_bridge.ino b/sonoff/xdrv_08_serial_bridge.ino index e751ce488..6cc354f60 100644 --- a/sonoff/xdrv_08_serial_bridge.ino +++ b/sonoff/xdrv_08_serial_bridge.ino @@ -26,12 +26,14 @@ const uint8_t SERIAL_BRIDGE_BUFFER_SIZE = 130; +const char kSerialBridgeCommands[] PROGMEM = "|" // No prefix + D_CMND_SSERIALSEND "|" D_CMND_SBAUDRATE; + +void (* const SerialBridgeCommand[])(void) PROGMEM = + { &CmndSSerialSend, &CmndSBaudrate }; + #include -const char kSerialBridgeCommands[] PROGMEM = D_CMND_SSERIALSEND "|" D_CMND_SBAUDRATE; - -void (* const SerialBridgeCommand[])(void) PROGMEM = { &CmndSSerialSend, &CmndSBaudrate }; - TasmotaSerial *SerialBridgeSerial = nullptr; unsigned long serial_bridge_polling_window = 0; diff --git a/sonoff/xdrv_09_timers.ino b/sonoff/xdrv_09_timers.ino index f6b6eb148..49da66331 100644 --- a/sonoff/xdrv_09_timers.ino +++ b/sonoff/xdrv_09_timers.ino @@ -38,7 +38,7 @@ #define XDRV_09 9 -const char kTimerCommands[] PROGMEM = +const char kTimerCommands[] PROGMEM = "|" // No prefix D_CMND_TIMER "|" D_CMND_TIMERS #ifdef USE_SUNRISE "|" D_CMND_LATITUDE "|" D_CMND_LONGITUDE diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index f2734fe63..6a40f861d 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -108,7 +108,7 @@ const char kCompareOperators[] PROGMEM = "=\0>\0<\0|\0==!=>=<="; #define MAX_EXPRESSION_OPERATOR_PRIORITY 4 #endif // USE_EXPRESSION -const char kRulesCommands[] PROGMEM = +const char kRulesCommands[] PROGMEM = "|" // No prefix D_CMND_RULE "|" D_CMND_RULETIMER "|" D_CMND_EVENT "|" D_CMND_VAR "|" D_CMND_MEM "|" D_CMND_ADD "|" D_CMND_SUB "|" D_CMND_MULT "|" D_CMND_SCALE "|" D_CMND_CALC_RESOLUTION #ifdef SUPPORT_MQTT_EVENT diff --git a/sonoff/xdrv_11_knx.ino b/sonoff/xdrv_11_knx.ino index 33409f7b5..73e388fbc 100644 --- a/sonoff/xdrv_11_knx.ino +++ b/sonoff/xdrv_11_knx.ino @@ -188,21 +188,20 @@ const char *device_param_cb[] = { }; // Commands -#define D_CMND_KNXTXCMND "KnxTx_Cmnd" -#define D_CMND_KNXTXVAL "KnxTx_Val" -#define D_CMND_KNX_ENABLED "Knx_Enabled" -#define D_CMND_KNX_ENHANCED "Knx_Enhanced" -#define D_CMND_KNX_PA "Knx_PA" -#define D_CMND_KNX_GA "Knx_GA" -#define D_CMND_KNX_CB "Knx_CB" +#define D_PRFX_KNX "Knx" +#define D_CMND_KNXTXCMND "Tx_Cmnd" +#define D_CMND_KNXTXVAL "Tx_Val" +#define D_CMND_KNX_ENABLED "_Enabled" +#define D_CMND_KNX_ENHANCED "_Enhanced" +#define D_CMND_KNX_PA "_PA" +#define D_CMND_KNX_GA "_GA" +#define D_CMND_KNX_CB "_CB" -const char kKnxCommands[] PROGMEM = - D_CMND_KNXTXCMND "|" D_CMND_KNXTXVAL "|" D_CMND_KNX_ENABLED "|" D_CMND_KNX_ENHANCED "|" - D_CMND_KNX_PA "|" D_CMND_KNX_GA "|" D_CMND_KNX_CB ; +const char kKnxCommands[] PROGMEM = D_PRFX_KNX "|" // Prefix + D_CMND_KNXTXCMND "|" D_CMND_KNXTXVAL "|" D_CMND_KNX_ENABLED "|" D_CMND_KNX_ENHANCED "|" D_CMND_KNX_PA "|" D_CMND_KNX_GA "|" D_CMND_KNX_CB ; void (* const KnxCommand[])(void) PROGMEM = { - &CmndKnxTxCmnd, &CmndKnxTxVal, &CmndKnxEnabled, &CmndKnxEnhanced, - &CmndKnxPa, &CmndKnxGa, &CmndKnxCb }; + &CmndKnxTxCmnd, &CmndKnxTxVal, &CmndKnxEnabled, &CmndKnxEnhanced, &CmndKnxPa, &CmndKnxGa, &CmndKnxCb }; uint8_t KNX_GA_Search( uint8_t param, uint8_t start = 0 ) { diff --git a/sonoff/xdrv_13_display.ino b/sonoff/xdrv_13_display.ino index 3625804f6..4b5349040 100644 --- a/sonoff/xdrv_13_display.ino +++ b/sonoff/xdrv_13_display.ino @@ -28,7 +28,7 @@ const uint8_t DISPLAY_MAX_ROWS = 32; // Max number of lines allowed wi const uint8_t DISPLAY_LOG_ROWS = 32; // Number of lines in display log buffer -#define D_CMND_DISPLAY "Display" +#define D_PRFX_DISPLAY "Display" #define D_CMND_DISP_ADDRESS "Address" #define D_CMND_DISP_COLS "Cols" #define D_CMND_DISP_DIMMER "Dimmer" @@ -53,7 +53,7 @@ enum XdspFunctions { FUNC_DISPLAY_INIT_DRIVER, FUNC_DISPLAY_INIT, FUNC_DISPLAY_E enum DisplayInitModes { DISPLAY_INIT_MODE, DISPLAY_INIT_PARTIAL, DISPLAY_INIT_FULL }; -const char kDisplayCommands[] PROGMEM = +const char kDisplayCommands[] PROGMEM = D_PRFX_DISPLAY "|" // Prefix "|" D_CMND_DISP_MODEL "|" D_CMND_DISP_WIDTH "|" D_CMND_DISP_HEIGHT "|" D_CMND_DISP_MODE "|" D_CMND_DISP_REFRESH "|" D_CMND_DISP_DIMMER "|" D_CMND_DISP_COLS "|" D_CMND_DISP_ROWS "|" D_CMND_DISP_SIZE "|" D_CMND_DISP_FONT "|" D_CMND_DISP_ROTATE "|" D_CMND_DISP_TEXT "|" D_CMND_DISP_ADDRESS ; @@ -909,21 +909,9 @@ void DisplaySetPower(void) * Commands \*********************************************************************************************/ -void ResponseDisplayCmndNumber(int value) -{ - Response_P(PSTR("{\"" D_CMND_DISPLAY "%s\":%d}"), XdrvMailbox.command, value); -} - -void ResponseDisplayCmndIdxNumber(int value) -{ - Response_P(PSTR("{\"" D_CMND_DISPLAY "%s%d\":%d}"), XdrvMailbox.command, XdrvMailbox.index, value); -} - -/*********************************************************************************************/ - void CmndDisplay(void) { - Response_P(PSTR("{\"" D_CMND_DISPLAY "\":{\"" D_CMND_DISP_MODEL "\":%d,\"" D_CMND_DISP_WIDTH "\":%d,\"" D_CMND_DISP_HEIGHT "\":%d,\"" + Response_P(PSTR("{\"" D_PRFX_DISPLAY "\":{\"" D_CMND_DISP_MODEL "\":%d,\"" D_CMND_DISP_WIDTH "\":%d,\"" D_CMND_DISP_HEIGHT "\":%d,\"" D_CMND_DISP_MODE "\":%d,\"" D_CMND_DISP_DIMMER "\":%d,\"" D_CMND_DISP_SIZE "\":%d,\"" D_CMND_DISP_FONT "\":%d,\"" D_CMND_DISP_ROTATE "\":%d,\"" D_CMND_DISP_REFRESH "\":%d,\"" D_CMND_DISP_COLS "\":[%d,%d],\"" D_CMND_DISP_ROWS "\":%d}}"), Settings.display_model, Settings.display_width, Settings.display_height, @@ -942,7 +930,7 @@ void CmndDisplayModel(void) Settings.display_model = last_display_model; } } - ResponseDisplayCmndNumber(Settings.display_model); + ResponseCmndNumber(Settings.display_model); } void CmndDisplayWidth(void) @@ -953,7 +941,7 @@ void CmndDisplayWidth(void) restart_flag = 2; // Restart to re-init width } } - ResponseDisplayCmndNumber(Settings.display_width); + ResponseCmndNumber(Settings.display_width); } void CmndDisplayHeight(void) @@ -964,7 +952,7 @@ void CmndDisplayHeight(void) restart_flag = 2; // Restart to re-init height } } - ResponseDisplayCmndNumber(Settings.display_height); + ResponseCmndNumber(Settings.display_height); } void CmndDisplayMode(void) @@ -994,7 +982,7 @@ void CmndDisplayMode(void) } } #endif // USE_DISPLAY_MODES1TO5 - ResponseDisplayCmndNumber(Settings.display_mode); + ResponseCmndNumber(Settings.display_mode); } void CmndDisplayDimmer(void) @@ -1008,7 +996,7 @@ void CmndDisplayDimmer(void) ExecuteCommandPower(disp_device, POWER_OFF, SRC_DISPLAY); } } - ResponseDisplayCmndNumber(Settings.display_dimmer); + ResponseCmndNumber(Settings.display_dimmer); } void CmndDisplaySize(void) @@ -1016,7 +1004,7 @@ void CmndDisplaySize(void) if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload <= 4)) { Settings.display_size = XdrvMailbox.payload; } - ResponseDisplayCmndNumber(Settings.display_size); + ResponseCmndNumber(Settings.display_size); } void CmndDisplayFont(void) @@ -1024,7 +1012,7 @@ void CmndDisplayFont(void) if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload <= 4)) { Settings.display_font = XdrvMailbox.payload; } - ResponseDisplayCmndNumber(Settings.display_font); + ResponseCmndNumber(Settings.display_font); } void CmndDisplayRotate(void) @@ -1049,7 +1037,7 @@ void CmndDisplayRotate(void) #endif // USE_DISPLAY_MODES1TO5 } } - ResponseDisplayCmndNumber(Settings.display_rotate); + ResponseCmndNumber(Settings.display_rotate); } void CmndDisplayText(void) @@ -1064,7 +1052,7 @@ void CmndDisplayText(void) DisplayLogBufferAdd(XdrvMailbox.data); } #endif // USE_DISPLAY_MODES1TO5 - Response_P("{\"" D_CMND_DISPLAY "%s\":\"%s\"}", XdrvMailbox.command, XdrvMailbox.data); + ResponseCmndChar(XdrvMailbox.data); } } @@ -1074,7 +1062,7 @@ void CmndDisplayAddress(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 255)) { Settings.display_address[XdrvMailbox.index -1] = XdrvMailbox.payload; } - ResponseDisplayCmndIdxNumber(Settings.display_address[XdrvMailbox.index -1]); + ResponseCmndIdxNumber(Settings.display_address[XdrvMailbox.index -1]); } } @@ -1083,7 +1071,7 @@ void CmndDisplayRefresh(void) if ((XdrvMailbox.payload >= 1) && (XdrvMailbox.payload <= 7)) { Settings.display_refresh = XdrvMailbox.payload; } - ResponseDisplayCmndNumber(Settings.display_refresh); + ResponseCmndNumber(Settings.display_refresh); } void CmndDisplayColumns(void) @@ -1098,7 +1086,7 @@ void CmndDisplayColumns(void) } #endif // USE_DISPLAY_MODES1TO5 } - ResponseDisplayCmndIdxNumber(Settings.display_cols[XdrvMailbox.index -1]); + ResponseCmndIdxNumber(Settings.display_cols[XdrvMailbox.index -1]); } } @@ -1111,7 +1099,7 @@ void CmndDisplayRows(void) DisplayReAllocScreenBuffer(); #endif // USE_DISPLAY_MODES1TO5 } - ResponseDisplayCmndNumber(Settings.display_rows); + ResponseCmndNumber(Settings.display_rows); } /*********************************************************************************************\ @@ -1148,10 +1136,7 @@ bool Xdrv13(uint8_t function) break; #endif // USE_DISPLAY_MODES1TO5 case FUNC_COMMAND: - if (!strncasecmp_P(XdrvMailbox.topic, PSTR(D_CMND_DISPLAY), strlen(D_CMND_DISPLAY))) { // Prefix - XdrvMailbox.topic += strlen(D_CMND_DISPLAY); - result = DecodeCommand(kDisplayCommands, DisplayCommand); - } + result = DecodeCommand(kDisplayCommands, DisplayCommand); break; } } diff --git a/sonoff/xdrv_17_rcswitch.ino b/sonoff/xdrv_17_rcswitch.ino index bbbdf573f..902304f0b 100644 --- a/sonoff/xdrv_17_rcswitch.ino +++ b/sonoff/xdrv_17_rcswitch.ino @@ -32,9 +32,11 @@ #define D_JSON_RF_PULSE "Pulse" #define D_JSON_RF_REPEAT "Repeat" -const char kRfSendCommands[] PROGMEM = D_CMND_RFSEND; +const char kRfSendCommands[] PROGMEM = "|" // No prefix + D_CMND_RFSEND; -void (* const RfSendCommand[])(void) PROGMEM = { &CmndRfSend }; +void (* const RfSendCommand[])(void) PROGMEM = + { &CmndRfSend }; #include diff --git a/sonoff/xdrv_22_sonoff_ifan.ino b/sonoff/xdrv_22_sonoff_ifan.ino index 2dcc71215..45d37c977 100644 --- a/sonoff/xdrv_22_sonoff_ifan.ino +++ b/sonoff/xdrv_22_sonoff_ifan.ino @@ -30,9 +30,11 @@ const uint8_t kIFan02Speed[MAX_FAN_SPEED] = { 0x00, 0x01, 0x03, 0x05 }; const uint8_t kIFan03Speed[MAX_FAN_SPEED +2] = { 0x00, 0x01, 0x03, 0x04, 0x05, 0x06 }; const uint8_t kIFan03Sequence[MAX_FAN_SPEED][MAX_FAN_SPEED] = {{0, 2, 2, 2}, {0, 1, 2, 4}, {1, 1, 2, 5}, {4, 4, 5, 3}}; -const char kSonoffIfanCommands[] PROGMEM = D_CMND_FANSPEED; +const char kSonoffIfanCommands[] PROGMEM = "|" // No prefix + D_CMND_FANSPEED; -void (* const SonoffIfanCommand[])(void) PROGMEM = { &CmndFanspeed }; +void (* const SonoffIfanCommand[])(void) PROGMEM = + { &CmndFanspeed }; uint8_t ifan_fanspeed_timer = 0; uint8_t ifan_fanspeed_goal = 0; diff --git a/sonoff/xdrv_23_zigbee.ino b/sonoff/xdrv_23_zigbee.ino index c6e479857..99140c3f1 100644 --- a/sonoff/xdrv_23_zigbee.ino +++ b/sonoff/xdrv_23_zigbee.ino @@ -271,9 +271,16 @@ enum class ConfigurationOption : uint8_t { ZDO_DIRECT_CB = 0x8F }; -const char kZigbeeCommands[] PROGMEM = D_CMND_ZIGBEEZNPSEND; +#define D_JSON_ZIGBEEZNPRECEIVED "ZigbeeZNPReceived" -void (* const ZigbeeCommand[])(void) PROGMEM = { &CmndZigbeeZNPSend }; +#define D_PRFX_ZIGBEE "Zigbee" +#define D_CMND_ZIGBEEZNPSEND "ZNPSend" + +const char kZigbeeCommands[] PROGMEM = D_PRFX_ZIGBEE "|" // Prefix + D_CMND_ZIGBEEZNPSEND; + +void (* const ZigbeeCommand[])(void) PROGMEM = + { &CmndZigbeeZNPSend }; #include diff --git a/sonoff/xdrv_99_debug.ino b/sonoff/xdrv_99_debug.ino index 8553aa859..5a1286c84 100644 --- a/sonoff/xdrv_99_debug.ino +++ b/sonoff/xdrv_99_debug.ino @@ -58,7 +58,7 @@ #define D_CMND_RTCDUMP "RtcDump" #define D_CMND_SETSENSOR "SetSensor" -const char kDebugCommands[] PROGMEM = +const char kDebugCommands[] PROGMEM = "|" // No prefix D_CMND_CFGDUMP "|" D_CMND_CFGPEEK "|" D_CMND_CFGPOKE "|" #ifdef USE_DEBUG_SETTING_NAMES D_CMND_CFGSHOW "|" diff --git a/sonoff/xsns_01_counter.ino b/sonoff/xsns_01_counter.ino index 9605814a7..61245e2e6 100644 --- a/sonoff/xsns_01_counter.ino +++ b/sonoff/xsns_01_counter.ino @@ -24,9 +24,15 @@ #define XSNS_01 1 -const char kCounterCommands[] PROGMEM = D_CMND_COUNTER "|" D_CMND_COUNTERTYPE "|" D_CMND_COUNTERDEBOUNCE ; +#define D_PRFX_COUNTER "Counter" +#define D_CMND_COUNTERTYPE "Type" +#define D_CMND_COUNTERDEBOUNCE "Debounce" -void (* const CounterCommand[])(void) PROGMEM = { &CmndCounter, &CmndCounterType, &CmndCounterDebounce }; +const char kCounterCommands[] PROGMEM = D_PRFX_COUNTER "|" // Prefix + "|" D_CMND_COUNTERTYPE "|" D_CMND_COUNTERDEBOUNCE ; + +void (* const CounterCommand[])(void) PROGMEM = + { &CmndCounter, &CmndCounterType, &CmndCounterDebounce }; unsigned long last_counter_timer[MAX_COUNTERS]; // Last counter time in micro seconds @@ -155,7 +161,7 @@ void CmndCounter(void) Settings.pulse_counter[XdrvMailbox.index -1] = XdrvMailbox.payload; } } - Response_P(S_JSON_COMMAND_INDEX_LVALUE, XdrvMailbox.command, XdrvMailbox.index, RtcSettings.pulse_counter[XdrvMailbox.index -1]); + ResponseCmndIdxNumber(RtcSettings.pulse_counter[XdrvMailbox.index -1]); } } diff --git a/sonoff/xsns_02_analog.ino b/sonoff/xsns_02_analog.ino index f0696dcb5..b3c29e9d8 100644 --- a/sonoff/xsns_02_analog.ino +++ b/sonoff/xsns_02_analog.ino @@ -183,9 +183,11 @@ void AdcShow(bool json) \*********************************************************************************************/ #define D_CMND_ADCPARAM "AdcParam" -const char kAdcCommands[] PROGMEM = D_CMND_ADC "|" D_CMND_ADCS "|" D_CMND_ADCPARAM; +const char kAdcCommands[] PROGMEM = "|" // No prefix + D_CMND_ADC "|" D_CMND_ADCS "|" D_CMND_ADCPARAM; -void (* const AdcCommand[])(void) PROGMEM = { &CmndAdc, &CmndAdcs, &CmndAdcParam }; +void (* const AdcCommand[])(void) PROGMEM = + { &CmndAdc, &CmndAdcs, &CmndAdcParam }; void CmndAdc(void) {