diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 554cd44b5..1c37b3664 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -2,6 +2,7 @@ * 6.6.0.21 20191022 * Remove support for WPS and SmartConfig in favour of Web server (!) based WifiManager (#6680) * Remove binary sonoff-classic (#6680) + * Remove command SetOption2 * * 6.6.0.20 20191018 * Add command SetOption65 0/1 to disable (1) fast power cycle detection fixing unwanted brownout trigger diff --git a/sonoff/i18n.h b/sonoff/i18n.h index 3f19f67dd..d8d0db151 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -502,20 +502,9 @@ #endif // Common -enum UnitNames { - UNIT_AMPERE, UNIT_HOUR, UNIT_KILOOHM, UNIT_KILOWATTHOUR, UNIT_LUX, UNIT_MICROSECOND, UNIT_MILLIAMPERE, UNIT_MILLIMETER_MERCURY, - UNIT_MILLISECOND, UNIT_MINUTE, UNIT_PPB, UNIT_PPD, UNIT_PPM, UNIT_PERCENTAGE, UNIT_PRESSURE, UNIT_SECOND, - UNIT_SECTORS, UNIT_VOLT, UNIT_WATT, UNIT_WATTHOUR, UNIT_HERTZ }; -const char kUnitNames[] PROGMEM = - D_UNIT_AMPERE "|" D_UNIT_HOUR "|" D_UNIT_KILOOHM "|" D_UNIT_KILOWATTHOUR "|" D_UNIT_LUX "|" D_UNIT_MICROSECOND "|" D_UNIT_MILLIAMPERE "|" D_UNIT_MILLIMETER_MERCURY "|" - D_UNIT_MILLISECOND "|" D_UNIT_MINUTE "|" D_UNIT_PARTS_PER_BILLION "|" D_UNIT_PARTS_PER_DECILITER "|" D_UNIT_PARTS_PER_MILLION "|%|" D_UNIT_PRESSURE "|" D_UNIT_SECOND "|" - D_UNIT_SECTORS "|" D_UNIT_VOLT "|" D_UNIT_WATT "|" D_UNIT_WATTHOUR "|" D_UNIT_HERTZ ; - const char S_JSON_COMMAND_NVALUE_SPACE_UNIT[] PROGMEM = "{\"%s\":\"%d %s\"}"; const char S_JSON_COMMAND_LVALUE_SPACE_UNIT[] PROGMEM = "{\"%s\":\"%lu %s\"}"; const char S_JSON_COMMAND_SVALUE_SPACE_UNIT[] PROGMEM = "{\"%s\":\"%s %s\"}"; -const char S_JSON_COMMAND_NVALUE_UNIT[] PROGMEM = "{\"%s\":\"%d%s\"}"; -const char S_JSON_COMMAND_NVALUE_UNIT_NVALUE_UNIT[] PROGMEM = "{\"%s\":\"%d%s (%d%s)\"}"; const char S_JSON_COMMAND_NVALUE_SVALUE[] PROGMEM = "{\"%s\":{\"%d\":\"%s\"}}"; const char S_JSON_COMMAND_NVALUE_ACTIVE_NVALUE[] PROGMEM = "{\"%s\":{\"%d\":{\"" D_JSON_ACTIVE "\":\"%d\"}}}"; diff --git a/sonoff/settings.h b/sonoff/settings.h index b31e0416d..80960260a 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -27,7 +27,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu struct { // SetOption0 .. SetOption31 uint32_t save_state : 1; // bit 0 - SetOption0 - Save power state and use after restart uint32_t button_restrict : 1; // bit 1 - SetOption1 - Control button multipress - uint32_t value_units : 1; // bit 2 - SetOption2 - Add units to JSON status messages + uint32_t ex_value_units : 1; // bit 2 - SetOption2 - Add units to JSON status messages - removed 6.6.0.21 uint32_t mqtt_enabled : 1; // bit 3 - SetOption3 - Control MQTT uint32_t mqtt_response : 1; // bit 4 - SetOption4 - Switch between MQTT RESULT or COMMAND uint32_t mqtt_power_retain : 1; // bit 5 - CMND_POWERRETAIN diff --git a/sonoff/support_command.ino b/sonoff/support_command.ino index c6315ff23..4704e14e1 100644 --- a/sonoff/support_command.ino +++ b/sonoff/support_command.ino @@ -495,7 +495,8 @@ void CmndSleep(void) sleep = XdrvMailbox.payload; WiFiSetSleepMode(); } - Response_P(S_JSON_COMMAND_NVALUE_UNIT_NVALUE_UNIT, XdrvMailbox.command, sleep, (Settings.flag.value_units) ? " " D_UNIT_MILLISECOND : "", Settings.sleep, (Settings.flag.value_units) ? " " D_UNIT_MILLISECOND : ""); + Response_P(S_JSON_COMMAND_NVALUE_ACTIVE_NVALUE, XdrvMailbox.command, Settings.sleep, sleep); + } void CmndUpgrade(void) @@ -1306,7 +1307,7 @@ void CmndTeleperiod(void) if ((Settings.tele_period > 0) && (Settings.tele_period < 10)) Settings.tele_period = 10; // Do not allow periods < 10 seconds tele_period = Settings.tele_period; } - Response_P(S_JSON_COMMAND_NVALUE_UNIT, XdrvMailbox.command, Settings.tele_period, (Settings.flag.value_units) ? " " D_UNIT_SECOND : ""); + ResponseCmndNumber(Settings.tele_period); } void CmndReset(void) diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index 7df40b976..30b0237e2 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -352,7 +352,7 @@ void EnergyMarginCheck(void) } else { Energy.mplh_counter--; if (!Energy.mplh_counter) { - ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHED "\":\"%d%s\"}"), energy_power_u, (Settings.flag.value_units) ? " " D_UNIT_WATT : ""); + ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHED "\":%d}"), energy_power_u); MqttPublishPrefixTopic_P(STAT, S_RSLT_WARNING); EnergyMqttShow(); SetAllPower(POWER_ALL_OFF, SRC_MAXPOWER); @@ -399,8 +399,9 @@ void EnergyMarginCheck(void) } else if ((1 == Energy.max_energy_state ) && (energy_daily_u >= Settings.energy_max_energy)) { Energy.max_energy_state = 2; - dtostrfd(Energy.daily, 3, mqtt_data); - ResponseTime_P(PSTR(",\"" D_JSON_MAXENERGYREACHED "\":\"%s%s\"}"), mqtt_data, (Settings.flag.value_units) ? " " D_UNIT_KILOWATTHOUR : ""); + char stemp[FLOATSZ]; + dtostrfd(Energy.daily, 3, stemp); + ResponseTime_P(PSTR(",\"" D_JSON_MAXENERGYREACHED "\":%s}"), stemp); MqttPublishPrefixTopic_P(STAT, S_RSLT_WARNING); EnergyMqttShow(); SetAllPower(POWER_ALL_OFF, SRC_MAXENERGY); @@ -470,19 +471,10 @@ void EnergyEverySecond() * Commands \*********************************************************************************************/ -void EnergyCommandResponse(uint32_t nvalue, uint32_t unit) +void EnergyCommandCalResponse(uint32_t nvalue) { - if (UNIT_MILLISECOND == unit) { - snprintf_P(XdrvMailbox.command, CMDSZ, PSTR("%sCal"), XdrvMailbox.command); - unit = UNIT_MICROSECOND; - } - - if (Settings.flag.value_units) { - char sunit[CMDSZ]; - Response_P(S_JSON_COMMAND_LVALUE_SPACE_UNIT, XdrvMailbox.command, nvalue, GetTextIndexed(sunit, sizeof(sunit), unit, kUnitNames)); - } else { - Response_P(S_JSON_COMMAND_LVALUE, XdrvMailbox.command, nvalue); - } + snprintf_P(XdrvMailbox.command, CMDSZ, PSTR("%sCal"), XdrvMailbox.command); + ResponseCmndNumber(nvalue); } void CmndEnergyReset(void) @@ -635,7 +627,7 @@ void CmndPowerCal(void) if ((XdrvMailbox.payload > 999) && (XdrvMailbox.payload < 32001)) { Settings.energy_power_calibration = XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_power_calibration, UNIT_MICROSECOND); + ResponseCmndNumber(Settings.energy_power_calibration); } } @@ -646,7 +638,7 @@ void CmndVoltageCal(void) if ((XdrvMailbox.payload > 999) && (XdrvMailbox.payload < 32001)) { Settings.energy_voltage_calibration = XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_voltage_calibration, UNIT_MICROSECOND); + ResponseCmndNumber(Settings.energy_voltage_calibration); } } @@ -657,7 +649,7 @@ void CmndCurrentCal(void) if ((XdrvMailbox.payload > 999) && (XdrvMailbox.payload < 32001)) { Settings.energy_current_calibration = XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_current_calibration, UNIT_MICROSECOND); + ResponseCmndNumber(Settings.energy_current_calibration); } } @@ -665,7 +657,7 @@ void CmndPowerSet(void) { Energy.command_code = CMND_POWERSET; if (XnrgCall(FUNC_COMMAND)) { // Watt - EnergyCommandResponse(Settings.energy_power_calibration, UNIT_MILLISECOND); + EnergyCommandCalResponse(Settings.energy_power_calibration); } } @@ -673,7 +665,7 @@ void CmndVoltageSet(void) { Energy.command_code = CMND_VOLTAGESET; if (XnrgCall(FUNC_COMMAND)) { // Volt - EnergyCommandResponse(Settings.energy_voltage_calibration, UNIT_MILLISECOND); + EnergyCommandCalResponse(Settings.energy_voltage_calibration); } } @@ -681,7 +673,7 @@ void CmndCurrentSet(void) { Energy.command_code = CMND_CURRENTSET; if (XnrgCall(FUNC_COMMAND)) { // milliAmpere - EnergyCommandResponse(Settings.energy_current_calibration, UNIT_MILLISECOND); + EnergyCommandCalResponse(Settings.energy_current_calibration); } } @@ -689,7 +681,7 @@ void CmndFrequencySet(void) { Energy.command_code = CMND_FREQUENCYSET; if (XnrgCall(FUNC_COMMAND)) { // Hz - EnergyCommandResponse(Settings.energy_frequency_calibration, UNIT_MILLISECOND); + EnergyCommandCalResponse(Settings.energy_frequency_calibration); } } @@ -709,7 +701,7 @@ void CmndPowerDelta(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32000)) { Settings.energy_power_delta = XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_power_delta, (Settings.energy_power_delta < 101) ? UNIT_PERCENTAGE : UNIT_WATT); + ResponseCmndNumber(Settings.energy_power_delta); } void CmndPowerLow(void) @@ -717,7 +709,7 @@ void CmndPowerLow(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 3601)) { Settings.energy_min_power = XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_min_power, UNIT_WATT); + ResponseCmndNumber(Settings.energy_min_power); } void CmndPowerHigh(void) @@ -725,7 +717,7 @@ void CmndPowerHigh(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 3601)) { Settings.energy_max_power = XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_max_power, UNIT_WATT); + ResponseCmndNumber(Settings.energy_max_power); } void CmndVoltageLow(void) @@ -733,7 +725,7 @@ void CmndVoltageLow(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 501)) { Settings.energy_min_voltage = XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_min_voltage, UNIT_VOLT); + ResponseCmndNumber(Settings.energy_min_voltage); } void CmndVoltageHigh(void) @@ -741,7 +733,7 @@ void CmndVoltageHigh(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 501)) { Settings.energy_max_voltage = XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_max_voltage, UNIT_VOLT); + ResponseCmndNumber(Settings.energy_max_voltage); } void CmndCurrentLow(void) @@ -749,7 +741,7 @@ void CmndCurrentLow(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 16001)) { Settings.energy_min_current = XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_min_current, UNIT_MILLIAMPERE); + ResponseCmndNumber(Settings.energy_min_current); } void CmndCurrentHigh(void) @@ -757,7 +749,7 @@ void CmndCurrentHigh(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 16001)) { Settings.energy_max_current = XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_max_current, UNIT_MILLIAMPERE); + ResponseCmndNumber(Settings.energy_max_current); } #ifdef USE_ENERGY_POWER_LIMIT @@ -766,7 +758,7 @@ void CmndMaxPower(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 3601)) { Settings.energy_max_power_limit = XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_max_power_limit, UNIT_WATT); + ResponseCmndNumber(Settings.energy_max_power_limit); } void CmndMaxPowerHold(void) @@ -774,7 +766,7 @@ void CmndMaxPowerHold(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 3601)) { Settings.energy_max_power_limit_hold = (1 == XdrvMailbox.payload) ? MAX_POWER_HOLD : XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_max_power_limit_hold, UNIT_SECOND); + ResponseCmndNumber(Settings.energy_max_power_limit_hold); } void CmndMaxPowerWindow(void) @@ -782,7 +774,7 @@ void CmndMaxPowerWindow(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 3601)) { Settings.energy_max_power_limit_window = (1 == XdrvMailbox.payload) ? MAX_POWER_WINDOW : XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_max_power_limit_window, UNIT_SECOND); + ResponseCmndNumber(Settings.energy_max_power_limit_window); } void CmndSafePower(void) @@ -790,7 +782,7 @@ void CmndSafePower(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 3601)) { Settings.energy_max_power_safe_limit = XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_max_power_safe_limit, UNIT_WATT); + ResponseCmndNumber(Settings.energy_max_power_safe_limit); } void CmndSafePowerHold(void) @@ -798,7 +790,7 @@ void CmndSafePowerHold(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 3601)) { Settings.energy_max_power_safe_limit_hold = (1 == XdrvMailbox.payload) ? SAFE_POWER_HOLD : XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_max_power_safe_limit_hold, UNIT_SECOND); + ResponseCmndNumber(Settings.energy_max_power_safe_limit_hold); } void CmndSafePowerWindow(void) @@ -806,7 +798,7 @@ void CmndSafePowerWindow(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 1440)) { Settings.energy_max_power_safe_limit_window = (1 == XdrvMailbox.payload) ? SAFE_POWER_WINDOW : XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_max_power_safe_limit_window, UNIT_MINUTE); + ResponseCmndNumber(Settings.energy_max_power_safe_limit_window); } void CmndMaxEnergy(void) @@ -815,7 +807,7 @@ void CmndMaxEnergy(void) Settings.energy_max_energy = XdrvMailbox.payload; Energy.max_energy_state = 3; } - EnergyCommandResponse(Settings.energy_max_energy, UNIT_WATTHOUR); + ResponseCmndNumber(Settings.energy_max_energy); } void CmndMaxEnergyStart(void) @@ -823,7 +815,7 @@ void CmndMaxEnergyStart(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 24)) { Settings.energy_max_energy_start = XdrvMailbox.payload; } - EnergyCommandResponse(Settings.energy_max_energy_start, UNIT_HOUR); + ResponseCmndNumber(Settings.energy_max_energy_start); } #endif // USE_ENERGY_POWER_LIMIT #endif // USE_ENERGY_MARGIN_DETECTION diff --git a/tools/decode-status.py b/tools/decode-status.py index 1497f35e2..10deefede 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -53,7 +53,7 @@ a_on_off = ["OFF","ON "] a_setoption = [[ "Save power state and use after restart", "Restrict button actions to single, double and hold", - "Show value units in JSON messages", + "(not used) Show value units in JSON messages", "MQTT enabled", "Respond as Command topic instead of RESULT", "MQTT retain on Power",