mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-29 13:46:37 +00:00
Add SetOption comments to code
This commit is contained in:
parent
55cc695649
commit
5f4e38023d
@ -28,7 +28,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
|
||||
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 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_enabled : 1; // bit 3 - SetOption3 - Enable 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
|
||||
uint32_t mqtt_button_retain : 1; // bit 6 - CMND_BUTTONRETAIN
|
||||
@ -39,10 +39,10 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
|
||||
uint32_t button_swap : 1; // bit 11 (v5.1.6) - SetOption11 - Swap button single and double press functionality
|
||||
uint32_t stop_flash_rotate : 1; // bit 12 (v5.2.0) - SetOption12 - Switch between dynamic or fixed slot flash save location
|
||||
uint32_t button_single : 1; // bit 13 (v5.4.0) - SetOption13 - Support only single press to speed up button press recognition
|
||||
uint32_t interlock : 1; // bit 14 (v5.6.0) - CMND_INTERLOCK
|
||||
uint32_t interlock : 1; // bit 14 (v5.6.0) - CMND_INTERLOCK - Enable/disable interlock
|
||||
uint32_t pwm_control : 1; // bit 15 (v5.8.1) - SetOption15 - Switch between commands PWM or COLOR/DIMMER/CT/CHANNEL
|
||||
uint32_t ws_clock_reverse : 1; // bit 16 (v5.8.1) - SetOption16 - Switch between clockwise or counter-clockwise
|
||||
uint32_t decimal_text : 1; // bit 17 (v5.8.1) - SetOption17 - Switch between decimal or hexadecimal output
|
||||
uint32_t decimal_text : 1; // bit 17 (v5.8.1) - SetOption17 - Switch between decimal or hexadecimal output (0 = hexadecimal, 1 = decimal)
|
||||
uint32_t light_signal : 1; // bit 18 (v5.10.0c) - SetOption18 - Pair light signal with CO2 sensor
|
||||
uint32_t hass_discovery : 1; // bit 19 (v5.11.1a) - SetOption19 - Control Home Assistantautomatic discovery (See SetOption59)
|
||||
uint32_t not_power_linked : 1; // bit 20 (v5.11.1f) - SetOption20 - Control power in relation to Dimmer/Color/Ct changes
|
||||
@ -53,8 +53,8 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
|
||||
uint32_t knx_enabled : 1; // bit 25 (v5.12.0l) - CMND_KNX_ENABLED
|
||||
uint32_t device_index_enable : 1; // bit 26 (v5.13.1a) - SetOption26 - Switch between POWER or POWER1
|
||||
uint32_t knx_enable_enhancement : 1; // bit 27 (v5.14.0a) - CMND_KNX_ENHANCED
|
||||
uint32_t rf_receive_decimal : 1; // bit 28 (v6.0.0a) - SetOption28 - RF receive data format
|
||||
uint32_t ir_receive_decimal : 1; // bit 29 (v6.0.0a) - SetOption29 - IR receive data format
|
||||
uint32_t rf_receive_decimal : 1; // bit 28 (v6.0.0a) - SetOption28 - RF receive data format (0 = hexadecimal, 1 = decimal)
|
||||
uint32_t ir_receive_decimal : 1; // bit 29 (v6.0.0a) - SetOption29 - IR receive data format (0 = hexadecimal, 1 = decimal)
|
||||
uint32_t hass_light : 1; // bit 30 (v6.0.0b) - SetOption30 - Enforce HAss autodiscovery as light
|
||||
uint32_t global_state : 1; // bit 31 (v6.1.0) - SetOption31 - Control link led blinking
|
||||
};
|
||||
|
@ -619,7 +619,7 @@ float ConvertTemp(float c)
|
||||
global_update = uptime;
|
||||
global_temperature = c;
|
||||
|
||||
if (!isnan(c) && Settings.flag.temperature_conversion) {
|
||||
if (!isnan(c) && Settings.flag.temperature_conversion) { // SetOption8 - Switch between Celsius or Fahrenheit
|
||||
result = c * 1.8 + 32; // Fahrenheit
|
||||
}
|
||||
return result;
|
||||
@ -629,7 +629,7 @@ float ConvertTempToCelsius(float c)
|
||||
{
|
||||
float result = c;
|
||||
|
||||
if (!isnan(c) && Settings.flag.temperature_conversion) {
|
||||
if (!isnan(c) && Settings.flag.temperature_conversion) { // SetOption8 - Switch between Celsius or Fahrenheit
|
||||
result = (c - 32) / 1.8; // Celsius
|
||||
}
|
||||
return result;
|
||||
@ -637,7 +637,7 @@ float ConvertTempToCelsius(float c)
|
||||
|
||||
char TempUnit(void)
|
||||
{
|
||||
return (Settings.flag.temperature_conversion) ? 'F' : 'C';
|
||||
return (Settings.flag.temperature_conversion) ? 'F' : 'C'; // SetOption8 - Switch between Celsius or Fahrenheit
|
||||
}
|
||||
|
||||
float ConvertHumidity(float h)
|
||||
@ -655,7 +655,7 @@ float ConvertPressure(float p)
|
||||
global_update = uptime;
|
||||
global_pressure = p;
|
||||
|
||||
if (!isnan(p) && Settings.flag.pressure_conversion) {
|
||||
if (!isnan(p) && Settings.flag.pressure_conversion) { // SetOption24 - Switch between hPa or mmHg pressure unit
|
||||
result = p * 0.75006375541921; // mmHg
|
||||
}
|
||||
return result;
|
||||
|
@ -300,7 +300,7 @@ void CmndPower(void)
|
||||
if ((XdrvMailbox.payload < POWER_OFF) || (XdrvMailbox.payload > POWER_BLINK_STOP)) {
|
||||
XdrvMailbox.payload = POWER_SHOW_STATE;
|
||||
}
|
||||
// Settings.flag.device_index_enable = XdrvMailbox.usridx;
|
||||
// Settings.flag.device_index_enable = XdrvMailbox.usridx; // SetOption26 - Switch between POWER or POWER1
|
||||
ExecuteCommandPower(XdrvMailbox.index, XdrvMailbox.payload, SRC_IGNORE);
|
||||
mqtt_data[0] = '\0';
|
||||
}
|
||||
@ -324,7 +324,7 @@ void CmndStatus(void)
|
||||
// Workaround MQTT - TCP/IP stack queueing when SUB_PREFIX = PUB_PREFIX
|
||||
if (!strcmp(Settings.mqtt_prefix[0],Settings.mqtt_prefix[1]) && (!payload)) { option++; } // TELE
|
||||
|
||||
if ((!Settings.flag.mqtt_enabled) && (6 == payload)) { payload = 99; }
|
||||
if ((!Settings.flag.mqtt_enabled) && (6 == payload)) { payload = 99; } // SetOption3 - Enable MQTT
|
||||
if (!energy_flg && (9 == payload)) { payload = 99; }
|
||||
|
||||
if ((0 == payload) || (99 == payload)) {
|
||||
@ -346,8 +346,14 @@ void CmndStatus(void)
|
||||
D_CMND_SWITCHMODE "\":[%s],\"" D_CMND_BUTTONRETAIN "\":%d,\"" D_CMND_SWITCHRETAIN "\":%d,\"" D_CMND_SENSORRETAIN "\":%d,\"" D_CMND_POWERRETAIN "\":%d}}"),
|
||||
ModuleNr(), stemp, mqtt_topic,
|
||||
Settings.button_topic, power, Settings.poweronstate, Settings.ledstate,
|
||||
Settings.ledmask, Settings.save_data, Settings.flag.save_state, Settings.switch_topic,
|
||||
stemp2, Settings.flag.mqtt_button_retain, Settings.flag.mqtt_switch_retain, Settings.flag.mqtt_sensor_retain, Settings.flag.mqtt_power_retain);
|
||||
Settings.ledmask, Settings.save_data,
|
||||
Settings.flag.save_state, // SetOption0 - Save power state and use after restart
|
||||
Settings.switch_topic,
|
||||
stemp2,
|
||||
Settings.flag.mqtt_button_retain, // CMND_BUTTONRETAIN
|
||||
Settings.flag.mqtt_switch_retain, // CMND_SWITCHRETAIN
|
||||
Settings.flag.mqtt_sensor_retain, // CMND_SENSORRETAIN
|
||||
Settings.flag.mqtt_power_retain); // CMND_POWERRETAIN
|
||||
MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS));
|
||||
}
|
||||
|
||||
@ -404,7 +410,7 @@ void CmndStatus(void)
|
||||
MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "5"));
|
||||
}
|
||||
|
||||
if (((0 == payload) || (6 == payload)) && Settings.flag.mqtt_enabled) {
|
||||
if (((0 == payload) || (6 == payload)) && Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||
#ifdef USE_MQTT_AWS_IOT
|
||||
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS6_MQTT "\":{\"" D_CMND_MQTTHOST "\":\"%s%s\",\"" D_CMND_MQTTPORT "\":%d,\"" D_CMND_MQTTCLIENT D_JSON_MASK "\":\"%s\",\""
|
||||
D_CMND_MQTTCLIENT "\":\"%s\",\"" D_JSON_MQTT_COUNT "\":%d,\"MAX_PACKET_SIZE\":%d,\"KEEPALIVE\":%d}}"),
|
||||
@ -483,7 +489,7 @@ void CmndState(void)
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN);
|
||||
}
|
||||
#ifdef USE_HOME_ASSISTANT
|
||||
if (Settings.flag.hass_discovery) {
|
||||
if (Settings.flag.hass_discovery) { // SetOption19 - Control Home Assistantautomatic discovery (See SetOption59)
|
||||
HAssPublishStatus();
|
||||
}
|
||||
#endif // USE_HOME_ASSISTANT
|
||||
@ -526,7 +532,7 @@ void CmndOtaUrl(void)
|
||||
void CmndSeriallog(void)
|
||||
{
|
||||
if ((XdrvMailbox.payload >= LOG_LEVEL_NONE) && (XdrvMailbox.payload <= LOG_LEVEL_DEBUG_MORE)) {
|
||||
Settings.flag.mqtt_serial = 0;
|
||||
Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG
|
||||
SetSeriallog(XdrvMailbox.payload);
|
||||
}
|
||||
Response_P(S_JSON_COMMAND_NVALUE_ACTIVE_NVALUE, XdrvMailbox.command, Settings.seriallog_level, seriallog_level);
|
||||
@ -1061,8 +1067,8 @@ void CmndSerialSend(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 5)) {
|
||||
SetSeriallog(LOG_LEVEL_NONE);
|
||||
Settings.flag.mqtt_serial = 1;
|
||||
Settings.flag.mqtt_serial_raw = (XdrvMailbox.index > 3) ? 1 : 0;
|
||||
Settings.flag.mqtt_serial = 1; // CMND_SERIALSEND and CMND_SERIALLOG
|
||||
Settings.flag.mqtt_serial_raw = (XdrvMailbox.index > 3) ? 1 : 0; // CMND_SERIALSEND3
|
||||
if (XdrvMailbox.data_len > 0) {
|
||||
if (1 == XdrvMailbox.index) {
|
||||
Serial.printf("%s\n", XdrvMailbox.data); // "Hello Tiger\n"
|
||||
@ -1290,7 +1296,7 @@ void CmndInterlock(void)
|
||||
if (minimal_bits < 2) { Settings.interlock[i] = 0; } // Discard single relay as interlock
|
||||
}
|
||||
} else {
|
||||
Settings.flag.interlock = XdrvMailbox.payload &1; // Enable/disable interlock
|
||||
Settings.flag.interlock = XdrvMailbox.payload &1; // CMND_INTERLOCK - Enable/disable interlock
|
||||
if (Settings.flag.interlock) {
|
||||
SetDevicePower(power, SRC_IGNORE); // Remove multiple relays if set
|
||||
}
|
||||
@ -1320,7 +1326,7 @@ void CmndInterlock(void)
|
||||
}
|
||||
ResponseAppend_P(PSTR("\"}"));
|
||||
} else {
|
||||
Settings.flag.interlock = 0;
|
||||
Settings.flag.interlock = 0; // CMND_INTERLOCK - Enable/disable interlock
|
||||
ResponseCmndStateText(Settings.flag.interlock);
|
||||
}
|
||||
}
|
||||
|
@ -520,7 +520,7 @@ void WifiCheck(uint8_t param)
|
||||
#endif // USE_WEBSERVER
|
||||
|
||||
#ifdef USE_KNX
|
||||
if (!knx_started && Settings.flag.knx_enabled) {
|
||||
if (!knx_started && Settings.flag.knx_enabled) { // CMND_KNX_ENABLED
|
||||
KNXStart();
|
||||
knx_started = true;
|
||||
}
|
||||
@ -574,7 +574,9 @@ void WifiDisconnect(void)
|
||||
void EspRestart(void)
|
||||
{
|
||||
delay(100); // Allow time for message xfer - disabled v6.1.0b
|
||||
if (Settings.flag.mqtt_enabled) MqttDisconnect();
|
||||
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||
MqttDisconnect();
|
||||
}
|
||||
WifiDisconnect();
|
||||
// ESP.restart(); // This results in exception 3 on restarts on core 2.3.0
|
||||
ESP.reset();
|
||||
|
@ -342,7 +342,7 @@ void SetDevicePower(power_t rpower, uint32_t source)
|
||||
rpower = power;
|
||||
}
|
||||
|
||||
if (Settings.flag.interlock) { // Allow only one or no relay set
|
||||
if (Settings.flag.interlock) { // Allow only one or no relay set - CMND_INTERLOCK - Enable/disable interlock
|
||||
for (uint32_t i = 0; i < MAX_INTERLOCKS; i++) {
|
||||
power_t mask = 1;
|
||||
uint32_t count = 0;
|
||||
@ -526,12 +526,12 @@ bool SendKey(uint32_t key, uint32_t device, uint32_t state)
|
||||
|
||||
char *tmp = (key) ? Settings.switch_topic : Settings.button_topic;
|
||||
Format(key_topic, tmp, sizeof(key_topic));
|
||||
if (Settings.flag.mqtt_enabled && MqttIsConnected() && (strlen(key_topic) != 0) && strcmp(key_topic, "0")) {
|
||||
if (Settings.flag.mqtt_enabled && MqttIsConnected() && (strlen(key_topic) != 0) && strcmp(key_topic, "0")) { // SetOption3 - Enable MQTT
|
||||
if (!key && (device > devices_present)) {
|
||||
device = 1; // Only allow number of buttons up to number of devices
|
||||
}
|
||||
GetTopic_P(stopic, CMND, key_topic,
|
||||
GetPowerDevice(scommand, device, sizeof(scommand), (key + Settings.flag.device_index_enable))); // cmnd/switchtopic/POWERx
|
||||
GetPowerDevice(scommand, device, sizeof(scommand), (key + Settings.flag.device_index_enable))); // cmnd/switchtopic/POWERx - SetOption26 - Switch between POWER or POWER1
|
||||
if (CLEAR_RETAIN == state) {
|
||||
mqtt_data[0] = '\0';
|
||||
} else {
|
||||
@ -542,10 +542,12 @@ bool SendKey(uint32_t key, uint32_t device, uint32_t state)
|
||||
}
|
||||
#ifdef USE_DOMOTICZ
|
||||
if (!(DomoticzSendKey(key, device, state, strlen(mqtt_data)))) {
|
||||
MqttPublishDirect(stopic, ((key) ? Settings.flag.mqtt_switch_retain : Settings.flag.mqtt_button_retain) && (state != POWER_HOLD || !Settings.flag3.no_hold_retain));
|
||||
#endif // USE_DOMOTICZ
|
||||
MqttPublishDirect(stopic, ((key) ? Settings.flag.mqtt_switch_retain // CMND_SWITCHRETAIN
|
||||
: Settings.flag.mqtt_button_retain) && // CMND_BUTTONRETAIN
|
||||
(state != POWER_HOLD || !Settings.flag3.no_hold_retain)); // SetOption62 - Don't use retain flag on HOLD messages
|
||||
#ifdef USE_DOMOTICZ
|
||||
}
|
||||
#else
|
||||
MqttPublishDirect(stopic, ((key) ? Settings.flag.mqtt_switch_retain : Settings.flag.mqtt_button_retain) && (state != POWER_HOLD || !Settings.flag3.no_hold_retain));
|
||||
#endif // USE_DOMOTICZ
|
||||
result = !Settings.flag3.button_switch_force_local;
|
||||
} else {
|
||||
@ -577,7 +579,7 @@ void ExecuteCommandPower(uint32_t device, uint32_t state, uint32_t source)
|
||||
#ifdef USE_SONOFF_IFAN
|
||||
if (IsModuleIfan()) {
|
||||
blink_mask &= 1; // No blinking on the fan relays
|
||||
Settings.flag.interlock = 0; // No interlock mode as it is already done by the microcontroller
|
||||
Settings.flag.interlock = 0; // No interlock mode as it is already done by the microcontroller - CMND_INTERLOCK - Enable/disable interlock
|
||||
Settings.pulse_timer[1] = 0; // No pulsetimers on the fan relays
|
||||
Settings.pulse_timer[2] = 0;
|
||||
Settings.pulse_timer[3] = 0;
|
||||
@ -605,7 +607,7 @@ void ExecuteCommandPower(uint32_t device, uint32_t state, uint32_t source)
|
||||
MqttPublishPowerBlinkState(device);
|
||||
}
|
||||
|
||||
if (Settings.flag.interlock &&
|
||||
if (Settings.flag.interlock && // CMND_INTERLOCK - Enable/disable interlock
|
||||
!interlock_mutex &&
|
||||
((POWER_ON == state) || ((POWER_TOGGLE == state) && !(power & mask)))
|
||||
) {
|
||||
@ -722,7 +724,8 @@ void MqttShowState(void)
|
||||
if (i == LightDevice()) { LightState(1); } // call it only once
|
||||
} else {
|
||||
#endif
|
||||
ResponseAppend_P(PSTR(",\"%s\":\"%s\""), GetPowerDevice(stemp1, i, sizeof(stemp1), Settings.flag.device_index_enable), GetStateText(bitRead(power, i-1)));
|
||||
ResponseAppend_P(PSTR(",\"%s\":\"%s\""), GetPowerDevice(stemp1, i, sizeof(stemp1), Settings.flag.device_index_enable), // SetOption26 - Switch between POWER or POWER1
|
||||
GetStateText(bitRead(power, i-1)));
|
||||
#ifdef USE_SONOFF_IFAN
|
||||
if (IsModuleIfan()) {
|
||||
ResponseAppend_P(PSTR(",\"" D_CMND_FANSPEED "\":%d"), GetFanspeed());
|
||||
@ -847,7 +850,7 @@ void PerformEverySecond(void)
|
||||
|
||||
mqtt_data[0] = '\0';
|
||||
if (MqttShowSensor()) {
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
#if defined(USE_RULES) || defined(USE_SCRIPT)
|
||||
RulesTeleperiod(); // Allow rule based HA messages
|
||||
#endif // USE_RULES
|
||||
@ -914,7 +917,7 @@ void Every250mSeconds(void)
|
||||
|
||||
if (mqtt_cmnd_publish) mqtt_cmnd_publish--; // Clean up
|
||||
|
||||
if (!Settings.flag.global_state) { // Problem blinkyblinky enabled
|
||||
if (!Settings.flag.global_state) { // Problem blinkyblinky enabled - SetOption31 - Control link led blinking
|
||||
if (global_state.data) { // Any problem
|
||||
if (global_state.mqtt_down) { blinkinterval = 7; } // MQTT problem so blink every 2 seconds (slowest)
|
||||
if (global_state.wifi_down) { blinkinterval = 3; } // Wifi problem so blink every second (slow)
|
||||
@ -1027,7 +1030,7 @@ void Every250mSeconds(void)
|
||||
if (save_data_counter && BACKLOG_EMPTY) {
|
||||
save_data_counter--;
|
||||
if (save_data_counter <= 0) {
|
||||
if (Settings.flag.save_state) {
|
||||
if (Settings.flag.save_state) { // SetOption0 - Save power state and use after restart
|
||||
power_t mask = POWER_MASK;
|
||||
for (uint32_t i = 0; i < MAX_PULSETIMERS; i++) {
|
||||
if ((Settings.pulse_timer[i] > 0) && (Settings.pulse_timer[i] < 30)) { // 3 seconds
|
||||
@ -1127,7 +1130,9 @@ void ArduinoOTAInit(void)
|
||||
#ifdef USE_ARILUX_RF
|
||||
AriluxRfDisable(); // Prevent restart exception on Arilux Interrupt routine
|
||||
#endif // USE_ARILUX_RF
|
||||
if (Settings.flag.mqtt_enabled) { MqttDisconnect(); }
|
||||
if (Settings.flag.mqtt_enabled) {
|
||||
MqttDisconnect(); // SetOption3 - Enable MQTT
|
||||
}
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_UPLOAD "Arduino OTA " D_UPLOAD_STARTED));
|
||||
arduino_ota_triggered = true;
|
||||
arduino_ota_progress_dot_count = 0;
|
||||
@ -1201,12 +1206,12 @@ void SerialInput(void)
|
||||
|
||||
/*-------------------------------------------------------------------------------------------*/
|
||||
|
||||
if (serial_in_byte > 127 && !Settings.flag.mqtt_serial_raw) { // Discard binary data above 127 if no raw reception allowed
|
||||
if (serial_in_byte > 127 && !Settings.flag.mqtt_serial_raw) { // Discard binary data above 127 if no raw reception allowed - CMND_SERIALSEND3
|
||||
serial_in_byte_counter = 0;
|
||||
Serial.flush();
|
||||
return;
|
||||
}
|
||||
if (!Settings.flag.mqtt_serial) { // SerialSend active
|
||||
if (!Settings.flag.mqtt_serial) { // SerialSend active - CMND_SERIALSEND and CMND_SERIALLOG
|
||||
if (isprint(serial_in_byte)) { // Any char between 32 and 127
|
||||
if (serial_in_byte_counter < INPUT_BUFFER_SIZE -1) { // Add char to string if it still fits
|
||||
serial_in_buffer[serial_in_byte_counter++] = serial_in_byte;
|
||||
@ -1215,11 +1220,11 @@ void SerialInput(void)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (serial_in_byte || Settings.flag.mqtt_serial_raw) { // Any char between 1 and 127 or any char (0 - 255)
|
||||
if (serial_in_byte || Settings.flag.mqtt_serial_raw) { // Any char between 1 and 127 or any char (0 - 255) - CMND_SERIALSEND3
|
||||
if ((serial_in_byte_counter < INPUT_BUFFER_SIZE -1) && // Add char to string if it still fits and ...
|
||||
((isprint(serial_in_byte) && (128 == Settings.serial_delimiter)) || // Any char between 32 and 127
|
||||
((serial_in_byte != Settings.serial_delimiter) && (128 != Settings.serial_delimiter)) || // Any char between 1 and 127 and not being delimiter
|
||||
Settings.flag.mqtt_serial_raw)) { // Any char between 0 and 255
|
||||
Settings.flag.mqtt_serial_raw)) { // Any char between 0 and 255 - CMND_SERIALSEND3
|
||||
serial_in_buffer[serial_in_byte_counter++] = serial_in_byte;
|
||||
serial_polling_window = millis();
|
||||
} else {
|
||||
@ -1245,7 +1250,7 @@ void SerialInput(void)
|
||||
#endif // USE_SONOFF_SC
|
||||
/*-------------------------------------------------------------------------------------------*/
|
||||
|
||||
if (!Settings.flag.mqtt_serial && (serial_in_byte == '\n')) {
|
||||
if (!Settings.flag.mqtt_serial && (serial_in_byte == '\n')) { // CMND_SERIALSEND and CMND_SERIALLOG
|
||||
serial_in_buffer[serial_in_byte_counter] = 0; // Serial data completed
|
||||
seriallog_level = (Settings.seriallog_level < LOG_LEVEL_INFO) ? (uint8_t)LOG_LEVEL_INFO : Settings.seriallog_level;
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_COMMAND "%s"), serial_in_buffer);
|
||||
@ -1257,7 +1262,7 @@ void SerialInput(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (Settings.flag.mqtt_serial && serial_in_byte_counter && (millis() > (serial_polling_window + SERIAL_POLLING))) {
|
||||
if (Settings.flag.mqtt_serial && serial_in_byte_counter && (millis() > (serial_polling_window + SERIAL_POLLING))) { // CMND_SERIALSEND and CMND_SERIALLOG
|
||||
serial_in_buffer[serial_in_byte_counter] = 0; // Serial data completed
|
||||
char hex_char[(serial_in_byte_counter * 2) + 2];
|
||||
Response_P(PSTR(",\"" D_JSON_SERIALRECEIVED "\":\"%s\"}"),
|
||||
@ -1410,18 +1415,18 @@ void GpioInit(void)
|
||||
// devices_present = 1;
|
||||
}
|
||||
else if (SONOFF_DUAL == my_module_type) {
|
||||
Settings.flag.mqtt_serial = 0;
|
||||
Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG
|
||||
devices_present = 2;
|
||||
baudrate = 19200;
|
||||
}
|
||||
else if (CH4 == my_module_type) {
|
||||
Settings.flag.mqtt_serial = 0;
|
||||
Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG
|
||||
devices_present = 4;
|
||||
baudrate = 19200;
|
||||
}
|
||||
#ifdef USE_SONOFF_SC
|
||||
else if (SONOFF_SC == my_module_type) {
|
||||
Settings.flag.mqtt_serial = 0;
|
||||
Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG
|
||||
devices_present = 0;
|
||||
baudrate = 19200;
|
||||
}
|
||||
@ -1524,7 +1529,7 @@ void setup(void)
|
||||
seriallog_level = Settings.seriallog_level;
|
||||
seriallog_timer = SERIALLOG_TIMER;
|
||||
syslog_level = Settings.syslog_level;
|
||||
stop_flash_rotate = Settings.flag.stop_flash_rotate;
|
||||
stop_flash_rotate = Settings.flag.stop_flash_rotate; // SetOption12 - Switch between dynamic or fixed slot flash save location
|
||||
save_data_counter = Settings.save_data;
|
||||
sleep = Settings.sleep;
|
||||
#ifndef USE_EMULATION
|
||||
@ -1598,20 +1603,20 @@ void setup(void)
|
||||
break;
|
||||
case POWER_ALL_SAVED_TOGGLE:
|
||||
power = (Settings.power & ((1 << devices_present) -1)) ^ POWER_MASK;
|
||||
if (Settings.flag.save_state) {
|
||||
if (Settings.flag.save_state) { // SetOption0 - Save power state and use after restart
|
||||
SetDevicePower(power, SRC_RESTART);
|
||||
}
|
||||
break;
|
||||
case POWER_ALL_SAVED:
|
||||
power = Settings.power & ((1 << devices_present) -1);
|
||||
if (Settings.flag.save_state) {
|
||||
if (Settings.flag.save_state) { // SetOption0 - Save power state and use after restart
|
||||
SetDevicePower(power, SRC_RESTART);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
power = Settings.power & ((1 << devices_present) -1);
|
||||
if (Settings.flag.save_state) {
|
||||
if (Settings.flag.save_state) { // SetOption0 - Save power state and use after restart
|
||||
SetDevicePower(power, SRC_RESTART);
|
||||
}
|
||||
}
|
||||
|
@ -991,7 +991,7 @@ void HandleRoot(void)
|
||||
if (devices_present) {
|
||||
#ifdef USE_LIGHT
|
||||
if (light_type) {
|
||||
if (!Settings.flag3.pwm_multi_channels) {
|
||||
if (!Settings.flag3.pwm_multi_channels) { // SetOption68 0
|
||||
if ((LST_COLDWARM == (light_type &7)) || (LST_RGBWC == (light_type &7))) {
|
||||
// Cold - Warm &t related to lb("t", value) and WebGetArg("t", tmp, sizeof(tmp));
|
||||
WSContentSend_P(HTTP_MSG_SLIDER1, F(D_COLDLIGHT), F(D_WARMLIGHT),
|
||||
@ -1000,7 +1000,7 @@ void HandleRoot(void)
|
||||
// Dark - Bright &d related to lb("d", value) and WebGetArg("d", tmp, sizeof(tmp));
|
||||
WSContentSend_P(HTTP_MSG_SLIDER1, F(D_DARKLIGHT), F(D_BRIGHTLIGHT),
|
||||
1, 100, Settings.light_dimmer, 'd');
|
||||
} else { // Settings.flag3.pwm_multi_channels
|
||||
} else { // Settings.flag3.pwm_multi_channels - SetOption68 1
|
||||
uint32_t pwm_channels = (light_type & 7) > LST_MAX ? LST_MAX : (light_type & 7);
|
||||
for (uint32_t i = 0; i < pwm_channels; i++) {
|
||||
snprintf_P(stemp, sizeof(stemp), PSTR("c%d"), i);
|
||||
@ -1012,7 +1012,7 @@ void HandleRoot(void)
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_SHUTTER
|
||||
if (Settings.flag3.shutter_mode) {
|
||||
if (Settings.flag3.shutter_mode) { // SetOption80 1
|
||||
for (uint32_t i = 0; i < shutters_present; i++) {
|
||||
WSContentSend_P(HTTP_MSG_SLIDER2, F(D_CLOSE), F(D_OPEN),
|
||||
0, 100, Settings.shutter_position[i], 'u', i+1);
|
||||
@ -1625,7 +1625,7 @@ void HandleLoggingConfiguration(void)
|
||||
char stemp2[32];
|
||||
uint8_t dlevel[4] = { LOG_LEVEL_INFO, LOG_LEVEL_INFO, LOG_LEVEL_NONE, LOG_LEVEL_NONE };
|
||||
for (uint32_t idx = 0; idx < 4; idx++) {
|
||||
if ((2==idx) && !Settings.flag.mqtt_enabled) { continue; }
|
||||
if ((2==idx) && !Settings.flag.mqtt_enabled) { continue; } // SetOption3 - Enable MQTT
|
||||
uint32_t llevel = (0==idx)?Settings.seriallog_level:(1==idx)?Settings.weblog_level:(2==idx)?Settings.mqttlog_level:Settings.syslog_level;
|
||||
WSContentSend_P(PSTR("<p><b>%s</b> (%s)<br><select id='l%d'>"),
|
||||
GetTextIndexed(stemp1, sizeof(stemp1), idx, kLoggingOptions),
|
||||
@ -1689,7 +1689,7 @@ void HandleOtherConfiguration(void)
|
||||
TemplateJson();
|
||||
char stemp[strlen(mqtt_data) +1];
|
||||
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" : ""); // SetOption3 - Enable MQTT
|
||||
|
||||
uint32_t maxfn = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : (!devices_present) ? 1 : devices_present;
|
||||
#ifdef USE_SONOFF_IFAN
|
||||
@ -1738,7 +1738,7 @@ void OtherSaveSettings(void)
|
||||
|
||||
WebGetArg("wp", tmp, sizeof(tmp));
|
||||
strlcpy(Settings.web_password, (!strlen(tmp)) ? "" : (strchr(tmp,'*')) ? Settings.web_password : tmp, sizeof(Settings.web_password));
|
||||
Settings.flag.mqtt_enabled = WebServer->hasArg("b1");
|
||||
Settings.flag.mqtt_enabled = WebServer->hasArg("b1"); // SetOption3 - Enable MQTT
|
||||
#ifdef USE_EMULATION
|
||||
WebGetArg("b2", tmp, sizeof(tmp));
|
||||
Settings.flag2.emulation = (!strlen(tmp)) ? 0 : atoi(tmp);
|
||||
@ -1900,7 +1900,7 @@ void HandleInformation(void)
|
||||
WSContentSend_P(PSTR("}1" D_MAC_ADDRESS "}2%s"), WiFi.softAPmacAddress().c_str());
|
||||
}
|
||||
WSContentSend_P(PSTR("}1}2 ")); // Empty line
|
||||
if (Settings.flag.mqtt_enabled) {
|
||||
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||
#ifdef USE_MQTT_AWS_IOT
|
||||
WSContentSend_P(PSTR("}1" D_MQTT_HOST "}2%s%s"), Settings.mqtt_user, Settings.mqtt_host);
|
||||
WSContentSend_P(PSTR("}1" D_MQTT_PORT "}2%d"), Settings.mqtt_port);
|
||||
@ -2039,7 +2039,7 @@ void HandleUploadDone(void)
|
||||
}
|
||||
WSContentSend_P(error);
|
||||
DEBUG_CORE_LOG(PSTR("UPL: %s"), error);
|
||||
stop_flash_rotate = Settings.flag.stop_flash_rotate;
|
||||
stop_flash_rotate = Settings.flag.stop_flash_rotate; // SetOption12 - Switch between dynamic or fixed slot flash save location
|
||||
} else {
|
||||
WSContentSend_P(PSTR("%06x'>" D_SUCCESSFUL "</font></b><br>"), WebColor(COL_TEXT_SUCCESS));
|
||||
WSContentSend_P(HTTP_MSG_RSTRT);
|
||||
@ -2099,7 +2099,9 @@ void HandleUploadLoop(void)
|
||||
#ifdef USE_ARILUX_RF
|
||||
AriluxRfDisable(); // Prevent restart exception on Arilux Interrupt routine
|
||||
#endif // USE_ARILUX_RF
|
||||
if (Settings.flag.mqtt_enabled) MqttDisconnect();
|
||||
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||
MqttDisconnect();
|
||||
}
|
||||
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||
if (!Update.begin(maxSketchSpace)) { //start with max available size
|
||||
|
||||
|
@ -316,7 +316,7 @@ void MqttUnsubscribe(const char *topic)
|
||||
|
||||
void MqttPublishLogging(const char *mxtime)
|
||||
{
|
||||
if (Settings.flag.mqtt_enabled) {
|
||||
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||
if (MqttIsConnected()) {
|
||||
|
||||
char saved_mqtt_data[MESSZ];
|
||||
@ -355,7 +355,7 @@ void MqttPublishDirect(const char* topic, bool retained)
|
||||
sretained[0] = '\0';
|
||||
snprintf_P(slog_type, sizeof(slog_type), PSTR(D_LOG_RESULT));
|
||||
|
||||
if (Settings.flag.mqtt_enabled) {
|
||||
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||
if (MqttIsConnected()) {
|
||||
if (MqttPublishLib(topic, retained)) {
|
||||
snprintf_P(slog_type, sizeof(slog_type), PSTR(D_LOG_MQTT));
|
||||
@ -366,7 +366,7 @@ void MqttPublishDirect(const char* topic, bool retained)
|
||||
}
|
||||
}
|
||||
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s%s = %s"), slog_type, (Settings.flag.mqtt_enabled) ? topic : strrchr(topic,'/')+1, mqtt_data);
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s%s = %s"), slog_type, (Settings.flag.mqtt_enabled) ? topic : strrchr(topic,'/')+1, mqtt_data); // SetOption3 - Enable MQTT
|
||||
if (strlen(log_data) >= (sizeof(log_data) - strlen(sretained) -1)) {
|
||||
log_data[sizeof(log_data) - strlen(sretained) -5] = '\0';
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s ..."), log_data);
|
||||
@ -415,7 +415,7 @@ void MqttPublishPrefixTopic_P(uint32_t prefix, const char* subtopic, bool retain
|
||||
char romram[33];
|
||||
char stopic[TOPSZ];
|
||||
|
||||
snprintf_P(romram, sizeof(romram), ((prefix > 3) && !Settings.flag.mqtt_response) ? S_RSLT_RESULT : subtopic);
|
||||
snprintf_P(romram, sizeof(romram), ((prefix > 3) && !Settings.flag.mqtt_response) ? S_RSLT_RESULT : subtopic); // SetOption4 - Switch between MQTT RESULT or COMMAND
|
||||
for (uint32_t i = 0; i < strlen(romram); i++) {
|
||||
romram[i] = toupper(romram[i]);
|
||||
}
|
||||
@ -443,20 +443,20 @@ void MqttPublishPowerState(uint32_t device)
|
||||
DomoticzUpdateFanState(); // RC Button feedback
|
||||
#endif // USE_DOMOTICZ
|
||||
snprintf_P(scommand, sizeof(scommand), PSTR(D_CMND_FANSPEED));
|
||||
GetTopic_P(stopic, STAT, mqtt_topic, (Settings.flag.mqtt_response) ? scommand : S_RSLT_RESULT);
|
||||
GetTopic_P(stopic, STAT, mqtt_topic, (Settings.flag.mqtt_response) ? scommand : S_RSLT_RESULT); // SetOption4 - Switch between MQTT RESULT or COMMAND
|
||||
Response_P(S_JSON_COMMAND_NVALUE, scommand, GetFanspeed());
|
||||
MqttPublish(stopic);
|
||||
}
|
||||
} else {
|
||||
#endif // USE_SONOFF_IFAN
|
||||
GetPowerDevice(scommand, device, sizeof(scommand), Settings.flag.device_index_enable);
|
||||
GetTopic_P(stopic, STAT, mqtt_topic, (Settings.flag.mqtt_response) ? scommand : S_RSLT_RESULT);
|
||||
GetPowerDevice(scommand, device, sizeof(scommand), Settings.flag.device_index_enable); // SetOption26 - Switch between POWER or POWER1
|
||||
GetTopic_P(stopic, STAT, mqtt_topic, (Settings.flag.mqtt_response) ? scommand : S_RSLT_RESULT); // SetOption4 - Switch between MQTT RESULT or COMMAND
|
||||
Response_P(S_JSON_COMMAND_SVALUE, scommand, GetStateText(bitRead(power, device -1)));
|
||||
MqttPublish(stopic);
|
||||
|
||||
GetTopic_P(stopic, STAT, mqtt_topic, scommand);
|
||||
Response_P(GetStateText(bitRead(power, device -1)));
|
||||
MqttPublish(stopic, Settings.flag.mqtt_power_retain);
|
||||
MqttPublish(stopic, Settings.flag.mqtt_power_retain); // CMND_POWERRETAIN
|
||||
#ifdef USE_SONOFF_IFAN
|
||||
}
|
||||
#endif // USE_SONOFF_IFAN
|
||||
@ -480,7 +480,7 @@ void MqttPublishPowerBlinkState(uint32_t device)
|
||||
device = 1;
|
||||
}
|
||||
Response_P(PSTR("{\"%s\":\"" D_JSON_BLINK " %s\"}"),
|
||||
GetPowerDevice(scommand, device, sizeof(scommand), Settings.flag.device_index_enable), GetStateText(bitRead(blink_mask, device -1)));
|
||||
GetPowerDevice(scommand, device, sizeof(scommand), Settings.flag.device_index_enable), GetStateText(bitRead(blink_mask, device -1))); // SetOption26 - Switch between POWER or POWER1
|
||||
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_STAT, S_RSLT_POWER);
|
||||
}
|
||||
@ -559,7 +559,7 @@ void MqttConnected(void)
|
||||
Mqtt.initial_connection_state = 0;
|
||||
|
||||
global_state.mqtt_down = 0;
|
||||
if (Settings.flag.mqtt_enabled) {
|
||||
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||
rules_flag.mqtt_connected = 1;
|
||||
}
|
||||
}
|
||||
@ -568,7 +568,7 @@ void MqttReconnect(void)
|
||||
{
|
||||
char stopic[TOPSZ];
|
||||
|
||||
Mqtt.allowed = Settings.flag.mqtt_enabled;
|
||||
Mqtt.allowed = Settings.flag.mqtt_enabled; // SetOption3 - Enable MQTT
|
||||
if (Mqtt.allowed) {
|
||||
#ifdef USE_DISCOVERY
|
||||
#ifdef MQTT_HOST_DISCOVERY
|
||||
@ -697,7 +697,7 @@ void MqttReconnect(void)
|
||||
|
||||
void MqttCheck(void)
|
||||
{
|
||||
if (Settings.flag.mqtt_enabled) {
|
||||
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||
if (!MqttIsConnected()) {
|
||||
global_state.mqtt_down = 1;
|
||||
if (!Mqtt.retry_counter) {
|
||||
@ -836,7 +836,7 @@ void CmndFullTopic(void)
|
||||
char stemp1[TOPSZ];
|
||||
strlcpy(stemp1, (SC_DEFAULT == Shortcut()) ? MQTT_FULLTOPIC : XdrvMailbox.data, sizeof(stemp1));
|
||||
if (strcmp(stemp1, Settings.mqtt_fulltopic)) {
|
||||
Response_P((Settings.flag.mqtt_offline) ? S_OFFLINE : "");
|
||||
Response_P((Settings.flag.mqtt_offline) ? S_OFFLINE : ""); // SetOption10 - Control MQTT LWT message format
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_LWT), true); // Offline or remove previous retained topic
|
||||
strlcpy(Settings.mqtt_fulltopic, stemp1, sizeof(Settings.mqtt_fulltopic));
|
||||
restart_flag = 2;
|
||||
@ -897,7 +897,7 @@ void CmndTopic(void)
|
||||
char stemp1[TOPSZ];
|
||||
strlcpy(stemp1, (SC_DEFAULT == Shortcut()) ? MQTT_TOPIC : XdrvMailbox.data, sizeof(stemp1));
|
||||
if (strcmp(stemp1, Settings.mqtt_topic)) {
|
||||
Response_P((Settings.flag.mqtt_offline) ? S_OFFLINE : "");
|
||||
Response_P((Settings.flag.mqtt_offline) ? S_OFFLINE : ""); // SetOption10 - Control MQTT LWT message format
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_LWT), true); // Offline or remove previous retained topic
|
||||
strlcpy(Settings.mqtt_topic, stemp1, sizeof(Settings.mqtt_topic));
|
||||
restart_flag = 2;
|
||||
@ -944,9 +944,9 @@ void CmndButtonRetain(void)
|
||||
SendKey(KEY_BUTTON, i, CLEAR_RETAIN); // Clear MQTT retain in broker
|
||||
}
|
||||
}
|
||||
Settings.flag.mqtt_button_retain = XdrvMailbox.payload;
|
||||
Settings.flag.mqtt_button_retain = XdrvMailbox.payload; // CMND_BUTTONRETAIN
|
||||
}
|
||||
ResponseCmndStateText(Settings.flag.mqtt_button_retain);
|
||||
ResponseCmndStateText(Settings.flag.mqtt_button_retain); // CMND_BUTTONRETAIN
|
||||
}
|
||||
|
||||
void CmndSwitchRetain(void)
|
||||
@ -957,9 +957,9 @@ void CmndSwitchRetain(void)
|
||||
SendKey(KEY_SWITCH, i, CLEAR_RETAIN); // Clear MQTT retain in broker
|
||||
}
|
||||
}
|
||||
Settings.flag.mqtt_switch_retain = XdrvMailbox.payload;
|
||||
Settings.flag.mqtt_switch_retain = XdrvMailbox.payload; // CMND_SWITCHRETAIN
|
||||
}
|
||||
ResponseCmndStateText(Settings.flag.mqtt_switch_retain);
|
||||
ResponseCmndStateText(Settings.flag.mqtt_switch_retain); // CMND_SWITCHRETAIN
|
||||
}
|
||||
|
||||
void CmndPowerRetain(void)
|
||||
@ -969,14 +969,14 @@ void CmndPowerRetain(void)
|
||||
char stemp1[TOPSZ];
|
||||
char scommand[CMDSZ];
|
||||
for (uint32_t i = 1; i <= devices_present; i++) { // Clear MQTT retain in broker
|
||||
GetTopic_P(stemp1, STAT, mqtt_topic, GetPowerDevice(scommand, i, sizeof(scommand), Settings.flag.device_index_enable));
|
||||
GetTopic_P(stemp1, STAT, mqtt_topic, GetPowerDevice(scommand, i, sizeof(scommand), Settings.flag.device_index_enable)); // SetOption26 - Switch between POWER or POWER1
|
||||
mqtt_data[0] = '\0';
|
||||
MqttPublish(stemp1, Settings.flag.mqtt_power_retain);
|
||||
MqttPublish(stemp1, Settings.flag.mqtt_power_retain); // CMND_POWERRETAIN
|
||||
}
|
||||
}
|
||||
Settings.flag.mqtt_power_retain = XdrvMailbox.payload;
|
||||
Settings.flag.mqtt_power_retain = XdrvMailbox.payload; // CMND_POWERRETAIN
|
||||
}
|
||||
ResponseCmndStateText(Settings.flag.mqtt_power_retain);
|
||||
ResponseCmndStateText(Settings.flag.mqtt_power_retain); // CMND_POWERRETAIN
|
||||
}
|
||||
|
||||
void CmndSensorRetain(void)
|
||||
@ -984,12 +984,12 @@ void CmndSensorRetain(void)
|
||||
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
||||
if (!XdrvMailbox.payload) {
|
||||
mqtt_data[0] = '\0';
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_ENERGY), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_ENERGY), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
}
|
||||
Settings.flag.mqtt_sensor_retain = XdrvMailbox.payload;
|
||||
Settings.flag.mqtt_sensor_retain = XdrvMailbox.payload; // CMND_SENSORRETAIN
|
||||
}
|
||||
ResponseCmndStateText(Settings.flag.mqtt_sensor_retain);
|
||||
ResponseCmndStateText(Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
@ -1250,7 +1250,7 @@ void MqttSaveSettings(void)
|
||||
strlcpy(stemp2, (!strlen(tmp)) ? MQTT_FULLTOPIC : tmp, sizeof(stemp2));
|
||||
MakeValidMqtt(1, stemp2);
|
||||
if ((strcmp(stemp, Settings.mqtt_topic)) || (strcmp(stemp2, Settings.mqtt_fulltopic))) {
|
||||
Response_P((Settings.flag.mqtt_offline) ? S_OFFLINE : "");
|
||||
Response_P((Settings.flag.mqtt_offline) ? S_OFFLINE : ""); // SetOption10 - Control MQTT LWT message format
|
||||
MqttPublishPrefixTopic_P(TELE, S_LWT, true); // Offline or remove previous retained topic
|
||||
}
|
||||
strlcpy(Settings.mqtt_topic, stemp, sizeof(Settings.mqtt_topic));
|
||||
@ -1287,7 +1287,7 @@ bool Xdrv02(uint8_t function)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if (Settings.flag.mqtt_enabled) {
|
||||
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||
switch (function) {
|
||||
case FUNC_PRE_INIT:
|
||||
MqttInit();
|
||||
|
@ -213,7 +213,7 @@ void EnergyUpdateTotal(float value, bool kwh)
|
||||
|
||||
void Energy200ms(void)
|
||||
{
|
||||
Energy.power_on = (power != 0) | Settings.flag.no_power_on_check;
|
||||
Energy.power_on = (power != 0) | Settings.flag.no_power_on_check; // SetOption21 - Show voltage even if powered off
|
||||
|
||||
Energy.fifth_second++;
|
||||
if (5 == Energy.fifth_second) {
|
||||
@ -424,7 +424,7 @@ void EnergyMqttShow(void)
|
||||
EnergyShow(true);
|
||||
tele_period = tele_period_save;
|
||||
ResponseJsonEnd();
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
Energy.power_delta = false;
|
||||
}
|
||||
#endif // USE_ENERGY_MARGIN_DETECTION
|
||||
|
@ -1093,7 +1093,7 @@ bool LightModuleInit(void)
|
||||
{
|
||||
light_type = LT_BASIC; // Use basic PWM control if SetOption15 = 0
|
||||
|
||||
if (Settings.flag.pwm_control) {
|
||||
if (Settings.flag.pwm_control) { // SetOption15 - Switch between commands PWM or COLOR/DIMMER/CT/CHANNEL
|
||||
for (uint32_t i = 0; i < MAX_PWMS; i++) {
|
||||
if (pin[GPIO_PWM1 +i] < 99) { light_type++; } // Use Dimmer/Color control for all PWM as SetOption15 = 1
|
||||
}
|
||||
@ -1301,7 +1301,7 @@ void LightSetSignal(uint16_t lo, uint16_t hi, uint16_t value)
|
||||
/* lo - below lo is green
|
||||
hi - above hi is red
|
||||
*/
|
||||
if (Settings.flag.light_signal) {
|
||||
if (Settings.flag.light_signal) { // SetOption18 - Pair light signal with CO2 sensor
|
||||
uint16_t signal = changeUIntScale(value, lo, hi, 0, 255); // 0..255
|
||||
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "Light signal %d"), signal);
|
||||
light_controller.changeRGB(signal, 255 - signal, 0, true); // keep bri
|
||||
@ -1318,7 +1318,7 @@ char* LightGetColor(char* scolor, boolean force_hex = false)
|
||||
light_controller.calcLevels();
|
||||
scolor[0] = '\0';
|
||||
for (uint32_t i = 0; i < Light.subtype; i++) {
|
||||
if (!force_hex && Settings.flag.decimal_text) {
|
||||
if (!force_hex && Settings.flag.decimal_text) { // SetOption17 - Switch between decimal or hexadecimal output
|
||||
snprintf_P(scolor, LIGHT_COLOR_SIZE, PSTR("%s%s%d"), scolor, (i > 0) ? "," : "", Light.current_color[i]);
|
||||
} else {
|
||||
snprintf_P(scolor, LIGHT_COLOR_SIZE, PSTR("%s%02X"), scolor, Light.current_color[i]);
|
||||
@ -1345,7 +1345,7 @@ void LightState(uint8_t append)
|
||||
Response_P(PSTR("{"));
|
||||
}
|
||||
if (!Light.pwm_multi_channels) {
|
||||
GetPowerDevice(scommand, Light.device, sizeof(scommand), Settings.flag.device_index_enable);
|
||||
GetPowerDevice(scommand, Light.device, sizeof(scommand), Settings.flag.device_index_enable); // SetOption26 - Switch between POWER or POWER1
|
||||
ResponseAppend_P(PSTR("\"%s\":\"%s\",\"" D_CMND_DIMMER "\":%d"), scommand, GetStateText(Light.power), light_state.getDimmer());
|
||||
|
||||
if (Light.subtype > LST_SINGLE) {
|
||||
@ -1429,7 +1429,7 @@ void LightPreparePower(void)
|
||||
} else {
|
||||
if (light_controller.isCTRGBLinked()) { // linked, standard
|
||||
if (light_state.getBri() && !(Light.power)) {
|
||||
if (!Settings.flag.not_power_linked) {
|
||||
if (!Settings.flag.not_power_linked) { // SetOption20 - Control power in relation to Dimmer/Color/Ct changes
|
||||
ExecuteCommandPower(Light.device, POWER_ON_NO_STATE, SRC_LIGHT);
|
||||
}
|
||||
} else if (!light_state.getBri() && Light.power) {
|
||||
@ -1438,7 +1438,7 @@ void LightPreparePower(void)
|
||||
} else {
|
||||
// RGB
|
||||
if (light_state.getBriRGB() && !(Light.power & 1)) {
|
||||
if (!Settings.flag.not_power_linked) {
|
||||
if (!Settings.flag.not_power_linked) { // SetOption20 - Control power in relation to Dimmer/Color/Ct changes
|
||||
ExecuteCommandPower(Light.device, POWER_ON_NO_STATE, SRC_LIGHT);
|
||||
}
|
||||
} else if (!light_state.getBri() && (Light.power & 1)) {
|
||||
@ -1446,7 +1446,7 @@ void LightPreparePower(void)
|
||||
}
|
||||
// White CT
|
||||
if (light_state.getBriCT() && !(Light.power & 2)) {
|
||||
if (!Settings.flag.not_power_linked) {
|
||||
if (!Settings.flag.not_power_linked) { // SetOption20 - Control power in relation to Dimmer/Color/Ct changes
|
||||
ExecuteCommandPower(Light.device + 1, POWER_ON_NO_STATE, SRC_LIGHT);
|
||||
}
|
||||
} else if (!light_state.getBri() && (Light.power & 2)) {
|
||||
@ -1935,7 +1935,7 @@ bool LightColorEntry(char *buffer, uint32_t buffer_length)
|
||||
}
|
||||
}
|
||||
if (entry_type) {
|
||||
Settings.flag.decimal_text = entry_type -1;
|
||||
Settings.flag.decimal_text = entry_type -1; // SetOption17 - Switch between decimal or hexadecimal output
|
||||
}
|
||||
return (entry_type);
|
||||
}
|
||||
@ -1975,7 +1975,7 @@ void CmndSupportColor(void)
|
||||
if (XdrvMailbox.index >= 3) {
|
||||
scolor[0] = '\0';
|
||||
for (uint32_t i = 0; i < LST_RGB; i++) {
|
||||
if (Settings.flag.decimal_text) {
|
||||
if (Settings.flag.decimal_text) { // SetOption17 - Switch between decimal or hexadecimal output
|
||||
snprintf_P(scolor, sizeof(scolor), PSTR("%s%s%d"), scolor, (i > 0) ? "," : "", Settings.ws_color[XdrvMailbox.index -3][i]);
|
||||
} else {
|
||||
snprintf_P(scolor, sizeof(scolor), PSTR("%s%02X"), scolor, Settings.ws_color[XdrvMailbox.index -3][i]);
|
||||
@ -2031,7 +2031,7 @@ void CmndChannel(void)
|
||||
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 100)) {
|
||||
Light.current_color[XdrvMailbox.index - Light.device] = changeUIntScale(XdrvMailbox.payload,0,100,0,255);
|
||||
if (Light.pwm_multi_channels) {
|
||||
// if (!Settings.flag.not_power_linked) { // SetOption20
|
||||
// if (!Settings.flag.not_power_linked) { // SetOption20 - Control power in relation to Dimmer/Color/Ct changes
|
||||
// Light.power = Light.power | (1 << (XdrvMailbox.index - Light.device)); // ask to turn on channel
|
||||
// }
|
||||
} else {
|
||||
|
@ -137,7 +137,7 @@ void IrReceiveCheck(void)
|
||||
ir_lasttime = now;
|
||||
|
||||
char svalue[64];
|
||||
if (Settings.flag.ir_receive_decimal) {
|
||||
if (Settings.flag.ir_receive_decimal) { // SetOption29 - IR receive data format
|
||||
ulltoa(results.value, svalue, 10);
|
||||
} else {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("\"0x%s\""), hvalue);
|
||||
|
@ -161,7 +161,7 @@ String sendIRJsonState(const struct decode_results &results) {
|
||||
} else {
|
||||
json += ",\"" D_JSON_IR_HASH "\":";
|
||||
}
|
||||
if (Settings.flag.ir_receive_decimal) {
|
||||
if (Settings.flag.ir_receive_decimal) { // SetOption29 - IR receive data format
|
||||
char svalue[32];
|
||||
ulltoa(results.value, svalue, 10);
|
||||
json += svalue;
|
||||
|
@ -291,7 +291,7 @@ void SonoffBridgeReceived(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Settings.flag.rf_receive_decimal) {
|
||||
if (Settings.flag.rf_receive_decimal) { // SetOption28 - RF receive data format
|
||||
snprintf_P(stemp, sizeof(stemp), PSTR("%u"), received_id);
|
||||
} else {
|
||||
snprintf_P(stemp, sizeof(stemp), PSTR("\"%06X\""), received_id);
|
||||
@ -578,7 +578,7 @@ bool Xdrv06(uint8_t function)
|
||||
SonoffBridgeSendCommand(0xA7); // Stop reading RF signals enabling iTead default RF handling
|
||||
break;
|
||||
case FUNC_PRE_INIT:
|
||||
Settings.flag.mqtt_serial = 0;
|
||||
Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG
|
||||
baudrate = 19200;
|
||||
break;
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ int DomoticzRssiQuality(void)
|
||||
#ifdef USE_SONOFF_IFAN
|
||||
void MqttPublishDomoticzFanState()
|
||||
{
|
||||
if (Settings.flag.mqtt_enabled && Settings.domoticz_relay_idx[1]) {
|
||||
if (Settings.flag.mqtt_enabled && Settings.domoticz_relay_idx[1]) { // SetOption3 - Enable MQTT
|
||||
char svalue[8]; // Fanspeed value
|
||||
|
||||
int fan_speed = GetFanspeed();
|
||||
@ -105,7 +105,7 @@ void DomoticzUpdateFanState()
|
||||
|
||||
void MqttPublishDomoticzPowerState(uint8_t device)
|
||||
{
|
||||
if (Settings.flag.mqtt_enabled) {
|
||||
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||
if ((device < 1) || (device > devices_present)) { device = 1; }
|
||||
if (Settings.domoticz_relay_idx[device -1]) {
|
||||
#ifdef USE_SONOFF_IFAN
|
||||
@ -574,7 +574,7 @@ bool Xdrv07(uint8_t function)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if (Settings.flag.mqtt_enabled) {
|
||||
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||
switch (function) {
|
||||
case FUNC_EVERY_SECOND:
|
||||
DomoticzMqttUpdate();
|
||||
|
@ -2664,15 +2664,15 @@ int16_t Run_Scripter(const char *type, int8_t tlen, char *js) {
|
||||
// allow recursive call
|
||||
} else {
|
||||
tasm_cmd_activ=1;
|
||||
svmqtt=Settings.flag.mqtt_enabled;
|
||||
svmqtt=Settings.flag.mqtt_enabled; // SetOption3 - Enable MQTT
|
||||
swll=Settings.weblog_level;
|
||||
Settings.flag.mqtt_enabled=0;
|
||||
Settings.flag.mqtt_enabled=0; // SetOption3 - Enable MQTT
|
||||
Settings.weblog_level=0;
|
||||
}
|
||||
ExecuteCommand((char*)tmp, SRC_RULE);
|
||||
tasm_cmd_activ=0;
|
||||
if (sflag==1) {
|
||||
Settings.flag.mqtt_enabled=svmqtt;
|
||||
Settings.flag.mqtt_enabled=svmqtt; // SetOption3 - Enable MQTT
|
||||
Settings.weblog_level=swll;
|
||||
}
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ void HAssAnnounceRelayLight(void)
|
||||
|
||||
for (uint32_t i = 1; i <= MAX_RELAYS; i++) {
|
||||
is_light = ((i == devices_present) && (light_type));
|
||||
is_topic_light = Settings.flag.hass_light || is_light;
|
||||
is_topic_light = Settings.flag.hass_light || is_light; // SetOption30 - Enforce HAss autodiscovery as light
|
||||
|
||||
mqtt_data[0] = '\0'; // Clear retained message
|
||||
|
||||
@ -224,7 +224,7 @@ void HAssAnnounceRelayLight(void)
|
||||
snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/%s/%s/config"),
|
||||
(is_topic_light) ? "light" : "switch", unique_id);
|
||||
|
||||
if (Settings.flag.hass_discovery && (i <= devices_present)) {
|
||||
if (Settings.flag.hass_discovery && (i <= devices_present)) { // SetOption19 - Control Home Assistantautomatic discovery (See SetOption59)
|
||||
char name[33+2]; // friendlyname(33) + " " + index
|
||||
char value_template[33];
|
||||
char prefix[TOPSZ];
|
||||
@ -237,7 +237,7 @@ void HAssAnnounceRelayLight(void)
|
||||
} else {
|
||||
snprintf_P(name, sizeof(name), Settings.friendlyname[i -1]);
|
||||
}
|
||||
GetPowerDevice(value_template, i, sizeof(value_template), Settings.flag.device_index_enable);
|
||||
GetPowerDevice(value_template, i, sizeof(value_template), Settings.flag.device_index_enable); // SetOption26 - Switch between POWER or POWER1
|
||||
GetTopic_P(command_topic, CMND, mqtt_topic, value_template);
|
||||
//GetTopic_P(state_topic, STAT, mqtt_topic, S_RSLT_RESULT);
|
||||
GetTopic_P(state_topic, TELE, mqtt_topic, D_RSLT_STATE);
|
||||
@ -257,7 +257,7 @@ void HAssAnnounceRelayLight(void)
|
||||
|
||||
GetTopic_P(brightness_command_topic, CMND, mqtt_topic, D_CMND_DIMMER);
|
||||
Shorten(&brightness_command_topic, prefix);
|
||||
strncpy_P(stemp3, Settings.flag.not_power_linked?PSTR("last"):PSTR("brightness"), sizeof(stemp3));
|
||||
strncpy_P(stemp3, Settings.flag.not_power_linked?PSTR("last"):PSTR("brightness"), sizeof(stemp3)); // SetOption20 - Control power in relation to Dimmer/Color/Ct changes
|
||||
TryResponseAppend_P(HASS_DISCOVER_LIGHT_DIMMER, brightness_command_topic, state_topic, stemp3);
|
||||
|
||||
if (Light.subtype >= LST_RGB) {
|
||||
@ -310,7 +310,7 @@ void HAssAnnounceButtonSwitch(uint8_t device, char* topic, uint8_t present, uint
|
||||
snprintf_P(unique_id, sizeof(unique_id), PSTR("%06X_%s_%d"), ESP.getChipId(), key?"SW":"BTN", device+1);
|
||||
snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/binary_sensor/%s/config"), unique_id);
|
||||
|
||||
if (Settings.flag.hass_discovery && present) {
|
||||
if (Settings.flag.hass_discovery && present) { // SetOption19 - Control Home Assistantautomatic discovery (See SetOption59)
|
||||
char name[33+6]; // friendlyname(33) + " " + "BTN" + " " + index
|
||||
char value_template[33];
|
||||
char prefix[TOPSZ];
|
||||
@ -320,7 +320,7 @@ void HAssAnnounceButtonSwitch(uint8_t device, char* topic, uint8_t present, uint
|
||||
|
||||
snprintf_P(name, sizeof(name), PSTR("%s %s%d"), Settings.friendlyname[0], key?"Switch":"Button", device+1);
|
||||
GetPowerDevice(value_template, device+1, sizeof(value_template),
|
||||
key + Settings.flag.device_index_enable); // Force index for Switch 1, Index on Button1 is controlled by Settings.flag.device_index_enable
|
||||
key + Settings.flag.device_index_enable); // Force index for Switch 1, Index on Button1 is controlled by SetOption26 - Switch between POWER or POWER1
|
||||
//GetTopic_P(state_topic, CMND, topic, value_template); // State of button is sent as CMND TOGGLE, state of switch is sent as ON/OFF
|
||||
GetTopic_P(state_topic, STAT, mqtt_topic, PSTR(D_RSLT_RESULT));
|
||||
GetTopic_P(availability_topic, TELE, mqtt_topic, S_LWT);
|
||||
@ -420,7 +420,7 @@ void HAssAnnounceSensor(const char* sensorname, const char* subsensortype)
|
||||
} else {
|
||||
snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/sensor/%s/config"), unique_id);
|
||||
}
|
||||
if (Settings.flag.hass_discovery) {
|
||||
if (Settings.flag.hass_discovery) { // SetOption19 - Control Home Assistantautomatic discovery (See SetOption59)
|
||||
char name[33+42]; // friendlyname(33) + " " + sensorname(20?) + " " + sensortype(20?)
|
||||
char prefix[TOPSZ];
|
||||
char *state_topic = stemp1;
|
||||
@ -531,7 +531,7 @@ void HAssAnnounceStatusSensor(void)
|
||||
snprintf_P(unique_id, sizeof(unique_id), PSTR("%06X_status"), ESP.getChipId());
|
||||
snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/sensor/%s/config"), unique_id);
|
||||
|
||||
if (Settings.flag.hass_discovery) {
|
||||
if (Settings.flag.hass_discovery) { // SetOption19 - Control Home Assistantautomatic discovery (See SetOption59)
|
||||
char name[33+7]; // friendlyname(33) + " " + "status"
|
||||
char prefix[TOPSZ];
|
||||
char *state_topic = stemp1;
|
||||
@ -572,9 +572,9 @@ void HAssPublishStatus(void)
|
||||
void HAssDiscovery(void)
|
||||
{
|
||||
// Configure Tasmota for default Home Assistant parameters to keep discovery message as short as possible
|
||||
if (Settings.flag.hass_discovery) {
|
||||
Settings.flag.mqtt_response = 0; // Response always as RESULT and not as uppercase command
|
||||
Settings.flag.decimal_text = 1; // Respond with decimal color values
|
||||
if (Settings.flag.hass_discovery) { // SetOption19 - Control Home Assistantautomatic discovery (See SetOption59)
|
||||
Settings.flag.mqtt_response = 0; // SetOption4 - Switch between MQTT RESULT or COMMAND - Response always as RESULT and not as uppercase command
|
||||
Settings.flag.decimal_text = 1; // SetOption17 - Switch between decimal or hexadecimal output - Respond with decimal color values
|
||||
Settings.flag3.hass_tele_on_power = 1; // send tele/STATE message as stat/RESULT
|
||||
// Settings.light_scheme = 0; // To just control color it needs to be Scheme 0
|
||||
if (strcmp_P(Settings.mqtt_fulltopic, PSTR("%topic%/%prefix%/"))) {
|
||||
@ -584,7 +584,7 @@ void HAssDiscovery(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (Settings.flag.hass_discovery || (1 == hass_mode)) {
|
||||
if (Settings.flag.hass_discovery || (1 == hass_mode)) { // SetOption19 - Control Home Assistantautomatic discovery (See SetOption59)
|
||||
// Send info about relays and lights
|
||||
HAssAnnounceRelayLight();
|
||||
|
||||
@ -610,7 +610,7 @@ void HAssDiscover(void)
|
||||
|
||||
void HAssAnyKey(void)
|
||||
{
|
||||
if (!Settings.flag.hass_discovery) { return; }
|
||||
if (!Settings.flag.hass_discovery) { return; } // SetOption19 - Control Home Assistantautomatic discovery (See SetOption59)
|
||||
|
||||
uint32_t key = (XdrvMailbox.payload >> 16) & 0xFF;
|
||||
uint32_t device = XdrvMailbox.payload & 0xFF;
|
||||
@ -619,7 +619,7 @@ void HAssAnyKey(void)
|
||||
char scommand[CMDSZ];
|
||||
snprintf_P(scommand, sizeof(scommand), PSTR("%s%d"), (key) ? "SWITCH" : "BUTTON", device);
|
||||
char stopic[TOPSZ];
|
||||
GetTopic_P(stopic, STAT, mqtt_topic, (Settings.flag.mqtt_response) ? scommand : S_RSLT_RESULT);
|
||||
GetTopic_P(stopic, STAT, mqtt_topic, (Settings.flag.mqtt_response) ? scommand : S_RSLT_RESULT); // SetOption4 - Switch between MQTT RESULT or COMMAND
|
||||
Response_P(S_JSON_COMMAND_SVALUE, scommand, GetStateText(state));
|
||||
MqttPublish(stopic);
|
||||
}
|
||||
@ -632,7 +632,7 @@ bool Xdrv12(uint8_t function)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if (Settings.flag.mqtt_enabled) {
|
||||
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||
switch (function) {
|
||||
case FUNC_EVERY_SECOND:
|
||||
if (hass_init_step) {
|
||||
@ -640,7 +640,7 @@ bool Xdrv12(uint8_t function)
|
||||
if (!hass_init_step) {
|
||||
HAssDiscovery(); // Scheduled discovery using available resources
|
||||
}
|
||||
} else if (Settings.flag.hass_discovery && Settings.tele_period) {
|
||||
} else if (Settings.flag.hass_discovery && Settings.tele_period) { // SetOption19 - Control Home Assistantautomatic discovery (See SetOption59)
|
||||
hass_tele_period++;
|
||||
if (hass_tele_period >= Settings.tele_period) {
|
||||
hass_tele_period = 0;
|
||||
|
@ -172,7 +172,7 @@ void PCA9685_OutputTelemetry(bool telemetry) {
|
||||
}
|
||||
ResponseAppend_P(PSTR("\"END\":1}}"));
|
||||
if (telemetry) {
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -404,7 +404,7 @@ void TuyaRequestState(void)
|
||||
|
||||
void TuyaResetWifi(void)
|
||||
{
|
||||
if (!Settings.flag.button_restrict) {
|
||||
if (!Settings.flag.button_restrict) { // SetOption1 - Control button multipress
|
||||
char scmnd[20];
|
||||
snprintf_P(scmnd, sizeof(scmnd), D_CMND_WIFICONFIG " %d", 2);
|
||||
ExecuteCommand(scmnd, SRC_BUTTON);
|
||||
|
@ -62,7 +62,7 @@ void RfReceiveCheck(void)
|
||||
rf_lasttime = now;
|
||||
|
||||
char stemp[16];
|
||||
if (Settings.flag.rf_receive_decimal) { // SetOption28 (0 = hexadecimal, 1 = decimal)
|
||||
if (Settings.flag.rf_receive_decimal) { // SetOption28 - RF receive data format (0 = hexadecimal, 1 = decimal)
|
||||
snprintf_P(stemp, sizeof(stemp), PSTR("%u"), (uint32_t)data);
|
||||
} else {
|
||||
snprintf_P(stemp, sizeof(stemp), PSTR("\"0x%lX\""), (uint32_t)data);
|
||||
|
@ -154,7 +154,7 @@ void PS16DZSerialInput(void)
|
||||
else if (!strncmp(Ps16dz.rx_buffer+3, "SETTING", 7)) {
|
||||
// AT+SETTING=enterESPTOUCH - When ON button is held for over 5 seconds
|
||||
// AT+SETTING=exitESPTOUCH - When ON button is pressed
|
||||
if (!Settings.flag.button_restrict) {
|
||||
if (!Settings.flag.button_restrict) { // SetOption1 - Control button multipress
|
||||
int state = WIFI_MANAGER;
|
||||
if (!strncmp(Ps16dz.rx_buffer+10, "=exit", 5)) { state = WIFI_RETRY; }
|
||||
if (state != Settings.sta_config) {
|
||||
|
@ -217,7 +217,7 @@ void CmndFanspeed(void)
|
||||
bool SonoffIfanInit(void)
|
||||
{
|
||||
if (SONOFF_IFAN03 == my_module_type) {
|
||||
Settings.flag.mqtt_serial = 0;
|
||||
Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG
|
||||
baudrate = 9600;
|
||||
SetSeriallog(LOG_LEVEL_NONE);
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ void ShutterInit(void)
|
||||
// Determine shutter types
|
||||
Shutter.mask |= 3 << (Settings.shutter_startrelay[i] -1) ;
|
||||
|
||||
for (uint32_t j = 0; j < MAX_INTERLOCKS * Settings.flag.interlock; j++) {
|
||||
for (uint32_t j = 0; j < MAX_INTERLOCKS * Settings.flag.interlock; j++) { // CMND_INTERLOCK - Enable/disable interlock
|
||||
//AddLog_P2(LOG_LEVEL_INFO, PSTR("SHT: Interlock state i=%d %d, flag %d, , shuttermask %d, maskedIL %d"),i, Settings.interlock[i], Settings.flag.interlock,Shutter.mask, Settings.interlock[i]&Shutter.mask);
|
||||
if (Settings.interlock[j] && Settings.interlock[j] & Shutter.mask) {
|
||||
//AddLog_P2(LOG_LEVEL_INFO, PSTR("SHT: Relay in Interlock group"));
|
||||
@ -275,7 +275,7 @@ void ShutterUpdatePosition(void)
|
||||
snprintf_P(scommand, sizeof(scommand),PSTR(D_SHUTTER "%d"), i+1);
|
||||
GetTopic_P(stopic, STAT, mqtt_topic, scommand);
|
||||
Response_P("%d", Settings.shutter_invert[i] ? 100 - Settings.shutter_position[i]: Settings.shutter_position[i]);
|
||||
MqttPublish(stopic, Settings.flag.mqtt_power_retain);
|
||||
MqttPublish(stopic, Settings.flag.mqtt_power_retain); // CMND_POWERRETAIN
|
||||
|
||||
switch (Shutter.mode) {
|
||||
case SHT_PULSE_OPEN__PULSE_CLOSE:
|
||||
@ -638,7 +638,7 @@ bool Xdrv27(uint8_t function)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if (Settings.flag3.shutter_mode) {
|
||||
if (Settings.flag3.shutter_mode) { // SetOption80 1
|
||||
switch (function) {
|
||||
case FUNC_PRE_INIT:
|
||||
ShutterInit();
|
||||
|
@ -355,7 +355,7 @@ void ExsPacketProcess(void)
|
||||
bool ExsModuleSelected(void)
|
||||
{
|
||||
Settings.light_correction = 0;
|
||||
Settings.flag.mqtt_serial = 0;
|
||||
Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG
|
||||
Settings.flag3.pwm_multi_channels = 1;
|
||||
SetSeriallog(LOG_LEVEL_NONE);
|
||||
|
||||
|
@ -125,7 +125,7 @@ void ILI9488_InitDriver()
|
||||
#ifdef USE_TOUCH_BUTTONS
|
||||
void ILI9488_MQTT(uint8_t count,const char *cp) {
|
||||
ResponseTime_P(PSTR(",\"RA8876\":{\"%s%d\":\"%d\"}}"), cp,count+1,(buttons[count]->vpower&0x80)>>7);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
}
|
||||
|
||||
void ILI9488_RDW_BUTT(uint32_t count,uint32_t pwr) {
|
||||
|
@ -110,7 +110,7 @@ void RA8876_InitDriver()
|
||||
#ifdef USE_TOUCH_BUTTONS
|
||||
void RA8876_MQTT(uint8_t count,const char *cp) {
|
||||
ResponseTime_P(PSTR(",\"RA8876\":{\"%s%d\":\"%d\"}}"), cp,count+1,(buttons[count]->vpower&0x80)>>7);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
}
|
||||
|
||||
void RA8876_RDW_BUTT(uint32_t count,uint32_t pwr) {
|
||||
|
@ -191,7 +191,9 @@ void Ws2812UpdateHand(int position, uint32_t index)
|
||||
|
||||
position = (position + Settings.light_rotation) % Settings.light_pixels;
|
||||
|
||||
if (Settings.flag.ws_clock_reverse) position = Settings.light_pixels -position;
|
||||
if (Settings.flag.ws_clock_reverse) { // SetOption16 - Switch between clockwise or counter-clockwise
|
||||
position = Settings.light_pixels -position;
|
||||
}
|
||||
WsColor hand_color = { Settings.ws_color[index][WS_RED], Settings.ws_color[index][WS_GREEN], Settings.ws_color[index][WS_BLUE] };
|
||||
|
||||
Ws2812UpdatePixelColor(position, hand_color, 1);
|
||||
@ -387,7 +389,7 @@ char* Ws2812GetColor(uint32_t led, char* scolor)
|
||||
sl_ledcolor[2] = lcolor.B;
|
||||
scolor[0] = '\0';
|
||||
for (uint32_t i = 0; i < Light.subtype; i++) {
|
||||
if (Settings.flag.decimal_text) {
|
||||
if (Settings.flag.decimal_text) { // SetOption17 - Switch between decimal or hexadecimal output (0 = hexadecimal, 1 = decimal)
|
||||
snprintf_P(scolor, 25, PSTR("%s%s%d"), scolor, (i > 0) ? "," : "", sl_ledcolor[i]);
|
||||
} else {
|
||||
snprintf_P(scolor, 25, PSTR("%s%02X"), scolor, sl_ledcolor[i]);
|
||||
|
@ -222,7 +222,7 @@ void SnfL1ModuleSelected(void)
|
||||
{
|
||||
if (SONOFF_L1 == my_module_type) {
|
||||
if ((pin[GPIO_RXD] < 99) && (pin[GPIO_TXD] < 99)) {
|
||||
Settings.flag.mqtt_serial = 0;
|
||||
Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG
|
||||
baudrate = 19200;
|
||||
|
||||
light_type = LT_RGB;
|
||||
|
@ -1812,7 +1812,7 @@ void handleGesture(void) {
|
||||
|
||||
mqtt_data[0] = '\0';
|
||||
if (MqttShowSensor()) {
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
#ifdef USE_RULES
|
||||
RulesTeleperiod(); // Allow rule based HA messages
|
||||
#endif // USE_RULES
|
||||
|
@ -161,7 +161,7 @@ void MCP230xx_ApplySettings(void) {
|
||||
#ifdef USE_MCP230xx_OUTPUT
|
||||
case 5 ... 6:
|
||||
reg_iodir &= ~(1 << idx);
|
||||
if (Settings.flag.save_state) { // Firmware configuration wants us to use the last pin state
|
||||
if (Settings.flag.save_state) { // SetOption0 - Save power state and use after restart - Firmware configuration wants us to use the last pin state
|
||||
reg_portpins |= (Settings.mcp230xx_config[idx+(mcp230xx_port*8)].saved_state << idx);
|
||||
} else {
|
||||
if (Settings.mcp230xx_config[idx+(mcp230xx_port*8)].pullup) {
|
||||
@ -347,7 +347,7 @@ void MCP230xx_SetOutPin(uint8_t pin,uint8_t pinstate) {
|
||||
uint8_t portpins;
|
||||
uint8_t port = 0;
|
||||
uint8_t pinmo = Settings.mcp230xx_config[pin].pinmode;
|
||||
uint8_t interlock = Settings.flag.interlock;
|
||||
uint8_t interlock = Settings.flag.interlock; // CMND_INTERLOCK - Enable/disable interlock
|
||||
int pinadd = (pin % 2)+1-(3*(pin % 2)); //check if pin is odd or even and convert to 1 (if even) or -1 (if odd)
|
||||
char cmnd[7], stt[4];
|
||||
if (pin > 7) { port = 1; }
|
||||
@ -374,7 +374,7 @@ void MCP230xx_SetOutPin(uint8_t pin,uint8_t pinstate) {
|
||||
}
|
||||
}
|
||||
I2cWrite8(USE_MCP230xx_ADDR, MCP230xx_GPIO + port, portpins);
|
||||
if (Settings.flag.save_state) { // Firmware configured to save last known state in settings
|
||||
if (Settings.flag.save_state) { // SetOption0 - Save power state and use after restart - Firmware configured to save last known state in settings
|
||||
Settings.mcp230xx_config[pin].saved_state=portpins>>(pin-(port*8))&1;
|
||||
Settings.mcp230xx_config[pin+pinadd].saved_state=portpins>>(pin+pinadd-(port*8))&1;
|
||||
}
|
||||
@ -737,7 +737,7 @@ void MCP230xx_OutputTelemetry(void) {
|
||||
}
|
||||
}
|
||||
ResponseAppend_P(PSTR("\"END\":1}}"));
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
}
|
||||
}
|
||||
|
||||
@ -752,7 +752,7 @@ void MCP230xx_Interrupt_Counter_Report(void) {
|
||||
}
|
||||
}
|
||||
ResponseAppend_P(PSTR("\"END\":1}}"));
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
mcp230xx_int_sec_counter = 0;
|
||||
}
|
||||
|
||||
@ -767,7 +767,7 @@ void MCP230xx_Interrupt_Retain_Report(void) {
|
||||
}
|
||||
}
|
||||
ResponseAppend_P(PSTR("\"Value\":%u}}"),retainresult);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
|
@ -360,7 +360,7 @@ void HxEvery100mSecond(void)
|
||||
ResponseAppendTime();
|
||||
HxShow(true);
|
||||
ResponseJsonEnd();
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
Hx.weight_changed = false;
|
||||
}
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ uint8_t MGC3130enableAirwheel[] = {0x10, 0x00, 0x00, 0xA2, 0x90, 0x00 , 0x00, 0x
|
||||
void MGC3130_triggerTele(){
|
||||
mqtt_data[0] = '\0';
|
||||
if (MqttShowSensor()) {
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
#ifdef USE_RULES
|
||||
RulesTeleperiod(); // Allow rule based HA messages
|
||||
#endif // USE_RULES
|
||||
|
@ -74,7 +74,7 @@ float MAX31855_GetProbeTemperature(int32_t RawData){
|
||||
|
||||
float result = (RawData * 0.25); // MAX31855 LSB resolution is 0.25°C for probe temperature
|
||||
|
||||
return (Settings.flag.temperature_conversion) ? ConvertTemp(result) : result; // Check if we have to convert to Fahrenheit
|
||||
return ConvertTemp(result); // Check if we have to convert to Fahrenheit
|
||||
}
|
||||
|
||||
/*
|
||||
@ -89,7 +89,7 @@ float MAX31855_GetReferenceTemperature(int32_t RawData){
|
||||
|
||||
float result = (RawData * 0.0625); // MAX31855 LSB resolution is 0.0625°C for reference temperature
|
||||
|
||||
return (Settings.flag.temperature_conversion) ? ConvertTemp(result) : result; // Check if we have to convert to Fahrenheit
|
||||
return ConvertTemp(result); // Check if we have to convert to Fahrenheit
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -500,7 +500,7 @@ void PN532_ScanForTag(void)
|
||||
ResponseTime_P(PSTR(",\"PN532\":{\"UID\":\"%s\"}}"), uids);
|
||||
#endif // USE_PN532_DATA_FUNCTION
|
||||
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
|
||||
#ifdef USE_PN532_CAUSE_EVENTS
|
||||
|
||||
|
@ -254,7 +254,7 @@ void SPS30_Show(bool json) {
|
||||
void CmdClean(void) {
|
||||
sps30_cmd(SPS_CMD_CLEAN);
|
||||
ResponseTime_P(PSTR(",\"SPS30\":{\"CFAN\":\"true\"}}"));
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
}
|
||||
|
||||
bool SPS30_cmd(void) {
|
||||
|
@ -133,7 +133,7 @@ void PAJ7620SelectBank(uint8_t bank)
|
||||
void PAJ7620TriggerTele(){
|
||||
mqtt_data[0] = '\0';
|
||||
if (MqttShowSensor()) {
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
#ifdef USE_RULES
|
||||
RulesTeleperiod(); // Allow rule based HA messages
|
||||
#endif // USE_RULES
|
||||
|
@ -107,7 +107,7 @@ void RDM6300_ScanForTag() {
|
||||
rdm_uid_str[9]=0;
|
||||
|
||||
ResponseTime_P(PSTR(",\"RDM6300\":{\"UID\":\"%s\"}}"), rdm_uid_str);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
/*
|
||||
char command[24];
|
||||
sprintf(command,"event RDM6300=%s",rdm_uid_str);
|
||||
|
@ -548,7 +548,7 @@ void ibeacon_mqtt(const char *mac,const char *rssi) {
|
||||
s_rssi[4]=0;
|
||||
int16_t n_rssi=atoi(s_rssi);
|
||||
ResponseTime_P(PSTR(",\"" D_CMND_IBEACON "_%s\":{\"RSSI\":%d}}"),s_mac,n_rssi);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
}
|
||||
|
||||
|
||||
|
@ -1621,7 +1621,7 @@ void SML_Immediate_MQTT(const char *mp,uint8_t index,uint8_t mindex) {
|
||||
// immediate mqtt
|
||||
dtostrfd(meter_vars[index],dp&0xf,tpowstr);
|
||||
ResponseTime_P(PSTR(",\"%s\":{\"%s\":%s}}"),meter_desc_p[mindex].prefix,jname,tpowstr);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user