Merge branch 'arendst/development' into development

# Conflicts:
#	sonoff/xdrv_wemohue.ino
This commit is contained in:
reloxx13 2017-12-17 17:36:10 +01:00
commit 5795045578
4 changed files with 40 additions and 71 deletions

View File

@ -1,6 +1,8 @@
/* 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 to enable with define USE_PZEM004T in user_config.h (#614)
* Add optional support for PZEM004T energy sensor
* 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
* Add (experimental) support for sensor SHT3x

View File

@ -189,7 +189,7 @@ boolean (*xsns_func_ptr[XSNS_MAX])(byte); // External Sensor Function Pointers
char my_hostname[33]; // Composed Wifi hostname
char mqtt_client[33]; // Composed MQTT Clientname
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
String web_log[MAX_LOG_LINES]; // Web log buffer
String backlog[MAX_BACKLOG]; // Command backlog
@ -349,6 +349,7 @@ void MqttSubscribe(char *topic)
void MqttPublishDirect(const char* topic, boolean retained)
{
if (Settings.flag.mqtt_enabled) {
mqtt_data[MESSZ -1] = '\0';
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 ")" : "");
// MqttClient.loop(); // Do not use here! Will block previous publishes
@ -2622,6 +2623,8 @@ void GpioInit()
}
#endif // USE_IR_RECEIVE
#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" {

View File

@ -1337,7 +1337,7 @@ void HandleHttpCommand()
}
}
String message = "";
String message = F("{\"" D_RSLT_WARNING "\":\"");
if (valid) {
byte curridx = web_log_index;
if (strlen(WebServer->arg("cmnd").c_str())) {
@ -1351,18 +1351,15 @@ void HandleHttpCommand()
if (web_log_index != curridx) {
byte counter = curridx;
message = F("{");
do {
if (web_log[counter].length()) {
if (message.length()) {
message += F("\n");
}
if (Settings.flag.mqtt_enabled) {
// [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].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);
// [14:49:36 MQTT: stat/wemos5/RESULT = {"POWER":"OFF"}] > [{"POWER":"OFF"}]
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) {
message += F(",");
}
message += web_log[counter].substring(web_log[counter].indexOf("{")+1,web_log[counter].length()-1);
}
}
counter++;
@ -1370,13 +1367,14 @@ void HandleHttpCommand()
counter = 0;
}
} while (counter != web_log_index);
message += F("}");
} else {
message = F(D_ENABLE_WEBLOG_FOR_RESPONSE "\n");
message += F(D_ENABLE_WEBLOG_FOR_RESPONSE "\"}");
}
} 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()

View File

@ -242,18 +242,18 @@ void PollUdp()
const char WEMO_EVENTSERVICE_XML[] PROGMEM =
"<?scpd xmlns=\"urn:Belkin:service-1-0\"?>"
"<actionList>"
"<action>"
"<name>SetBinaryState</name>"
"<argumentList>"
"<argument>"
"<retval/>"
"<name>BinaryState</name>"
"<relatedStateVariable>BinaryState</relatedStateVariable>"
"<direction>in</direction>"
"</argument>"
"</argumentList>"
"<serviceStateTable>"
"<actionList>"
"<action>"
"<name>SetBinaryState</name>"
"<argumentList>"
"<argument>"
"<retval/>"
"<name>BinaryState</name>"
"<relatedStateVariable>BinaryState</relatedStateVariable>"
"<direction>in</direction>"
"</argument>"
"</argumentList>"
"<serviceStateTable>"
"<stateVariable sendEvents=\"yes\">"
"<name>BinaryState</name>"
"<dataType>Boolean</dataType>"
@ -263,34 +263,14 @@ const char WEMO_EVENTSERVICE_XML[] PROGMEM =
"<name>level</name>"
"<dataType>string</dataType>"
"<defaultValue>0</defaultValue>"
"</stateVariable>"
"</serviceStateTable>"
"</action>"
"<action>"
"<name>GetBinaryState</name>"
"<argumentList>"
"<argument>"
"<retval/>"
"<name>BinaryState</name>"
"<relatedStateVariable>BinaryState</relatedStateVariable>"
"<direction>out</direction>"
"</argument>"
"</argumentList>"
"</stateVariable>"
"</serviceStateTable>"
"</action>"
"</scpd>\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 =
"<?xml version=\"1.0\"?>"
"<root xmlns=\"urn:Belkin:device-1-0\">"
"<root>"
"<device>"
"<deviceType>urn:Belkin:device:controllee:1</deviceType>"
"<friendlyName>{x1</friendlyName>"
@ -319,32 +299,17 @@ void HandleUpnpEvent()
{
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT));
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("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);
state_xml.replace("{x1", "Set");
state_xml.replace("{x2", "1");
}
else if (request.indexOf(F("State>0</Binary")) > 0) {
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT " SET STATE 0"));
if (request.indexOf(F("State>0</Binary")) > 0) {
// ExecuteCommandPower(1, 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()
@ -757,3 +722,4 @@ void HandleHueApi(String *path)
}
#endif // USE_WEBSERVER
#endif // USE_EMULATION