diff --git a/Network.cpp b/Network.cpp index bcee055..fcc9698 100644 --- a/Network.cpp +++ b/Network.cpp @@ -544,6 +544,7 @@ bool Network::openSoftAP() { WiFi.disconnect(true); WiFi.hostname("ESPSomfy RTS"); WiFi.mode(WIFI_AP_STA); + this->_connecting = false; delay(100); WiFi.softAP("ESPSomfy RTS", ""); Serial.println("Initializing AP for credentials modification"); diff --git a/Somfy.cpp b/Somfy.cpp index 6904733..f28aeb4 100644 --- a/Somfy.cpp +++ b/Somfy.cpp @@ -2924,11 +2924,11 @@ void SomfyShade::sendCommand(somfy_commands cmd, uint8_t repeat, uint8_t stepSiz } } void SomfyGroup::sendCommand(somfy_commands cmd) { this->sendCommand(cmd, this->repeats); } -void SomfyGroup::sendCommand(somfy_commands cmd, uint8_t repeat) { +void SomfyGroup::sendCommand(somfy_commands cmd, uint8_t repeat, uint8_t stepSize) { // This sendCommand function will always be called externally. sendCommand at the remote level // is expected to be called internally when the motor needs commanded. if(this->bitLength == 0) this->bitLength = somfy.transceiver.config.type; - SomfyRemote::sendCommand(cmd, repeat); + SomfyRemote::sendCommand(cmd, repeat, stepSize); switch(cmd) { case somfy_commands::My: @@ -3273,6 +3273,8 @@ void SomfyShade::toJSONRef(JsonResponse &json) { json.addElem("remoteAddress", (uint32_t)this->m_remoteAddress); json.addElem("paired", this->paired); json.addElem("shadeType", static_cast(this->shadeType)); + json.addElem("flipCommands", this->flipCommands); + json.addElem("flipPosition", this->flipCommands); json.addElem("bitLength", this->bitLength); json.addElem("proto", static_cast(this->proto)); json.addElem("flags", this->flags); @@ -4368,6 +4370,7 @@ void RECEIVE_ATTR Transceiver::handleReceive() { else if (somfy_rx.cpt_synchro_hw == 12) somfy_rx.bit_length = 80; else if (somfy_rx.cpt_synchro_hw > 17) somfy_rx.bit_length = 80; else somfy_rx.bit_length = 56; + //somfy_rx.bit_length = 80; somfy_rx.status = receiving_data; } else { diff --git a/Somfy.h b/Somfy.h index 26832a1..26d6bb4 100644 --- a/Somfy.h +++ b/Somfy.h @@ -402,7 +402,7 @@ class SomfyGroup : public SomfyRemote { void emitState(const char *evt = "groupState"); void emitState(uint8_t num, const char *evt = "groupState"); void sendCommand(somfy_commands cmd); - void sendCommand(somfy_commands cmd, uint8_t repeat); + void sendCommand(somfy_commands cmd, uint8_t repeat, uint8_t stepSize = 0); int8_t p_direction(int8_t dir); bool publish(const char *topic, uint8_t val, bool retain = false); bool publish(const char *topic, int8_t val, bool retain = false); diff --git a/SomfyController.ino.esp32.bin b/SomfyController.ino.esp32.bin index 23fc1f9..cb7496e 100644 Binary files a/SomfyController.ino.esp32.bin and b/SomfyController.ino.esp32.bin differ diff --git a/Web.cpp b/Web.cpp index b071ed3..aefa88b 100644 --- a/Web.cpp +++ b/Web.cpp @@ -407,6 +407,7 @@ void Web::handleRepeatCommand(WebServer& server) { if (method == HTTP_OPTIONS) { server.send(200, "OK"); return; } uint8_t shadeId = 255; uint8_t groupId = 255; + uint8_t stepSize = 0; int8_t repeat = -1; somfy_commands command = somfy_commands::My; if (method == HTTP_GET || method == HTTP_PUT || method == HTTP_POST) { @@ -414,6 +415,7 @@ void Web::handleRepeatCommand(WebServer& server) { else if(server.hasArg("groupId")) groupId = atoi(server.arg("groupId").c_str()); if(server.hasArg("command")) command = translateSomfyCommand(server.arg("command")); if(server.hasArg("repeat")) repeat = atoi(server.arg("repeat").c_str()); + if(server.hasArg("stepSize")) stepSize = atoi(server.arg("stepSize").c_str()); if(shadeId == 255 && groupId == 255 && server.hasArg("plain")) { DynamicJsonDocument doc(512); DeserializationError err = deserializeJson(doc, server.arg("plain")); @@ -425,6 +427,7 @@ void Web::handleRepeatCommand(WebServer& server) { JsonObject obj = doc.as(); if (obj.containsKey("shadeId")) shadeId = obj["shadeId"]; if(obj.containsKey("groupId")) groupId = obj["groupId"]; + if(obj.containsKey("stepSize")) stepSize = obj["stepSize"]; if (obj.containsKey("command")) { String scmd = obj["command"]; command = translateSomfyCommand(scmd); @@ -443,7 +446,7 @@ void Web::handleRepeatCommand(WebServer& server) { if(shade->shadeType == shade_types::garage1 && command == somfy_commands::Prog) command = somfy_commands::Toggle; if(!shade->isLastCommand(command)) { // We are going to send this as a new command. - shade->sendCommand(command, repeat >= 0 ? repeat : shade->repeats); + shade->sendCommand(command, repeat >= 0 ? repeat : shade->repeats, stepSize); } else { shade->repeatFrame(repeat >= 0 ? repeat : shade->repeats); @@ -463,7 +466,7 @@ void Web::handleRepeatCommand(WebServer& server) { } if(!group->isLastCommand(command)) { // We are going to send this as a new command. - group->sendCommand(command, repeat >= 0 ? repeat : group->repeats); + group->sendCommand(command, repeat >= 0 ? repeat : group->repeats, stepSize); } else group->repeatFrame(repeat >= 0 ? repeat : group->repeats); @@ -488,6 +491,7 @@ void Web::handleGroupCommand(WebServer &server) { if(server.method() == HTTP_OPTIONS) { server.send(200, "OK"); return; } HTTPMethod method = server.method(); uint8_t groupId = 255; + uint8_t stepSize = 0; int8_t repeat = -1; somfy_commands command = somfy_commands::My; if (method == HTTP_GET || method == HTTP_PUT || method == HTTP_POST) { @@ -495,6 +499,7 @@ void Web::handleGroupCommand(WebServer &server) { groupId = atoi(server.arg("groupId").c_str()); if (server.hasArg("command")) command = translateSomfyCommand(server.arg("command")); if(server.hasArg("repeat")) repeat = atoi(server.arg("repeat").c_str()); + if(server.hasArg("stepSize")) stepSize = atoi(server.arg("stepSize").c_str()); } else if (server.hasArg("plain")) { Serial.println("Sending Group Command"); @@ -507,12 +512,16 @@ void Web::handleGroupCommand(WebServer &server) { else { JsonObject obj = doc.as(); if (obj.containsKey("groupId")) groupId = obj["groupId"]; - else server.send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No group id was supplied.\"}")); + else { + server.send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No group id was supplied.\"}")); + return; + } if (obj.containsKey("command")) { String scmd = obj["command"]; command = translateSomfyCommand(scmd); } if(obj.containsKey("repeat")) repeat = obj["repeat"].as(); + if(obj.containsKey("stepSize")) stepSize = obj["stepSize"].as(); } } else server.send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No group object supplied.\"}")); @@ -521,8 +530,7 @@ void Web::handleGroupCommand(WebServer &server) { Serial.print("Received:"); Serial.println(server.arg("plain")); // Send the command to the group. - if(repeat > 0) group->sendCommand(command, repeat); - else group->sendCommand(command); + group->sendCommand(command, repeat >= 0 ? repeat : group->repeats, stepSize); JsonResponse resp; resp.beginResponse(&server, g_content, sizeof(g_content)); resp.beginObject();