Sync to Tasmota

Sync to Tasmota
This commit is contained in:
Adrian Scillato 2018-05-28 20:07:33 -03:00 committed by GitHub
commit da2775c1f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 399 additions and 194 deletions

View File

@ -1,6 +1,9 @@
/* 5.14.0b
* Add two rule sets of 511 characters using commands rule1, rule2 and rule3
* Add rule support for IrReceive and RfReceive (#2758)
* Add command WebSend [<host>(:<port>,<user>:<password>)] <command> (#2821)
* Add source information to command execution to be shown with logging option 3 (#2843)
* Fix some Pow R2 and S31 checksum errors (#1907)
*
* 5.14.0a
* Add feature information to Status 4

View File

@ -42,6 +42,7 @@
#define D_JSON_BUILDDATETIME "BuildDateTime"
#define D_JSON_CO2 "CarbonDioxide"
#define D_JSON_COMMAND "Command"
#define D_JSON_CONNECT_FAILED "Connect failed"
#define D_JSON_COREVERSION "Core"
#define D_JSON_COUNTER "Counter"
#define D_JSON_CURRENT "Current" // As in Voltage and Current
@ -67,6 +68,7 @@
#define D_JSON_GATEWAY "Gateway"
#define D_JSON_HEAPSIZE "Heap"
#define D_JSON_HIGH "High"
#define D_JSON_HOST_NOT_FOUND "Host not found"
#define D_JSON_HSBCOLOR "HSBColor"
#define D_JSON_HUMIDITY "Humidity"
#define D_JSON_I2CSCAN_DEVICES_FOUND_AT "Device(s) found at"
@ -133,6 +135,7 @@
#define D_JSON_VOLTAGE "Voltage"
#define D_JSON_WIFI "Wifi"
#define D_JSON_WRONG "Wrong"
#define D_JSON_WRONG_PARAMETERS "Wrong parameters"
#define D_JSON_YESTERDAY "Yesterday"
#define D_JSON_ZERO_POINT_CALIBRATION "Zero Point Calibration"
@ -213,14 +216,6 @@
#define D_WCFG_5_WAIT "Wait"
#define D_CMND_FRIENDLYNAME "FriendlyName"
#define D_CMND_SWITCHMODE "SwitchMode"
#define D_CMND_WEBSERVER "Webserver"
#define D_JSON_WEBSERVER_MODE "WebServerMode"
#define D_JSON_ACTIVE_FOR "Active for"
#define D_JSON_ON_DEVICE "on"
#define D_JSON_WITH_IP_ADDRESS "with IP address"
#define D_CMND_WEBPASSWORD "WebPassword"
#define D_CMND_WEBLOG "WebLog"
#define D_CMND_EMULATION "Emulation"
#define D_CMND_TELEPERIOD "TelePeriod"
#define D_CMND_RESTART "Restart"
#define D_JSON_ONE_TO_RESTART "1 to restart"
@ -238,7 +233,7 @@
#define D_CMND_SERIALDELIMITER "SerialDelimiter"
#define D_CMND_BAUDRATE "Baudrate"
// Commands xdrv_00_mqtt.ino
// Commands xdrv_01_mqtt.ino
#define D_CMND_MQTTHOST "MqttHost"
#define D_CMND_MQTTPORT "MqttPort"
#define D_CMND_MQTTRETRY "MqttRetry"
@ -263,37 +258,16 @@
#define D_CMND_SENSORRETAIN "SensorRetain"
#define D_CMND_PUBLISH "Publish"
// Commands xdrv_01_light.ino
#define D_CMND_CHANNEL "Channel"
#define D_CMND_COLOR "Color"
#define D_CMND_COLORTEMPERATURE "CT"
#define D_CMND_DIMMER "Dimmer"
#define D_CMND_HSBCOLOR "HSBColor"
#define D_CMND_LED "Led"
#define D_CMND_LEDTABLE "LedTable"
#define D_CMND_FADE "Fade"
#define D_CMND_PIXELS "Pixels"
#define D_CMND_ROTATION "Rotation"
#define D_CMND_SCHEME "Scheme"
#define D_CMND_SPEED "Speed"
#define D_CMND_WAKEUP "Wakeup"
#define D_CMND_WAKEUPDURATION "WakeUpDuration"
#define D_CMND_WIDTH "Width"
// Commands xdrv_02_irremote.ino
#define D_CMND_IRSEND "IRSend"
#define D_JSON_INVALID_JSON "Invalid JSON"
#define D_JSON_PROTOCOL_NOT_SUPPORTED "Protocol not supported"
#define D_JSON_IR_PROTOCOL "Protocol"
#define D_JSON_IR_BITS "Bits"
#define D_JSON_IR_DATA "Data"
#define D_CMND_IRHVAC "IRHVAC"
#define D_JSON_IRHVAC_VENDOR "VENDOR"
#define D_JSON_IRHVAC_POWER "POWER"
#define D_JSON_IRHVAC_MODE "MODE"
#define D_JSON_IRHVAC_FANSPEED "FANSPEED"
#define D_JSON_IRHVAC_TEMP "TEMP"
#define D_JSON_IRRECEIVED "IrReceived"
// Commands xdrv_02_webserver.ino
#define D_CMND_WEBSERVER "Webserver"
#define D_JSON_WEBSERVER_MODE "WebServerMode"
#define D_JSON_ACTIVE_FOR "Active for"
#define D_JSON_ON_DEVICE "on"
#define D_JSON_WITH_IP_ADDRESS "with IP address"
#define D_CMND_WEBPASSWORD "WebPassword"
#define D_CMND_WEBLOG "WebLog"
#define D_CMND_WEBSEND "WebSend"
#define D_CMND_EMULATION "Emulation"
// Commands xdrv_03_energy.ino
#define D_CMND_POWERLOW "PowerLow"
@ -324,7 +298,39 @@
#define D_JSON_ENERGYMONITOR "EnergyMonitor"
#define D_JSON_MAXENERGYREACHED "MaxEnergyReached"
// Commands xdrv_04_snfbridge.ino
// Commands xdrv_04_light.ino
#define D_CMND_CHANNEL "Channel"
#define D_CMND_COLOR "Color"
#define D_CMND_COLORTEMPERATURE "CT"
#define D_CMND_DIMMER "Dimmer"
#define D_CMND_HSBCOLOR "HSBColor"
#define D_CMND_LED "Led"
#define D_CMND_LEDTABLE "LedTable"
#define D_CMND_FADE "Fade"
#define D_CMND_PIXELS "Pixels"
#define D_CMND_ROTATION "Rotation"
#define D_CMND_SCHEME "Scheme"
#define D_CMND_SPEED "Speed"
#define D_CMND_WAKEUP "Wakeup"
#define D_CMND_WAKEUPDURATION "WakeUpDuration"
#define D_CMND_WIDTH "Width"
// Commands xdrv_05_irremote.ino
#define D_CMND_IRSEND "IRSend"
#define D_JSON_INVALID_JSON "Invalid JSON"
#define D_JSON_PROTOCOL_NOT_SUPPORTED "Protocol not supported"
#define D_JSON_IR_PROTOCOL "Protocol"
#define D_JSON_IR_BITS "Bits"
#define D_JSON_IR_DATA "Data"
#define D_CMND_IRHVAC "IRHVAC"
#define D_JSON_IRHVAC_VENDOR "VENDOR"
#define D_JSON_IRHVAC_POWER "POWER"
#define D_JSON_IRHVAC_MODE "MODE"
#define D_JSON_IRHVAC_FANSPEED "FANSPEED"
#define D_JSON_IRHVAC_TEMP "TEMP"
#define D_JSON_IRRECEIVED "IrReceived"
// Commands xdrv_06_snfbridge.ino
#define D_CMND_RFCODE "RfCode"
#define D_CMND_RFHIGH "RfHigh"
#define D_CMND_RFHOST "RfHost"
@ -340,7 +346,7 @@
#define D_CMND_RFSYNC "RfSync"
#define D_JSON_RFRECEIVED "RfReceived"
// Commands xdrv_05_domoticz.ino
// Commands xdrv_07_domoticz.ino
#define D_CMND_DOMOTICZ "Domoticz"
#define D_CMND_IDX "Idx"
#define D_CMND_KEYIDX "KeyIdx"
@ -348,18 +354,6 @@
#define D_CMND_SENSORIDX "SensorIdx"
#define D_CMND_UPDATETIMER "UpdateTimer"
// Commands xdrv_06_display.ino
#define D_CMND_DISPLAY "Display"
#define D_CMND_DISP_ADDRESS "Address"
#define D_CMND_DISP_COLS "Cols"
#define D_CMND_DISP_DIMMER "Dimmer"
#define D_CMND_DISP_MODE "Mode"
#define D_CMND_DISP_MODEL "Model"
#define D_CMND_DISP_REFRESH "Refresh"
#define D_CMND_DISP_ROWS "Rows"
#define D_CMND_DISP_SIZE "Size"
#define D_CMND_DISP_TEXT "Text"
// Commands xdrv_08_serial_bridge.ino
#define D_CMND_SSERIALSEND "SSerialSend"
#define D_CMND_SBAUDRATE "SBaudrate"
@ -380,6 +374,18 @@
#define D_CMND_LATITUDE "Latitude"
#define D_CMND_LONGITUDE "Longitude"
// Commands xdrv_98_display.ino
#define D_CMND_DISPLAY "Display"
#define D_CMND_DISP_ADDRESS "Address"
#define D_CMND_DISP_COLS "Cols"
#define D_CMND_DISP_DIMMER "Dimmer"
#define D_CMND_DISP_MODE "Mode"
#define D_CMND_DISP_MODEL "Model"
#define D_CMND_DISP_REFRESH "Refresh"
#define D_CMND_DISP_ROWS "Rows"
#define D_CMND_DISP_SIZE "Size"
#define D_CMND_DISP_TEXT "Text"
/********************************************************************************************/
#define D_ASTERIX "********"

View File

@ -192,6 +192,10 @@ enum XsnsFunctions {FUNC_INIT, FUNC_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_SECO
const uint8_t kDefaultRfCode[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48, 0x2E, 0x1A, 0x00 };
enum CommandSource { SRC_IGNORE, SRC_MQTT, SRC_RESTART, SRC_BUTTON, SRC_SWITCH, SRC_BACKLOG, SRC_SERIAL, SRC_WEBGUI, SRC_WEBCOMMAND, SRC_WEBCONSOLE, SRC_PULSETIMER,
SRC_TIMER, SRC_RULE, SRC_MAXPOWER, SRC_MAXENERGY, SRC_LIGHT, SRC_KNX, SRC_DISPLAY, SRC_WEMO, SRC_HUE, SRC_MAX };
const char kCommandSource[] PROGMEM = "I|MQTT|Restart|Button|Switch|Backlog|Serial|WebGui|WebCommand|WebConsole|PulseTimer|Timer|Rule|MaxPower|MaxEnergy|Light|Knx|Display|Wemo|Hue";
/*********************************************************************************************\
* Extern global variables
\*********************************************************************************************/

View File

@ -82,7 +82,7 @@ enum TasmotaCommands {
CMND_GPIO, CMND_GPIOS, CMND_PWM, CMND_PWMFREQUENCY, CMND_PWMRANGE, CMND_COUNTER, CMND_COUNTERTYPE,
CMND_COUNTERDEBOUNCE, CMND_SLEEP, CMND_UPGRADE, CMND_UPLOAD, CMND_OTAURL, CMND_SERIALLOG, CMND_SYSLOG,
CMND_LOGHOST, CMND_LOGPORT, CMND_IPADDRESS, CMND_NTPSERVER, CMND_AP, CMND_SSID, CMND_PASSWORD, CMND_HOSTNAME,
CMND_WIFICONFIG, CMND_FRIENDLYNAME, CMND_SWITCHMODE, CMND_WEBSERVER, CMND_WEBPASSWORD, CMND_WEBLOG, CMND_EMULATION,
CMND_WIFICONFIG, CMND_FRIENDLYNAME, CMND_SWITCHMODE,
CMND_TELEPERIOD, CMND_RESTART, CMND_RESET, CMND_TIMEZONE, CMND_TIMESTD, CMND_TIMEDST, CMND_ALTITUDE, CMND_LEDPOWER, CMND_LEDSTATE,
CMND_I2CSCAN, CMND_SERIALSEND, CMND_BAUDRATE, CMND_SERIALDELIMITER };
const char kTasmotaCommands[] PROGMEM =
@ -92,7 +92,7 @@ const char kTasmotaCommands[] PROGMEM =
D_CMND_GPIO "|" D_CMND_GPIOS "|" D_CMND_PWM "|" D_CMND_PWMFREQUENCY "|" D_CMND_PWMRANGE "|" D_CMND_COUNTER "|" D_CMND_COUNTERTYPE "|"
D_CMND_COUNTERDEBOUNCE "|" D_CMND_SLEEP "|" D_CMND_UPGRADE "|" D_CMND_UPLOAD "|" D_CMND_OTAURL "|" D_CMND_SERIALLOG "|" D_CMND_SYSLOG "|"
D_CMND_LOGHOST "|" D_CMND_LOGPORT "|" D_CMND_IPADDRESS "|" D_CMND_NTPSERVER "|" D_CMND_AP "|" D_CMND_SSID "|" D_CMND_PASSWORD "|" D_CMND_HOSTNAME "|"
D_CMND_WIFICONFIG "|" D_CMND_FRIENDLYNAME "|" D_CMND_SWITCHMODE "|" D_CMND_WEBSERVER "|" D_CMND_WEBPASSWORD "|" D_CMND_WEBLOG "|" D_CMND_EMULATION "|"
D_CMND_WIFICONFIG "|" D_CMND_FRIENDLYNAME "|" D_CMND_SWITCHMODE "|"
D_CMND_TELEPERIOD "|" D_CMND_RESTART "|" D_CMND_RESET "|" D_CMND_TIMEZONE "|" D_CMND_TIMESTD "|" D_CMND_TIMEDST "|" D_CMND_ALTITUDE "|" D_CMND_LEDPOWER "|" D_CMND_LEDSTATE "|"
D_CMND_I2CSCAN "|" D_CMND_SERIALSEND "|" D_CMND_BAUDRATE "|" D_CMND_SERIALDELIMITER;
@ -304,10 +304,12 @@ void SetLatchingRelay(power_t power, uint8_t state)
}
}
void SetDevicePower(power_t rpower)
void SetDevicePower(power_t rpower, int source)
{
uint8_t state;
ShowSource(source);
if (POWER_ALL_ALWAYS_ON == Settings.poweronstate) { // All on and stay on
power = (1 << devices_present) -1;
rpower = power;
@ -396,6 +398,8 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
memcpy(dataBuf, data +i, sizeof(dataBuf));
dataBuf[sizeof(dataBuf)-1] = 0;
if (topicBuf[0] != '/') { ShowSource(SRC_MQTT); }
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_RESULT D_RECEIVED_TOPIC " %s, " D_DATA_SIZE " %d, " D_DATA " %s"),
topicBuf, data_len, dataBuf);
AddLog(LOG_LEVEL_DEBUG_MORE);
@ -490,7 +494,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
else if ((CMND_POWER == command_code) && (index > 0) && (index <= devices_present)) {
if ((payload < 0) || (payload > 4)) payload = 9;
// Settings.flag.device_index_enable = user_append_index;
ExecuteCommandPower(index, payload);
ExecuteCommandPower(index, payload, SRC_IGNORE);
fallback_topic_flag = 0;
return;
}
@ -516,7 +520,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
Settings.poweronstate = payload;
if (POWER_ALL_ALWAYS_ON == Settings.poweronstate) {
for (byte i = 1; i <= devices_present; i++) {
ExecuteCommandPower(i, POWER_ON);
ExecuteCommandPower(i, POWER_ON, SRC_IGNORE);
}
}
}
@ -980,38 +984,6 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
if ((payload >= 0) && (payload < MAX_SWITCH_OPTION)) Settings.switchmode[index -1] = payload;
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_NVALUE, command, index, Settings.switchmode[index-1]);
}
#ifdef USE_WEBSERVER
else if (CMND_WEBSERVER == command_code) {
if ((payload >= 0) && (payload <= 2)) Settings.webserver = payload;
if (Settings.webserver) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WEBSERVER "\":\"" D_JSON_ACTIVE_FOR " %s " D_JSON_ON_DEVICE " %s " D_JSON_WITH_IP_ADDRESS " %s\"}"),
(2 == Settings.webserver) ? D_ADMIN : D_USER, my_hostname, WiFi.localIP().toString().c_str());
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, GetStateText(0));
}
}
else if (CMND_WEBPASSWORD == command_code) {
if ((data_len > 0) && (data_len < sizeof(Settings.web_password))) {
strlcpy(Settings.web_password, (!strcmp(dataBuf,"0")) ? "" : (1 == payload) ? WEB_PASSWORD : dataBuf, sizeof(Settings.web_password));
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, Settings.web_password);
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_ASTERIX, command);
}
}
else if (CMND_WEBLOG == command_code) {
if ((payload >= LOG_LEVEL_NONE) && (payload <= LOG_LEVEL_ALL)) Settings.weblog_level = payload;
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.weblog_level);
}
#ifdef USE_EMULATION
else if (CMND_EMULATION == command_code) {
if ((payload >= EMUL_NONE) && (payload < EMUL_MAX)) {
Settings.flag2.emulation = payload;
restart_flag = 2;
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.flag2.emulation);
}
#endif // USE_EMULATION
#endif // USE_WEBSERVER
else if (CMND_TELEPERIOD == command_code) {
if ((payload >= 0) && (payload < 3601)) {
Settings.tele_period = (1 == payload) ? TELE_PERIOD : payload;
@ -1187,7 +1159,7 @@ boolean SendKey(byte key, byte device, byte state)
return result;
}
void ExecuteCommandPower(byte device, byte state)
void ExecuteCommandPower(byte device, byte state, int source)
{
// device = Relay number 1 and up
// state 0 = Relay Off
@ -1199,6 +1171,8 @@ void ExecuteCommandPower(byte device, byte state)
// state 7 = Relay On and no publishPowerState
// state 9 = Show power state
// ShowSource(source);
uint8_t publish_power = 1;
if ((POWER_OFF_NO_STATE == state) || (POWER_ON_NO_STATE == state)) {
state &= 1;
@ -1216,7 +1190,7 @@ void ExecuteCommandPower(byte device, byte state)
interlock_mutex = 1;
for (byte i = 0; i < devices_present; i++) {
power_t imask = 1 << i;
if ((power & imask) && (mask != imask)) ExecuteCommandPower(i +1, POWER_OFF);
if ((power & imask) && (mask != imask)) ExecuteCommandPower(i +1, POWER_OFF, SRC_IGNORE);
}
interlock_mutex = 0;
}
@ -1230,7 +1204,7 @@ void ExecuteCommandPower(byte device, byte state)
case POWER_TOGGLE:
power ^= mask;
}
SetDevicePower(power);
SetDevicePower(power, source);
#ifdef USE_DOMOTICZ
DomoticzUpdatePowerState(device);
#endif // USE_DOMOTICZ
@ -1257,7 +1231,7 @@ void ExecuteCommandPower(byte device, byte state)
byte flag = (blink_mask & mask);
blink_mask &= (POWER_MASK ^ mask); // Clear device mask
MqttPublishPowerBlinkState(device);
if (flag) ExecuteCommandPower(device, (blink_powersave >> (device -1))&1); // Restore state
if (flag) ExecuteCommandPower(device, (blink_powersave >> (device -1))&1, SRC_IGNORE); // Restore state
return;
}
if (publish_power) MqttPublishPowerState(device);
@ -1272,18 +1246,20 @@ void StopAllPowerBlink()
if (blink_mask & mask) {
blink_mask &= (POWER_MASK ^ mask); // Clear device mask
MqttPublishPowerBlinkState(i);
ExecuteCommandPower(i, (blink_powersave >> (i -1))&1); // Restore state
ExecuteCommandPower(i, (blink_powersave >> (i -1))&1, SRC_IGNORE); // Restore state
}
}
}
void ExecuteCommand(char *cmnd)
void ExecuteCommand(char *cmnd, int source)
{
char stopic[CMDSZ];
char svalue[INPUT_BUFFER_SIZE];
char *start;
char *token;
ShowSource(source);
token = strtok(cmnd, " ");
if (token != NULL) {
start = strrchr(token, '/'); // Skip possible cmnd/sonoff/ preamble
@ -1582,7 +1558,7 @@ void ButtonHandler()
}
if (button_pressed) {
if (!SendKey(0, button_index +1, POWER_TOGGLE)) { // Execute Toggle command via MQTT if ButtonTopic is set
ExecuteCommandPower(button_index +1, POWER_TOGGLE); // Execute Toggle command internally
ExecuteCommandPower(button_index +1, POWER_TOGGLE, SRC_BUTTON); // Execute Toggle command internally
}
}
} else {
@ -1591,7 +1567,7 @@ void ButtonHandler()
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_BUTTON "%d " D_IMMEDIATE), button_index +1);
AddLog(LOG_LEVEL_DEBUG);
if (!SendKey(0, button_index +1, POWER_TOGGLE)) { // Execute Toggle command via MQTT if ButtonTopic is set
ExecuteCommandPower(button_index +1, POWER_TOGGLE); // Execute Toggle command internally
ExecuteCommandPower(button_index +1, POWER_TOGGLE, SRC_BUTTON); // Execute Toggle command internally
}
} else {
multipress[button_index] = (multiwindow[button_index]) ? multipress[button_index] +1 : 1;
@ -1610,7 +1586,7 @@ void ButtonHandler()
if (holdbutton[button_index] == Settings.param[P_HOLD_TIME] * (STATES / 10) * hold_time_extent) { // Button held for factor times longer
// Settings.flag.button_single = 0;
snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_SETOPTION "13 0")); // Disable single press only
ExecuteCommand(scmnd);
ExecuteCommand(scmnd, SRC_BUTTON);
}
} else {
if (Settings.flag.button_restrict) { // Button restriction
@ -1622,7 +1598,7 @@ void ButtonHandler()
if (holdbutton[button_index] == (Settings.param[P_HOLD_TIME] * (STATES / 10)) * hold_time_extent) { // Button held for factor times longer
multipress[button_index] = 0;
snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_RESET " 1"));
ExecuteCommand(scmnd);
ExecuteCommand(scmnd, SRC_BUTTON);
}
}
}
@ -1649,12 +1625,12 @@ void ButtonHandler()
if (WifiState()) { // WPSconfig, Smartconfig or Wifimanager active
restart_flag = 1;
} else {
ExecuteCommandPower(button_index + multipress[button_index], POWER_TOGGLE); // Execute Toggle command internally
ExecuteCommandPower(button_index + multipress[button_index], POWER_TOGGLE, SRC_BUTTON); // Execute Toggle command internally
}
} else { // 3 - 7 press
if (!Settings.flag.button_restrict) {
snprintf_P(scmnd, sizeof(scmnd), kCommands[multipress[button_index] -3]);
ExecuteCommand(scmnd);
ExecuteCommand(scmnd, SRC_BUTTON);
}
}
}
@ -1737,7 +1713,7 @@ void SwitchHandler()
if (switchflag < 3) {
if (!SendKey(1, i +1, switchflag)) { // Execute command via MQTT
ExecuteCommandPower(i +1, switchflag); // Execute command internally (if i < devices_present)
ExecuteCommandPower(i +1, switchflag, SRC_SWITCH); // Execute command internally (if i < devices_present)
}
}
@ -1784,8 +1760,8 @@ void StateLoop()
if ((pulse_timer[i] > 0) && (pulse_timer[i] < 112)) {
pulse_timer[i]--;
if (!pulse_timer[i]) {
// ExecuteCommandPower(i +1, POWER_OFF);
ExecuteCommandPower(i +1, (POWER_ALL_OFF_PULSETIME_ON == Settings.poweronstate) ? POWER_ON : POWER_OFF);
// ExecuteCommandPower(i +1, POWER_OFF, SRC_PULSETIMER);
ExecuteCommandPower(i +1, (POWER_ALL_OFF_PULSETIME_ON == Settings.poweronstate) ? POWER_ON : POWER_OFF, SRC_PULSETIMER);
}
}
}
@ -1800,7 +1776,7 @@ void StateLoop()
} else {
blink_power ^= 1;
power_now = (power & (POWER_MASK ^ blink_mask)) | ((blink_power) ? blink_mask : 0);
SetDevicePower(power_now);
SetDevicePower(power_now, SRC_IGNORE);
}
}
}
@ -1809,7 +1785,7 @@ void StateLoop()
if (backlog_delay) backlog_delay--;
if ((backlog_pointer != backlog_index) && !backlog_delay && !backlog_mutex) {
backlog_mutex = 1;
ExecuteCommand((char*)backlog[backlog_pointer].c_str());
ExecuteCommand((char*)backlog[backlog_pointer].c_str(), SRC_BACKLOG);
backlog_mutex = 0;
backlog_pointer++;
if (backlog_pointer >= MAX_BACKLOG) backlog_pointer = 0;
@ -2154,7 +2130,7 @@ void SerialInput()
seriallog_level = (Settings.seriallog_level < LOG_LEVEL_INFO) ? (byte)LOG_LEVEL_INFO : Settings.seriallog_level;
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_COMMAND "%s"), serial_in_buffer);
AddLog(LOG_LEVEL_INFO);
ExecuteCommand(serial_in_buffer);
ExecuteCommand(serial_in_buffer, SRC_SERIAL);
serial_in_byte_counter = 0;
serial_polling_window = 0;
Serial.flush();
@ -2411,36 +2387,36 @@ void setup()
if (MOTOR == Settings.module) Settings.poweronstate = POWER_ALL_ON; // Needs always on else in limbo!
if (POWER_ALL_ALWAYS_ON == Settings.poweronstate) {
SetDevicePower(1);
SetDevicePower(1, SRC_RESTART);
} else {
if ((resetInfo.reason == REASON_DEFAULT_RST) || (resetInfo.reason == REASON_EXT_SYS_RST)) {
switch (Settings.poweronstate) {
case POWER_ALL_OFF:
case POWER_ALL_OFF_PULSETIME_ON:
power = 0;
SetDevicePower(power);
SetDevicePower(power, SRC_RESTART);
break;
case POWER_ALL_ON: // All on
power = (1 << devices_present) -1;
SetDevicePower(power);
SetDevicePower(power, SRC_RESTART);
break;
case POWER_ALL_SAVED_TOGGLE:
power = (Settings.power & ((1 << devices_present) -1)) ^ POWER_MASK;
if (Settings.flag.save_state) {
SetDevicePower(power);
SetDevicePower(power, SRC_RESTART);
}
break;
case POWER_ALL_SAVED:
power = Settings.power & ((1 << devices_present) -1);
if (Settings.flag.save_state) {
SetDevicePower(power);
SetDevicePower(power, SRC_RESTART);
}
break;
}
} else {
power = Settings.power & ((1 << devices_present) -1);
if (Settings.flag.save_state) {
SetDevicePower(power);
SetDevicePower(power, SRC_RESTART);
}
}
}
@ -2480,13 +2456,6 @@ void loop()
OsWatchLoop();
#ifdef USE_WEBSERVER
PollDnsWebserver();
#ifdef USE_EMULATION
if (Settings.flag2.emulation) PollUdp();
#endif // USE_EMULATION
#endif // USE_WEBSERVER
if (millis() >= state_loop_timer) StateLoop();
if (!serial_local) SerialInput();

View File

@ -606,6 +606,15 @@ uint32_t GetHash(const char *buffer, size_t size)
return hash;
}
void ShowSource(int source)
{
if ((source > 0) && (source < SRC_MAX)) {
char stemp1[20];
snprintf_P(log_data, sizeof(log_data), PSTR("SRC: %s"), GetTextIndexed(stemp1, sizeof(stemp1), source, kCommandSource));
AddLog(LOG_LEVEL_DEBUG);
}
}
/*********************************************************************************************\
* Fill feature list
\*********************************************************************************************/
@ -633,52 +642,52 @@ void GetFeatures()
feature_drv1 |= 0x00000040; // sonoff.ino
#endif
#ifdef USE_WEBSERVER
feature_drv1 |= 0x00000080; // webserver.ino
feature_drv1 |= 0x00000080; // xdrv_02_webserver.ino
#endif
#ifdef WEBSERVER_ADVERTISE
feature_drv1 |= 0x00000100; // webserver.ino
feature_drv1 |= 0x00000100; // xdrv_02_webserver.ino
#endif
#ifdef USE_EMULATION
feature_drv1 |= 0x00000200; // xplg_wemohue.ino
#endif
#if (MQTT_LIBRARY_TYPE == MQTT_PUBSUBCLIENT)
feature_drv1 |= 0x00000400; // xdrv_00_mqtt.ino
feature_drv1 |= 0x00000400; // xdrv_01_mqtt.ino
#endif
#if (MQTT_LIBRARY_TYPE == MQTT_TASMOTAMQTT)
feature_drv1 |= 0x00000800; // xdrv_00_mqtt.ino
feature_drv1 |= 0x00000800; // xdrv_01_mqtt.ino
#endif
#if (MQTT_LIBRARY_TYPE == MQTT_ESPMQTTARDUINO)
feature_drv1 |= 0x00001000; // xdrv_00_mqtt.ino
feature_drv1 |= 0x00001000; // xdrv_01_mqtt.ino
#endif
#ifdef MQTT_HOST_DISCOVERY
feature_drv1 |= 0x00002000; // xdrv_00_mqtt.ino
feature_drv1 |= 0x00002000; // xdrv_01_mqtt.ino
#endif
#ifdef USE_ARILUX_RF
feature_drv1 |= 0x00004000; // xdrv_01_light.ino
feature_drv1 |= 0x00004000; // xdrv_04_light.ino
#endif
#ifdef USE_WS2812
feature_drv1 |= 0x00008000; // xdrv_01_light.ino
feature_drv1 |= 0x00008000; // xdrv_04_light.ino
#endif
#ifdef USE_WS2812_DMA
feature_drv1 |= 0x00010000; // xdrv_01_light.ino
feature_drv1 |= 0x00010000; // xdrv_04_light.ino
#endif
#ifdef USE_IR_REMOTE
feature_drv1 |= 0x00020000; // xdrv_02_irremote.ino
feature_drv1 |= 0x00020000; // xdrv_05_irremote.ino
#endif
#ifdef USE_IR_HVAC
feature_drv1 |= 0x00040000; // xdrv_02_irremote.ino
feature_drv1 |= 0x00040000; // xdrv_05_irremote.ino
#endif
#ifdef USE_IR_RECEIVE
feature_drv1 |= 0x00080000; // xdrv_02_irremote.ino
feature_drv1 |= 0x00080000; // xdrv_05_irremote.ino
#endif
#ifdef USE_DOMOTICZ
feature_drv1 |= 0x00100000; // xdrv_05_domoticz.ino
feature_drv1 |= 0x00100000; // xdrv_07_domoticz.ino
#endif
#ifdef USE_DISPLAY
feature_drv1 |= 0x00200000; // xdrv_06_display.ino
feature_drv1 |= 0x00200000; // xdrv_98_display.ino
#endif
#ifdef USE_HOME_ASSISTANT
feature_drv1 |= 0x00400000; // xdrv_07_home_assistant.ino
feature_drv1 |= 0x00400000; // xdrv_12_home_assistant.ino
#endif
#ifdef USE_SERIAL_BRIDGE
feature_drv1 |= 0x00800000; // xdrv_08_serial_bridge.ino
@ -1141,7 +1150,7 @@ void WifiCheck(uint8_t param)
StartWebserver(Settings.webserver, WiFi.localIP());
#ifdef USE_DISCOVERY
#ifdef WEBSERVER_ADVERTISE
MDNS.addService("http", "tcp", 80);
MDNS.addService("http", "tcp", WEB_PORT);
#endif // WEBSERVER_ADVERTISE
#endif // USE_DISCOVERY
} else {

View File

@ -1,5 +1,5 @@
/*
xdrv_00_mqtt.ino - mqtt support for Sonoff-Tasmota
xdrv_01_mqtt.ino - mqtt support for Sonoff-Tasmota
Copyright (C) 2018 Theo Arends
@ -745,9 +745,9 @@ bool MqttCommand()
* Interface
\*********************************************************************************************/
#define XDRV_00
#define XDRV_01
boolean Xdrv00(byte function)
boolean Xdrv01(byte function)
{
boolean result = false;

View File

@ -1,5 +1,5 @@
/*
webserver.ino - webserver for Sonoff-Tasmota
xdrv_02_webserver.ino - webserver for Sonoff-Tasmota
Copyright (C) 2018 Theo Arends
@ -337,6 +337,21 @@ static void WebGetArg(const char* arg, char* out, size_t max)
out[max-1] = '\0'; // Ensure terminating NUL
}
void ShowWebSource(int source)
{
if ((source > 0) && (source < SRC_MAX)) {
char stemp1[20];
snprintf_P(log_data, sizeof(log_data), PSTR("SRC: %s from %s"), GetTextIndexed(stemp1, sizeof(stemp1), source, kCommandSource), WebServer->client().remoteIP().toString().c_str());
AddLog(LOG_LEVEL_DEBUG);
}
}
void ExecuteWebCommand(char* svalue, int source)
{
ShowWebSource(source);
ExecuteCommand(svalue, SRC_IGNORE);
}
void StartWebserver(int type, IPAddress ipweb)
{
if (!webserver_state) {
@ -567,22 +582,23 @@ void HandleAjaxStatusRefresh()
WebGetArg("o", tmp, sizeof(tmp));
if (strlen(tmp)) {
ExecuteCommandPower(atoi(tmp), POWER_TOGGLE);
ShowWebSource(SRC_WEBGUI);
ExecuteCommandPower(atoi(tmp), POWER_TOGGLE, SRC_IGNORE);
}
WebGetArg("d", tmp, sizeof(tmp));
if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_DIMMER " %s"), tmp);
ExecuteCommand(svalue);
ExecuteWebCommand(svalue, SRC_WEBGUI);
}
WebGetArg("t", tmp, sizeof(tmp));
if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_COLORTEMPERATURE " %s"), tmp);
ExecuteCommand(svalue);
ExecuteWebCommand(svalue, SRC_WEBGUI);
}
WebGetArg("k", tmp, sizeof(tmp));
if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_RFKEY "%s"), tmp);
ExecuteCommand(svalue);
ExecuteWebCommand(svalue, SRC_WEBGUI);
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{t}"));
@ -1106,6 +1122,7 @@ void HandleSaveSettings()
}
ShowPage(page);
ShowWebSource(SRC_WEBGUI);
restart_flag = 2;
} else {
HandleConfiguration();
@ -1129,7 +1146,7 @@ void HandleResetConfiguration()
ShowPage(page);
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_RESET " 1"));
ExecuteCommand(svalue);
ExecuteWebCommand(svalue, SRC_WEBGUI);
}
void HandleRestoreConfiguration()
@ -1181,7 +1198,7 @@ void HandleUpgradeFirmwareStart()
WebGetArg("o", tmp, sizeof(tmp));
if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_OTAURL " %s"), tmp);
ExecuteCommand(svalue);
ExecuteWebCommand(svalue, SRC_WEBGUI);
}
String page = FPSTR(HTTP_HEAD);
@ -1193,7 +1210,7 @@ void HandleUpgradeFirmwareStart()
ShowPage(page);
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_UPGRADE " 1"));
ExecuteCommand(svalue);
ExecuteWebCommand(svalue, SRC_WEBGUI);
}
void HandleUploadDone()
@ -1233,6 +1250,8 @@ void HandleUploadDone()
} else {
page += F("green'>" D_SUCCESSFUL "</font></b><br/>");
page += FPSTR(HTTP_MSG_RSTRT);
ShowWebSource(SRC_WEBGUI);
restart_flag = 2;
}
SettingsBufferFree();
@ -1381,16 +1400,16 @@ void HandleHttpCommand()
WebGetArg("user", tmp1, sizeof(tmp1));
char tmp2[100];
WebGetArg("password", tmp2, sizeof(tmp2));
if (!(!strcmp(tmp1, WEB_USERNAME) && !strcmp(tmp2, Settings.web_password))) {
valid = 0;
}
if (!(!strcmp(tmp1, WEB_USERNAME) && !strcmp(tmp2, Settings.web_password))) { valid = 0; }
}
String message = F("{\"" D_RSLT_WARNING "\":\"");
if (valid) {
byte curridx = web_log_index;
WebGetArg("cmnd", svalue, sizeof(svalue));
if (strlen(svalue)) { ExecuteCommand(svalue); }
if (strlen(svalue)) {
ExecuteWebCommand(svalue, SRC_WEBCOMMAND);
}
if (web_log_index != curridx) {
byte counter = curridx;
@ -1449,7 +1468,7 @@ void HandleAjaxConsoleRefresh()
if (strlen(svalue)) {
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_COMMAND "%s"), svalue);
AddLog(LOG_LEVEL_INFO);
ExecuteCommand(svalue);
ExecuteWebCommand(svalue, SRC_WEBCONSOLE);
}
WebGetArg("c2", svalue, sizeof(svalue));
@ -1624,6 +1643,7 @@ void HandleRestart()
}
ShowPage(page);
ShowWebSource(SRC_WEBGUI);
restart_flag = 2;
}
@ -1676,4 +1696,202 @@ boolean ValidIpAddress(String str)
}
return true;
}
/*********************************************************************************************/
String UrlEncode(const String& text)
{
const char hex[] = "0123456789ABCDEF";
String encoded = "";
int len = text.length();
int i = 0;
while (i < len) {
char decodedChar = text.charAt(i++);
/*
if (('a' <= decodedChar && decodedChar <= 'z') ||
('A' <= decodedChar && decodedChar <= 'Z') ||
('0' <= decodedChar && decodedChar <= '9') ||
('=' == decodedChar)) {
encoded += decodedChar;
} else {
encoded += '%';
encoded += hex[decodedChar >> 4];
encoded += hex[decodedChar & 0xF];
}
*/
if (' ' == decodedChar) {
encoded += '%';
encoded += hex[decodedChar >> 4];
encoded += hex[decodedChar & 0xF];
} else {
encoded += decodedChar;
}
}
return encoded;
}
int WebSend(char *buffer)
{
// http://192.168.178.86:80/cm?user=admin&password=joker&cmnd=POWER1 ON
// http://192.168.178.86:80/cm?cmnd=POWER1 ON
// [192.168.178.86:80,admin:joker] POWER1 ON
char *host;
char *port;
char *user;
char *password;
char *command;
uint16_t nport = 80;
int status = 1; // Wrong parameters
host = strtok_r(buffer, "]", &command); // buffer = [192.168.178.86:80,admin:joker] POWER1 ON
if (host && command) {
host = LTrim(host);
host++; // Skip [
host = strtok_r(host, ",", &user); // host = 192.168.178.86:80,admin:joker > 192.168.178.86:80
host = strtok_r(host, ":", &port); // host = 192.168.178.86:80 > 192.168.178.86
if (user) {
user = strtok_r(user, ":", &password); // user = admin:joker > admin
}
//snprintf_P(log_data, sizeof(log_data), PSTR("DBG: Buffer |%X|, Host |%X|, Port |%X|, User |%X|, Password |%X|, Command |%X|"), buffer, host, port, user, password, command);
//AddLog(LOG_LEVEL_DEBUG);
if (port) { nport = atoi(port); }
String nuri = "";
if (user && password) {
nuri += F("user=");
nuri += user;
nuri += F("&password=");
nuri += password;
nuri += F("&");
}
nuri += F("cmnd=");
nuri += LTrim(command);
String uri = UrlEncode(nuri);
IPAddress host_ip;
if (WiFi.hostByName(host, host_ip)) {
WiFiClient client;
bool connected = false;
byte retry = 2;
while ((retry > 0) && !connected) {
--retry;
connected = client.connect(host_ip, nport);
if (connected) break;
}
if (connected) {
String url = F("GET /cm?");
url += uri;
url += F(" HTTP/1.1\r\n Host: ");
url += IPAddress(host_ip).toString();
if (port) {
url += F(" \r\n Port: ");
url += port;
}
url += F(" \r\n Connection: close\r\n\r\n");
//snprintf_P(log_data, sizeof(log_data), PSTR("DBG: Url |%s|"), url.c_str());
//AddLog(LOG_LEVEL_DEBUG);
client.print(url.c_str());
client.flush();
client.stop();
status = 0; // No error - Done
} else {
status = 2; // Connection failed
}
} else {
status = 3; // Host not found
}
}
return status;
}
/*********************************************************************************************/
enum WebCommands { CMND_WEBSERVER, CMND_WEBPASSWORD, CMND_WEBLOG, CMND_WEBSEND, CMND_EMULATION };
const char kWebCommands[] PROGMEM = D_CMND_WEBSERVER "|" D_CMND_WEBPASSWORD "|" D_CMND_WEBLOG "|" D_CMND_WEBSEND "|" D_CMND_EMULATION ;
const char kWebSendStatus[] PROGMEM = D_JSON_DONE "|" D_JSON_WRONG_PARAMETERS "|" D_JSON_CONNECT_FAILED "|" D_JSON_HOST_NOT_FOUND ;
bool WebCommand()
{
char command[CMDSZ];
bool serviced = true;
int command_code = GetCommandCode(command, sizeof(command), XdrvMailbox.topic, kWebCommands);
if (-1 == command_code) {
serviced = false; // Unknown command
}
if (CMND_WEBSERVER == command_code) {
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 2)) { Settings.webserver = XdrvMailbox.payload; }
if (Settings.webserver) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WEBSERVER "\":\"" D_JSON_ACTIVE_FOR " %s " D_JSON_ON_DEVICE " %s " D_JSON_WITH_IP_ADDRESS " %s\"}"),
(2 == Settings.webserver) ? D_ADMIN : D_USER, my_hostname, WiFi.localIP().toString().c_str());
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, GetStateText(0));
}
}
else if (CMND_WEBPASSWORD == command_code) {
if ((XdrvMailbox.data_len > 0) && (XdrvMailbox.data_len < sizeof(Settings.web_password))) {
strlcpy(Settings.web_password, (!strcmp(XdrvMailbox.data,"0")) ? "" : (1 == XdrvMailbox.payload) ? WEB_PASSWORD : XdrvMailbox.data, sizeof(Settings.web_password));
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, Settings.web_password);
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_ASTERIX, command);
}
}
else if (CMND_WEBLOG == command_code) {
if ((XdrvMailbox.payload >= LOG_LEVEL_NONE) && (XdrvMailbox.payload <= LOG_LEVEL_ALL)) { Settings.weblog_level = XdrvMailbox.payload; }
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.weblog_level);
}
else if (CMND_WEBSEND == command_code) {
if (XdrvMailbox.data_len > 0) {
uint8_t result = WebSend(XdrvMailbox.data);
char stemp1[20];
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, GetTextIndexed(stemp1, sizeof(stemp1), result, kWebSendStatus));
}
}
#ifdef USE_EMULATION
else if (CMND_EMULATION == command_code) {
if ((XdrvMailbox.payload >= EMUL_NONE) && (XdrvMailbox.payload < EMUL_MAX)) {
Settings.flag2.emulation = XdrvMailbox.payload;
restart_flag = 2;
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.flag2.emulation);
}
#endif // USE_EMULATION
else serviced = false; // Unknown command
return serviced;
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
#define XDRV_02
boolean Xdrv02(byte function)
{
boolean result = false;
switch (function) {
case FUNC_LOOP:
PollDnsWebserver();
#ifdef USE_EMULATION
if (Settings.flag2.emulation) PollUdp();
#endif // USE_EMULATION
break;
case FUNC_COMMAND:
result = WebCommand();
break;
}
return result;
}
#endif // USE_WEBSERVER

View File

@ -726,7 +726,7 @@ void EnergyMarginCheck()
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_MAXPOWERREACHED "\":\"%d%s\"}"), energy_power_u, (Settings.flag.value_units) ? " " D_UNIT_WATT : "");
MqttPublishPrefixTopic_P(STAT, S_RSLT_WARNING);
EnergyMqttShow();
ExecuteCommandPower(1, POWER_OFF);
ExecuteCommandPower(1, POWER_OFF, SRC_MAXPOWER);
if (!energy_mplr_counter) {
energy_mplr_counter = Settings.param[P_MAX_POWER_RETRY] +1;
}
@ -748,7 +748,7 @@ void EnergyMarginCheck()
if (energy_mplr_counter) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_POWERMONITOR "\":\"%s\"}"), GetStateText(1));
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_JSON_POWERMONITOR));
ExecuteCommandPower(1, POWER_ON);
ExecuteCommandPower(1, POWER_ON, SRC_MAXPOWER);
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_MAXPOWERREACHEDRETRY "\":\"%s\"}"), GetStateText(0));
MqttPublishPrefixTopic_P(STAT, S_RSLT_WARNING);
@ -766,7 +766,7 @@ void EnergyMarginCheck()
energy_max_energy_state = 1;
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_ENERGYMONITOR "\":\"%s\"}"), GetStateText(1));
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_JSON_ENERGYMONITOR));
ExecuteCommandPower(1, POWER_ON);
ExecuteCommandPower(1, POWER_ON, SRC_MAXENERGY);
}
else if ((1 == energy_max_energy_state) && (energy_daily_u >= Settings.energy_max_energy)) {
energy_max_energy_state = 2;
@ -774,7 +774,7 @@ void EnergyMarginCheck()
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_MAXENERGYREACHED "\":\"%s%s\"}"), mqtt_data, (Settings.flag.value_units) ? " " D_UNIT_KILOWATTHOUR : "");
MqttPublishPrefixTopic_P(STAT, S_RSLT_WARNING);
EnergyMqttShow();
ExecuteCommandPower(1, POWER_OFF);
ExecuteCommandPower(1, POWER_OFF, SRC_MAXENERGY);
}
}
#endif // FEATURE_POWER_LIMIT

View File

@ -1,5 +1,5 @@
/*
xdrv_01_light.ino - PWM, WS2812 and sonoff led support for Sonoff-Tasmota
xdrv_04_light.ino - PWM, WS2812 and sonoff led support for Sonoff-Tasmota
Copyright (C) 2018 Theo Arends
@ -230,7 +230,7 @@ void AriluxRfHandler()
}
}
if (strlen(command)) {
ExecuteCommand(command);
ExecuteCommand(command, SRC_LIGHT);
}
}
}
@ -529,7 +529,7 @@ char* LightGetColor(uint8_t type, char* scolor)
void LightPowerOn()
{
if (Settings.light_dimmer && !(light_power)) {
ExecuteCommandPower(light_device, POWER_ON);
ExecuteCommandPower(light_device, POWER_ON, SRC_LIGHT);
}
}
@ -585,11 +585,11 @@ void LightPreparePower()
{
if (Settings.light_dimmer && !(light_power)) {
if (!Settings.flag.not_power_linked) {
ExecuteCommandPower(light_device, POWER_ON_NO_STATE);
ExecuteCommandPower(light_device, POWER_ON_NO_STATE, SRC_LIGHT);
}
}
else if (!Settings.light_dimmer && light_power) {
ExecuteCommandPower(light_device, POWER_OFF_NO_STATE);
ExecuteCommandPower(light_device, POWER_OFF_NO_STATE, SRC_LIGHT);
}
#ifdef USE_DOMOTICZ
DomoticzUpdatePowerState(light_device);
@ -1279,7 +1279,7 @@ boolean LightCommand()
if (coldim) {
LightPreparePower();
}
return serviced;
}
@ -1287,9 +1287,9 @@ boolean LightCommand()
* Interface
\*********************************************************************************************/
#define XDRV_01
#define XDRV_04
boolean Xdrv01(byte function)
boolean Xdrv04(byte function)
{
boolean result = false;

View File

@ -1,5 +1,5 @@
/*
xdrv_02_irremote.ino - infra red support for Sonoff-Tasmota
xdrv_05_irremote.ino - infra red support for Sonoff-Tasmota
Copyright (C) 2018 Heiko Krupp, Lazar Obradovic and Theo Arends
@ -393,9 +393,9 @@ boolean IrSendCommand()
* Interface
\*********************************************************************************************/
#define XDRV_02
#define XDRV_05
boolean Xdrv02(byte function)
boolean Xdrv05(byte function)
{
boolean result = false;

View File

@ -1,5 +1,5 @@
/*
xdrv_04_snfbridge.ino - sonoff RF bridge 433 support for Sonoff-Tasmota
xdrv_06_snfbridge.ino - sonoff RF bridge 433 support for Sonoff-Tasmota
Copyright (C) 2018 Theo Arends
@ -295,7 +295,7 @@ boolean SonoffBridgeCommand()
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, sonoff_bridge_learn_key, D_JSON_LEARNING_ACTIVE);
}
} else serviced = false; // Unknown command
return serviced;
}
@ -303,9 +303,9 @@ boolean SonoffBridgeCommand()
* Interface
\*********************************************************************************************/
#define XDRV_04
#define XDRV_06
boolean Xdrv04(byte function)
boolean Xdrv06(byte function)
{
boolean result = false;

View File

@ -1,5 +1,5 @@
/*
xdrv_05_domoticz.ino - domoticz support for Sonoff-Tasmota
xdrv_07_domoticz.ino - domoticz support for Sonoff-Tasmota
Copyright (C) 2018 Theo Arends
@ -265,7 +265,7 @@ boolean DomoticzCommand()
else serviced = false; // Unknown command
}
else serviced = false; // Unknown command
return serviced;
}
@ -437,9 +437,9 @@ void DomoticzSaveSettings()
* Interface
\*********************************************************************************************/
#define XDRV_05
#define XDRV_07
boolean Xdrv05(byte function)
boolean Xdrv07(byte function)
{
boolean result = false;

View File

@ -290,7 +290,7 @@ void TimerEverySecond()
XdrvRulesProcess();
} else
#endif // USE_RULES
if (devices_present) { ExecuteCommandPower(xtimer.device +1, xtimer.power); }
if (devices_present) { ExecuteCommandPower(xtimer.device +1, xtimer.power, SRC_TIMER); }
}
}
}

View File

@ -324,7 +324,7 @@ bool RuleSetProcess(byte rule_set, String &event_saved)
// snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, D_CMND_RULE, D_JSON_INITIATED);
// MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_RULE));
ExecuteCommand(command);
ExecuteCommand(command, SRC_RULE);
serviced = true;
}
rules_trigger_count[rule_set]++;

View File

@ -494,12 +494,12 @@ void KNX_CB_Action(message_t const &msg, void *arg)
case KNX_CT_WRITE:
if (chan->type < 9) // Set Relays
{
ExecuteCommandPower(chan->type, msg.data[0]);
ExecuteCommandPower(chan->type, msg.data[0], SRC_KNX);
}
else if (chan->type < 17) // Toggle Relays
{
if (!toggle_inhibit) {
ExecuteCommandPower((chan->type) -8, 2);
ExecuteCommandPower((chan->type) -8, 2, SRC_KNX);
if (Settings.flag.knx_enable_enhancement) {
toggle_inhibit = TOGGLE_INHIBIT_TIME;
}

View File

@ -1,5 +1,5 @@
/*
xdrv_07_home_assistant.ino - home assistant support for Sonoff-Tasmota
xdrv_12_home_assistant.ino - home assistant support for Sonoff-Tasmota
Copyright (C) 2018 Theo Arends
@ -208,9 +208,9 @@ void HAssDiscovery(uint8_t mode)
* Interface
\*********************************************************************************************/
#define XDRV_07
#define XDRV_12
boolean Xdrv07(byte function)
boolean Xdrv12(byte function)
{
boolean result = false;

View File

@ -18,10 +18,6 @@
*/
boolean (* const xdrv_func_ptr[])(byte) PROGMEM = { // Driver Function Pointers
#ifdef XDRV_00
&Xdrv00,
#endif
#ifdef XDRV_01
&Xdrv01,
#endif

View File

@ -387,10 +387,10 @@ void HandleUpnpEvent()
//differentiate get and set state
if (request.indexOf(F("SetBinaryState")) > 0) {
if (request.indexOf(F("State>1</Binary")) > 0) {
ExecuteCommandPower(devices_present, POWER_ON);
ExecuteCommandPower(devices_present, POWER_ON, SRC_WEMO);
}
else if (request.indexOf(F("State>0</Binary")) > 0) {
ExecuteCommandPower(devices_present, POWER_OFF);
ExecuteCommandPower(devices_present, POWER_OFF, SRC_WEMO);
}
}
else if(request.indexOf(F("GetBinaryState")) > 0){
@ -660,10 +660,10 @@ void HueLights(String *path)
on = hue_json["on"];
switch(on)
{
case false : ExecuteCommandPower(device, POWER_OFF);
case false : ExecuteCommandPower(device, POWER_OFF, SRC_HUE);
response.replace("{re", "false");
break;
case true : ExecuteCommandPower(device, POWER_ON);
case true : ExecuteCommandPower(device, POWER_ON, SRC_HUE);
response.replace("{re", "true");
break;
default : response.replace("{re", (power & (1 << (device-1))) ? "true" : "false");

View File

@ -76,8 +76,8 @@ void Sgp30Show(boolean json)
#ifdef USE_DOMOTICZ
if (0 == tele_period) DomoticzSensor(DZ_AIRQUALITY, sgp.eCO2);
#endif // USE_DOMOTICZ
} else {
#ifdef USE_WEBSERVER
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_SGP30, mqtt_data, sgp.eCO2, sgp.TVOC);
#endif
}

View File

@ -335,8 +335,8 @@ void Si1145Show(boolean json)
#ifdef USE_DOMOTICZ
if (0 == tele_period) DomoticzSensor(DZ_ILLUMINANCE, visible);
#endif // USE_DOMOTICZ
} else {
#ifdef USE_WEBSERVER
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_SI1145, mqtt_data, visible, infrared, uvindex /100, uvindex %100);
#endif
}