mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-28 13:16:32 +00:00
Merge branch 'arendst/development' into development
# Conflicts: # sonoff/xdrv_wemohue.ino
This commit is contained in:
commit
5795045578
@ -1,6 +1,8 @@
|
|||||||
/* 5.10.0b
|
/* 5.10.0b
|
||||||
* Change Sonoff Pow Energy MQTT data JSON message and consolidate Status 8 into Status 10
|
* Add optional support for PZEM004T energy sensor
|
||||||
* Add optional support for PZEM004T energy sensor to enable with define USE_PZEM004T in user_config.h (#614)
|
* Change Sonoff Pow Enenrgy MQTT data message and consolidate Status 8 into Status 10
|
||||||
|
* Change Wemo SetBinaryState to distinguish from GetBinaryState (#1357)
|
||||||
|
* Change output of HTTP command to valid JSON only (#1363)
|
||||||
*
|
*
|
||||||
* 5.10.0a
|
* 5.10.0a
|
||||||
* Add (experimental) support for sensor SHT3x
|
* Add (experimental) support for sensor SHT3x
|
||||||
|
@ -189,7 +189,7 @@ boolean (*xsns_func_ptr[XSNS_MAX])(byte); // External Sensor Function Pointers
|
|||||||
char my_hostname[33]; // Composed Wifi hostname
|
char my_hostname[33]; // Composed Wifi hostname
|
||||||
char mqtt_client[33]; // Composed MQTT Clientname
|
char mqtt_client[33]; // Composed MQTT Clientname
|
||||||
char serial_in_buffer[INPUT_BUFFER_SIZE + 2]; // Receive buffer
|
char serial_in_buffer[INPUT_BUFFER_SIZE + 2]; // Receive buffer
|
||||||
char mqtt_data[TOPSZ + MESSZ]; // MQTT publish buffer
|
char mqtt_data[MESSZ + TOPSZ]; // MQTT publish buffer (MESSZ) and web page ajax buffer (MESSZ + TOPSZ)
|
||||||
char log_data[TOPSZ + MESSZ]; // Logging
|
char log_data[TOPSZ + MESSZ]; // Logging
|
||||||
String web_log[MAX_LOG_LINES]; // Web log buffer
|
String web_log[MAX_LOG_LINES]; // Web log buffer
|
||||||
String backlog[MAX_BACKLOG]; // Command backlog
|
String backlog[MAX_BACKLOG]; // Command backlog
|
||||||
@ -349,6 +349,7 @@ void MqttSubscribe(char *topic)
|
|||||||
void MqttPublishDirect(const char* topic, boolean retained)
|
void MqttPublishDirect(const char* topic, boolean retained)
|
||||||
{
|
{
|
||||||
if (Settings.flag.mqtt_enabled) {
|
if (Settings.flag.mqtt_enabled) {
|
||||||
|
mqtt_data[MESSZ -1] = '\0';
|
||||||
if (MqttClient.publish(topic, mqtt_data, retained)) {
|
if (MqttClient.publish(topic, mqtt_data, retained)) {
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MQTT "%s = %s%s"), topic, mqtt_data, (retained) ? " (" D_RETAINED ")" : "");
|
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MQTT "%s = %s%s"), topic, mqtt_data, (retained) ? " (" D_RETAINED ")" : "");
|
||||||
// MqttClient.loop(); // Do not use here! Will block previous publishes
|
// MqttClient.loop(); // Do not use here! Will block previous publishes
|
||||||
@ -2622,6 +2623,8 @@ void GpioInit()
|
|||||||
}
|
}
|
||||||
#endif // USE_IR_RECEIVE
|
#endif // USE_IR_RECEIVE
|
||||||
#endif // USE_IR_REMOTE
|
#endif // USE_IR_REMOTE
|
||||||
|
|
||||||
|
// energy_flg = (((pin[GPIO_HLW_SEL] < 99) && (pin[GPIO_HLW_CF1] < 99) && (pin[GPIO_HLW_CF] < 99)) || ((pin[GPIO_PZEM_RX] < 99) && (pin[GPIO_PZEM_TX])));
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -1337,7 +1337,7 @@ void HandleHttpCommand()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String message = "";
|
String message = F("{\"" D_RSLT_WARNING "\":\"");
|
||||||
if (valid) {
|
if (valid) {
|
||||||
byte curridx = web_log_index;
|
byte curridx = web_log_index;
|
||||||
if (strlen(WebServer->arg("cmnd").c_str())) {
|
if (strlen(WebServer->arg("cmnd").c_str())) {
|
||||||
@ -1351,18 +1351,15 @@ void HandleHttpCommand()
|
|||||||
|
|
||||||
if (web_log_index != curridx) {
|
if (web_log_index != curridx) {
|
||||||
byte counter = curridx;
|
byte counter = curridx;
|
||||||
|
message = F("{");
|
||||||
do {
|
do {
|
||||||
if (web_log[counter].length()) {
|
if (web_log[counter].length()) {
|
||||||
if (message.length()) {
|
// [14:49:36 MQTT: stat/wemos5/RESULT = {"POWER":"OFF"}] > [{"POWER":"OFF"}]
|
||||||
message += F("\n");
|
if (web_log[counter].indexOf("{") > 0) { // Is it a JSON message (and not only [15:26:08 MQT: stat/wemos5/POWER = O])
|
||||||
}
|
if (message.length() > 1) {
|
||||||
if (Settings.flag.mqtt_enabled) {
|
message += F(",");
|
||||||
// [14:49:36 MQTT: stat/wemos5/RESULT = {"POWER":"OFF"}] > [RESULT = {"POWER":"OFF"}]
|
}
|
||||||
// message += web_log[counter].substring(17 + strlen(PUB_PREFIX) + strlen(Settings.mqtt_topic));
|
message += web_log[counter].substring(web_log[counter].indexOf("{")+1,web_log[counter].length()-1);
|
||||||
message += web_log[counter].substring(web_log[counter].lastIndexOf("/",web_log[counter].indexOf("="))+1);
|
|
||||||
} else {
|
|
||||||
// [14:49:36 RSLT: RESULT = {"POWER":"OFF"}] > [RESULT = {"POWER":"OFF"}]
|
|
||||||
message += web_log[counter].substring(web_log[counter].indexOf(": ")+2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
counter++;
|
counter++;
|
||||||
@ -1370,13 +1367,14 @@ void HandleHttpCommand()
|
|||||||
counter = 0;
|
counter = 0;
|
||||||
}
|
}
|
||||||
} while (counter != web_log_index);
|
} while (counter != web_log_index);
|
||||||
|
message += F("}");
|
||||||
} else {
|
} else {
|
||||||
message = F(D_ENABLE_WEBLOG_FOR_RESPONSE "\n");
|
message += F(D_ENABLE_WEBLOG_FOR_RESPONSE "\"}");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
message = F(D_NEED_USER_AND_PASSWORD "\n");
|
message += F(D_NEED_USER_AND_PASSWORD "\"}");
|
||||||
}
|
}
|
||||||
WebServer->send(200, FPSTR(HDR_CTYPE_PLAIN), message);
|
WebServer->send(200, FPSTR(HDR_CTYPE_JSON), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleConsole()
|
void HandleConsole()
|
||||||
|
@ -242,18 +242,18 @@ void PollUdp()
|
|||||||
|
|
||||||
const char WEMO_EVENTSERVICE_XML[] PROGMEM =
|
const char WEMO_EVENTSERVICE_XML[] PROGMEM =
|
||||||
"<?scpd xmlns=\"urn:Belkin:service-1-0\"?>"
|
"<?scpd xmlns=\"urn:Belkin:service-1-0\"?>"
|
||||||
"<actionList>"
|
"<actionList>"
|
||||||
"<action>"
|
"<action>"
|
||||||
"<name>SetBinaryState</name>"
|
"<name>SetBinaryState</name>"
|
||||||
"<argumentList>"
|
"<argumentList>"
|
||||||
"<argument>"
|
"<argument>"
|
||||||
"<retval/>"
|
"<retval/>"
|
||||||
"<name>BinaryState</name>"
|
"<name>BinaryState</name>"
|
||||||
"<relatedStateVariable>BinaryState</relatedStateVariable>"
|
"<relatedStateVariable>BinaryState</relatedStateVariable>"
|
||||||
"<direction>in</direction>"
|
"<direction>in</direction>"
|
||||||
"</argument>"
|
"</argument>"
|
||||||
"</argumentList>"
|
"</argumentList>"
|
||||||
"<serviceStateTable>"
|
"<serviceStateTable>"
|
||||||
"<stateVariable sendEvents=\"yes\">"
|
"<stateVariable sendEvents=\"yes\">"
|
||||||
"<name>BinaryState</name>"
|
"<name>BinaryState</name>"
|
||||||
"<dataType>Boolean</dataType>"
|
"<dataType>Boolean</dataType>"
|
||||||
@ -263,34 +263,14 @@ const char WEMO_EVENTSERVICE_XML[] PROGMEM =
|
|||||||
"<name>level</name>"
|
"<name>level</name>"
|
||||||
"<dataType>string</dataType>"
|
"<dataType>string</dataType>"
|
||||||
"<defaultValue>0</defaultValue>"
|
"<defaultValue>0</defaultValue>"
|
||||||
"</stateVariable>"
|
"</stateVariable>"
|
||||||
"</serviceStateTable>"
|
"</serviceStateTable>"
|
||||||
"</action>"
|
|
||||||
"<action>"
|
|
||||||
"<name>GetBinaryState</name>"
|
|
||||||
"<argumentList>"
|
|
||||||
"<argument>"
|
|
||||||
"<retval/>"
|
|
||||||
"<name>BinaryState</name>"
|
|
||||||
"<relatedStateVariable>BinaryState</relatedStateVariable>"
|
|
||||||
"<direction>out</direction>"
|
|
||||||
"</argument>"
|
|
||||||
"</argumentList>"
|
|
||||||
"</action>"
|
"</action>"
|
||||||
"</scpd>\r\n"
|
"</scpd>\r\n"
|
||||||
"\r\n";
|
"\r\n";
|
||||||
const char WEMO_RESPONSE_STATE_XML[] PROGMEM =
|
|
||||||
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
|
|
||||||
"<s:Body>"
|
|
||||||
"<u:{x1BinaryStateResponse xmlns:u=\"urn:Belkin:service:basicevent:1\">"
|
|
||||||
"<BinaryState>{x2</BinaryState>"
|
|
||||||
"</u:{x1BinaryStateResponse>"
|
|
||||||
"</s:Body>"
|
|
||||||
"</s:Envelope>\r\n"
|
|
||||||
"\r\n";
|
|
||||||
const char WEMO_SETUP_XML[] PROGMEM =
|
const char WEMO_SETUP_XML[] PROGMEM =
|
||||||
"<?xml version=\"1.0\"?>"
|
"<?xml version=\"1.0\"?>"
|
||||||
"<root xmlns=\"urn:Belkin:device-1-0\">"
|
"<root>"
|
||||||
"<device>"
|
"<device>"
|
||||||
"<deviceType>urn:Belkin:device:controllee:1</deviceType>"
|
"<deviceType>urn:Belkin:device:controllee:1</deviceType>"
|
||||||
"<friendlyName>{x1</friendlyName>"
|
"<friendlyName>{x1</friendlyName>"
|
||||||
@ -319,32 +299,17 @@ void HandleUpnpEvent()
|
|||||||
{
|
{
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT));
|
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT));
|
||||||
String request = WebServer->arg(0);
|
String request = WebServer->arg(0);
|
||||||
String state_xml = FPSTR(WEMO_RESPONSE_STATE_XML);
|
|
||||||
//differentiate get and set state
|
|
||||||
if (request.indexOf(F("SetBinaryState")) > 0) {
|
if (request.indexOf(F("SetBinaryState")) > 0) {
|
||||||
if (request.indexOf(F("State>1</Binary")) > 0) {
|
if (request.indexOf(F("State>1</Binary")) > 0) {
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT " SET STATE 1"));
|
// ExecuteCommandPower(1, 1);
|
||||||
ExecuteCommandPower(devices_present, 1);
|
ExecuteCommandPower(devices_present, 1);
|
||||||
state_xml.replace("{x1", "Set");
|
|
||||||
state_xml.replace("{x2", "1");
|
|
||||||
}
|
}
|
||||||
else if (request.indexOf(F("State>0</Binary")) > 0) {
|
if (request.indexOf(F("State>0</Binary")) > 0) {
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT " SET STATE 0"));
|
// ExecuteCommandPower(1, 0);
|
||||||
ExecuteCommandPower(devices_present, 0);
|
ExecuteCommandPower(devices_present, 0);
|
||||||
|
|
||||||
state_xml.replace("{x1", "Set");
|
|
||||||
state_xml.replace("{x2", "0");
|
|
||||||
}
|
}
|
||||||
WebServer->send(200, FPSTR(HDR_CTYPE_XML), state_xml.c_str());
|
|
||||||
}
|
|
||||||
else if(request.indexOf(F("GetBinaryState")) > 0){
|
|
||||||
char svalue[80];
|
|
||||||
snprintf_P(svalue, sizeof(svalue), PSTR("%d"), bitRead(power, 1 -1));
|
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT " GET STATE"));
|
|
||||||
state_xml.replace("{x1", "Get");
|
|
||||||
state_xml.replace("{x2", svalue);
|
|
||||||
WebServer->send(200, FPSTR(HDR_CTYPE_XML), state_xml.c_str());
|
|
||||||
}
|
}
|
||||||
|
WebServer->send(200, FPSTR(HDR_CTYPE_PLAIN), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleUpnpService()
|
void HandleUpnpService()
|
||||||
@ -757,3 +722,4 @@ void HandleHueApi(String *path)
|
|||||||
}
|
}
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
#endif // USE_EMULATION
|
#endif // USE_EMULATION
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user