diff --git a/README.md b/README.md
index d857adf..4555054 100644
--- a/README.md
+++ b/README.md
@@ -86,4 +86,6 @@ pio pkg exec -p tool-esptoolpy -- esptool.py --port COM9 read_flash 0x3F0000 0x1
-esp-coredump info_corefile --core coredump.bin --core-format=raw --gdb C:\Users\oem\.platformio\packages\toolchain-xtensa-esp32\bin\xtensa-esp32-elf-gdb.exe .pio\build\esp32dev\firmware.elf > coredump_report.txt
\ No newline at end of file
+esp-coredump info_corefile --core coredump.bin --core-format=raw --gdb C:\Users\oem\.platformio\packages\toolchain-xtensa-esp32\bin\xtensa-esp32-elf-gdb.exe .pio\build\esp32dev\firmware.elf > coredump_report.txt
+
+ C:\Users\oem\.platformio\packages\framework-espidf\export.ps1
\ No newline at end of file
diff --git a/data-src/index.html b/data-src/index.html
index 20ef11d..616a1c2 100644
--- a/data-src/index.html
+++ b/data-src/index.html
@@ -246,6 +246,8 @@
Min:
+ Uptime:
+
diff --git a/data-src/index.js b/data-src/index.js
index 89f1aea..7a689c6 100644
--- a/data-src/index.js
+++ b/data-src/index.js
@@ -4385,6 +4385,8 @@ class Firmware {
if (sp) sp.innerHTML = mem.max.fmt('#,##0');
sp = document.getElementById('spanMinMemory');
if (sp) sp.innerHTML = mem.min.fmt('#,##0');
+ sp = document.getElementById('spanUptime');
+ if (sp) sp.innerHTML = mem.uptime / 3600000;
}
diff --git a/src/Network.cpp b/src/Network.cpp
index ad8f2e1..914d4fd 100644
--- a/src/Network.cpp
+++ b/src/Network.cpp
@@ -691,6 +691,7 @@ void Network::emitHeap(uint8_t num) {
json->addElem("free", freeHeap);
json->addElem("min", minHeap);
json->addElem("total", ESP.getHeapSize());
+ json->addElem("uptime", (uint64_t)millis());
json->endObject();
if(num == 255 && bTimeEmit && bValEmit) {
sockEmit.endEmit(num);
diff --git a/src/Sockets.cpp b/src/Sockets.cpp
index 51765aa..f980fa2 100644
--- a/src/Sockets.cpp
+++ b/src/Sockets.cpp
@@ -77,7 +77,7 @@ void SocketEmitter::startup() {
}
void SocketEmitter::begin() {
sockServer.begin();
- sockServer.enableHeartbeat(20000, 10000, 3);
+ sockServer.enableHeartbeat(3000, 2000, 2);
sockServer.onEvent(this->wsEvent);
Serial.println("Socket Server Started...");
//settings.printAvailHeap();
@@ -90,7 +90,7 @@ JsonSockEvent *SocketEmitter::beginEmit(const char *evt) {
this->json.beginEvent(&sockServer, evt, g_response, sizeof(g_response));
return &this->json;
}
-void SocketEmitter::endEmit(uint8_t num) { this->json.endEvent(num); sockServer.loop(); }
+void SocketEmitter::endEmit(uint8_t num) { this->json.endEvent(num); esp_task_wdt_reset(); sockServer.loop(); }
void SocketEmitter::endEmitRoom(uint8_t room) {
if(room < SOCK_MAX_ROOMS) {
room_t *r = &this->rooms[room];
diff --git a/src/Somfy.cpp b/src/Somfy.cpp
index 0b5eff1..946905d 100644
--- a/src/Somfy.cpp
+++ b/src/Somfy.cpp
@@ -1447,9 +1447,9 @@ void SomfyRoom::unpublish() {
}
void SomfyShade::publishState() {
if(mqtt.connected()) {
- this->publish("position", this->transformPosition(this->currentPos), true);
- this->publish("direction", this->direction, true);
- this->publish("target", this->transformPosition(this->target), true);
+ this->publish("position", (uint8_t)50, true);
+ this->publish("direction", (int8_t)0, true);
+ this->publish("target", (uint8_t)50, true);
this->publish("lastRollingCode", this->lastRollingCode);
this->publish("mypos", this->transformPosition(this->myPos), true);
this->publish("myTiltPos", this->transformPosition(this->myTiltPos), true);
@@ -1796,7 +1796,7 @@ bool SomfyGroup::publish(const char *topic, bool val, bool retain) {
float SomfyShade::p_currentPos(float pos) {
float old = this->currentPos;
this->currentPos = pos;
- if(floor(old) != floor(pos)) this->publish("position", this->transformPosition(static_cast(floor(this->currentPos))));
+ if(floor(old) != floor(pos)) this->publish("position", (uint8_t)50);
return old;
}
float SomfyShade::p_currentTiltPos(float pos) {
@@ -2894,6 +2894,17 @@ void SomfyShade::sendCommand(somfy_commands cmd, uint8_t repeat, uint8_t stepSiz
// 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;
+ // If same direction command sent while already moving, stop the state tracking.
+ // The real motor stops on its own when it receives the same direction again.
+ if((cmd == somfy_commands::Up && this->direction == -1) ||
+ (cmd == somfy_commands::Down && this->direction == 1)) {
+ Serial.println("Same command as dir");
+ SomfyRemote::sendCommand(cmd, repeat);
+ this->p_target(this->currentPos);
+ this->p_tiltTarget(this->currentTiltPos);
+ this->setMovement(0);
+ return;
+ }
if(cmd == somfy_commands::Up) {
if(this->tiltType == tilt_types::euromode) {
// In euromode we need to long press for 2 seconds on the
diff --git a/src/Somfy.h b/src/Somfy.h
index 7f99703..3c1aac5 100644
--- a/src/Somfy.h
+++ b/src/Somfy.h
@@ -30,10 +30,10 @@ enum class radio_proto : byte { // Ordinal byte 0-255
};
enum class somfy_commands : byte {
Unknown0 = 0x0,
- My = 0x1,
- Up = 0x2,
- MyUp = 0x3,
- Down = 0x4,
+ My = 0x2,//DOWN
+ Up = 0x1,
+ MyUp = 0x4, //up
+ Down = 0x3,
MyDown = 0x5,
UpDown = 0x6,
MyUpDown = 0x7,
diff --git a/src/SomfyController.ino b/src/SomfyController.ino
index 9fcb56b..1afa189 100644
--- a/src/SomfyController.ino
+++ b/src/SomfyController.ino
@@ -42,7 +42,7 @@ void setup() {
net.setup();
somfy.begin();
//git.checkForUpdate();
- esp_task_wdt_init(7, true); //enable panic so ESP32 restarts
+ esp_task_wdt_init(15, true); //enable panic so ESP32 restarts
esp_task_wdt_add(NULL); //add current thread to WDT watch
}
diff --git a/src/WResp.cpp b/src/WResp.cpp
index e44e3ba..80545a6 100644
--- a/src/WResp.cpp
+++ b/src/WResp.cpp
@@ -46,11 +46,15 @@ void JsonResponse::endResponse() {
server->sendContent("", 0);
}
void JsonResponse::send() {
+ Serial.println("JsonResponse::send start ");
+ unsigned long ts = millis();
+ esp_task_wdt_reset();
if(!this->_headersSent) server->send_P(200, "application/json", this->buff);
else server->sendContent(this->buff);
//Serial.printf("Sent %d bytes %d\n", strlen(this->buff), this->buffSize);
this->buff[0] = 0x00;
this->_headersSent = true;
+ Serial.printf("JsonResponse::send end took %d ms\n", millis() - ts);
}
void JsonResponse::_safecat(const char *val, bool escape) {
size_t len = (escape ? this->calcEscapedLength(val) : strlen(val)) + strlen(this->buff);
@@ -130,8 +134,9 @@ void JsonFormatter::addElem(const char *name, uint32_t nval) { sprintf(this->_nu
void JsonFormatter::addElem(const char *name, int16_t nval) { sprintf(this->_numbuff, "%d", nval); this->_appendNumber(name); }
void JsonFormatter::addElem(const char *name, uint16_t nval) { sprintf(this->_numbuff, "%u", nval); this->_appendNumber(name); }
void JsonFormatter::addElem(const char *name, int64_t lval) { sprintf(this->_numbuff, "%lld", (long long)lval); this->_appendNumber(name); }
-void JsonFormatter::addElem(const char *name, uint64_t lval) { sprintf(this->_numbuff, "%llu", (unsigned long long)lval); this->_appendNumber(name); }
*/
+void JsonFormatter::addElem(const char *name, uint64_t lval) { sprintf(this->_numbuff, "%llu", (unsigned long long)lval); this->_appendNumber(name); }
+
void JsonFormatter::addElem(const char *name, bool bval) { strcpy(this->_numbuff, bval ? "true" : "false"); this->_appendNumber(name); }
void JsonFormatter::_safecat(const char *val, bool escape) {
diff --git a/src/WResp.h b/src/WResp.h
index 4bda5d5..2efa89e 100644
--- a/src/WResp.h
+++ b/src/WResp.h
@@ -1,5 +1,6 @@
#include
#include
+#include
#include "Somfy.h"
#ifndef wresp_h
#define wresp_h
@@ -51,6 +52,7 @@ class JsonFormatter {
void addElem(const char* name, uint32_t lval);
void addElem(const char* name, bool bval);
void addElem(const char *name, const char *val);
+ void addElem(const char* name, uint64_t lval);
};
class JsonResponse : public JsonFormatter {
protected:
diff --git a/src/Web.cpp b/src/Web.cpp
index 832b153..b5c148e 100644
--- a/src/Web.cpp
+++ b/src/Web.cpp
@@ -249,6 +249,7 @@ void Web::handleController(WebServer &server) {
resp.addElem("maxGroupedShades", (uint8_t)SOMFY_MAX_GROUPED_SHADES);
resp.addElem("maxLinkedRemotes", (uint8_t)SOMFY_MAX_LINKED_REMOTES);
resp.addElem("startingAddress", (uint32_t)somfy.startingAddress);
+
resp.beginObject("transceiver");
somfy.transceiver.toJSON(resp);
resp.endObject();
@@ -815,6 +816,7 @@ void Web::handleDiscovery(WebServer &server) {
resp.addElem("free", ESP.getFreeHeap());
resp.addElem("min", ESP.getMinFreeHeap());
resp.addElem("total", ESP.getHeapSize());
+ resp.addElem("uptime", (uint64_t)millis());
resp.endObject();
resp.beginArray("rooms");
somfy.toJSONRooms(resp);