diff --git a/compiled_firmware_files/firmware.json b/compiled_firmware_files/firmware.json
index a26f2239..cf4b1614 100644
--- a/compiled_firmware_files/firmware.json
+++ b/compiled_firmware_files/firmware.json
@@ -1,12 +1,12 @@
{
"hw_rev": {
"1": {
- "latest_fw":"2.0.10",
- "link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_1/NRG_itho_wifi_HW1x_FW2.0.10.bin"
+ "latest_fw":"2.1",
+ "link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_1/NRG_itho_wifi_HW1x_FW2.1.bin"
},
"2": {
- "latest_fw":"2.0.10",
- "link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_2/NRG_itho_wifi_HW2x_FW2.0.10.bin"
+ "latest_fw":"2.1",
+ "link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_2/NRG_itho_wifi_HW2x_FW2.1.bin"
}
}
}
\ No newline at end of file
diff --git a/compiled_firmware_files/hardware_rev_1/NRG_itho_wifi_HW1x_FW2.1.bin b/compiled_firmware_files/hardware_rev_1/NRG_itho_wifi_HW1x_FW2.1.bin
new file mode 100644
index 00000000..d12c1995
Binary files /dev/null and b/compiled_firmware_files/hardware_rev_1/NRG_itho_wifi_HW1x_FW2.1.bin differ
diff --git a/compiled_firmware_files/hardware_rev_2/NRG_itho_wifi_HW2x_FW2.1.bin b/compiled_firmware_files/hardware_rev_2/NRG_itho_wifi_HW2x_FW2.1.bin
new file mode 100644
index 00000000..044e8a1f
Binary files /dev/null and b/compiled_firmware_files/hardware_rev_2/NRG_itho_wifi_HW2x_FW2.1.bin differ
diff --git a/software/NRG_itho_wifi/02_HTML.ino b/software/NRG_itho_wifi/02_HTML.ino
index 16d63b7a..4e844143 100644
--- a/software/NRG_itho_wifi/02_HTML.ino
+++ b/software/NRG_itho_wifi/02_HTML.ino
@@ -82,18 +82,19 @@ void handleAPI(AsyncWebServerRequest *request) {
if (strcmp(p->value().c_str(), "format") == 0 ) {
if (SPIFFS.format()) {
strcpy(logBuff, "Filesystem format = success");
+ dontSaveConfig = true;
}
else {
strcpy(logBuff, "Filesystem format = failed");
}
- jsonMessageBox(logBuff, "");
+ jsonLogMessage(logBuff, WEBINTERFACE);
strcpy(logBuff, "");
parseOK = true;
}
if (strcmp(p->value().c_str(), "reboot") == 0 ) {
shouldReboot = true;
- jsonMessageBox("Reboot requested", "");
+ jsonLogMessage(F("Reboot requested"), WEBINTERFACE);
parseOK = true;
}
@@ -103,7 +104,7 @@ void handleAPI(AsyncWebServerRequest *request) {
debugLevel = 0;
sprintf(logBuff, "Debug level = %d", debugLevel);
- jsonMessageBox(logBuff, "");
+ jsonLogMessage(logBuff, WEBINTERFACE);
strcpy(logBuff, "");
parseOK = true;
}
@@ -112,7 +113,7 @@ void handleAPI(AsyncWebServerRequest *request) {
debugLevel = 1;
sprintf(logBuff, "Debug level = %d", debugLevel);
- jsonMessageBox(logBuff, "");
+ jsonLogMessage(logBuff, WEBINTERFACE);
strcpy(logBuff, "");
parseOK = true;
}
@@ -121,7 +122,7 @@ void handleAPI(AsyncWebServerRequest *request) {
debugLevel = 2;
sprintf(logBuff, "Debug level = %d", debugLevel);
- jsonMessageBox(logBuff, "");
+ jsonLogMessage(logBuff, WEBINTERFACE);
strcpy(logBuff, "");
parseOK = true;
}
@@ -130,7 +131,7 @@ void handleAPI(AsyncWebServerRequest *request) {
debugLevel = 3;
sprintf(logBuff, "Debug level = %d", debugLevel);
- jsonMessageBox(logBuff, "");
+ jsonLogMessage(logBuff, WEBINTERFACE);
strcpy(logBuff, "");
parseOK = true;
}
@@ -213,11 +214,29 @@ void handleAPI(AsyncWebServerRequest *request) {
void handleDebug(AsyncWebServerRequest *request) {
AsyncResponseStream *response = request->beginResponseStream("text/html");
- response->print("
");
- response->print("Config version: ");
+ response->print(F("
"));
+ response->print(F("
Config version: "));
response->print(CONFIG_VERSION);
- response->print("
Itho I2C connection status: unknown
");
- response->print("
--- System Log ---
");
+ response->print(F("
Itho I2C connection status: unknown
"));
+ response->print(F("
File system: "));
+#if defined (__HW_VERSION_ONE__)
+ SPIFFS.info(fs_info);
+ response->print(fs_info.usedBytes);
+#elif defined (__HW_VERSION_TWO__)
+ response->print(SPIFFS.usedBytes());
+#endif
+ response->print(F(" bytes used / "));
+#if defined (__HW_VERSION_ONE__)
+ response->print(fs_info.totalBytes);
+#elif defined (__HW_VERSION_TWO__)
+ response->print(SPIFFS.totalBytes());
+#endif
+ response->print(F(" bytes total "));
+ response->print(F("
System Log:
"));
+
+
+
+ response->print(F("
"));
char link[24] = "";
char linkcur[24] = "";
@@ -232,21 +251,23 @@ void handleDebug(AsyncWebServerRequest *request) {
File file = SPIFFS.open(linkcur, FILE_READ);
while (file.available()) {
- //count row
- //of more than x row display fom total - 1
+ if(char(file.peek()) == '\n') response->print("
");
response->print(char(file.read()));
-
}
file.close();
- response->print("
Download current logfile");
+ response->print(F("
RF Log:
"));
+ response->print(F("
"));
+ response->print(F("
"));
+#endif
request->send(response);
diff --git a/software/NRG_itho_wifi/04_JS_UI_HW1.ino b/software/NRG_itho_wifi/04_JS_UI_HW1.ino
index cfd63448..7a1a8d33 100644
--- a/software/NRG_itho_wifi/04_JS_UI_HW1.ino
+++ b/software/NRG_itho_wifi/04_JS_UI_HW1.ino
@@ -131,9 +131,15 @@ function startWebsock(websocketServerLocation){
count += 1;
resetTimer();
$('#message_box').show();
- $('#message_box').append('Message: ' + x.message1 + ' ' + x.message2 + '
');
+ $('#message_box').append('Message: ' + x.message + '
');
removeAfter5secs(count);
}
+ else if (f.rflog) {
+ let x = f.rflog;
+ $('#rflog_outer').removeClass('hidden');
+ $('#rflog').append(x.message + '
');
+ $('#rflog').scrollTop($('#rflog').height());
+ }
else if (f.ota) {
let x = f.ota;
$('#updateprg').html('Firmware update progress: ' + x.percent + '%');
diff --git a/software/NRG_itho_wifi/04_JS_UI_HW2.ino b/software/NRG_itho_wifi/04_JS_UI_HW2.ino
index 737eba54..7e4dccea 100644
--- a/software/NRG_itho_wifi/04_JS_UI_HW2.ino
+++ b/software/NRG_itho_wifi/04_JS_UI_HW2.ino
@@ -131,9 +131,15 @@ function startWebsock(websocketServerLocation){
count += 1;
resetTimer();
$('#message_box').show();
- $('#message_box').append('Message: ' + x.message1 + ' ' + x.message2 + '
');
+ $('#message_box').append('Message: ' + x.message + '
');
removeAfter5secs(count);
}
+ else if (f.rflog) {
+ let x = f.rflog;
+ $('#rflog_outer').removeClass('hidden');
+ $('#rflog').append(x.message + '
');
+ $('#rflog').scrollTop($('#rflog').height());
+ }
else if (f.ota) {
let x = f.ota;
$('#updateprg').html('Firmware update progress: ' + x.percent + '%');
diff --git a/software/NRG_itho_wifi/06_Websock_func.ino b/software/NRG_itho_wifi/06_Websock_func.ino
index 28514284..8b409e72 100644
--- a/software/NRG_itho_wifi/06_Websock_func.ino
+++ b/software/NRG_itho_wifi/06_Websock_func.ino
@@ -36,7 +36,7 @@ void jsonWsSend(const char* rootName) {
JsonObject obj = root.to(); // Fill the object
remotes.get(obj);
}
-#endif
+#endif
size_t len = measureJson(root);
AsyncWebSocketMessageBuffer * buffer = ws.makeBuffer(len); // creates a buffer (len + 1) for you.
if (buffer) {
@@ -45,7 +45,7 @@ void jsonWsSend(const char* rootName) {
}
}
-// Convert & Transfer Arduino elements to JSON elements
+
void jsonWifiscanresult(int id, const char* ssid, int sigval, int sec) {
StaticJsonDocument<512> root;
//JsonObject root = jsonBuffer.createObject();
@@ -61,20 +61,44 @@ void jsonWifiscanresult(int id, const char* ssid, int sigval, int sec) {
ws.textAll(buffer, len);
}
-// Convert & Transfer Arduino elements to JSON elements
-void jsonMessageBox(const char* message1, const char* message2) {
+
+void jsonLogMessage(const __FlashStringHelper * str, logtype type) {
+ if (!str) return;
+ int length = strlen_P((PGM_P)str);
+ if (length == 0) return;
+#if defined (__HW_VERSION_ONE__)
+ if (length < 400) length = 400;
+ char message[400+1] = "";
+ strncat_P(message, (PGM_P)str, length);
+ jsonLogMessage(message, type);
+#else
+ jsonLogMessage((PGM_P)str, type);
+#endif
+}
+
+void jsonLogMessage(const char* message, logtype type) {
StaticJsonDocument<512> root;
- //JsonObject root = jsonBuffer.createObject();
- JsonObject messagebox = root.createNestedObject("messagebox");
- messagebox["message1"] = message1;
- messagebox["message2"] = message2;
+ JsonObject messagebox;
+
+ switch (type) {
+ case RFLOG:
+ messagebox = root.createNestedObject("rflog");
+ break;
+ default:
+ messagebox = root.createNestedObject("messagebox");
+ }
+
+ messagebox["message"] = message;
char buffer[512];
size_t len = serializeJson(root, buffer);
+
ws.textAll(buffer, len);
+
+
}
-// Convert & Transfer Arduino elements to JSON elements
+
void jsonSystemstat() {
StaticJsonDocument<512> root;
//JsonObject root = jsonBuffer.createObject();
@@ -88,7 +112,7 @@ void jsonSystemstat() {
systemstat["itho_high"] = systemConfig.itho_high;
#if defined (__HW_VERSION_TWO__)
systemstat["itho_llm"] = remotes.getllModeTime();
-#endif
+#endif
systemstat["i2cstat"] = i2cstat;
char buffer[512];
@@ -147,10 +171,10 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
JsonObject obj = p.value();
if (systemConfig.set(obj)) {
if (saveSystemConfig()) {
- jsonMessageBox("System settings saved", "successful");
+ jsonLogMessage(F("System settings saved successful"), WEBINTERFACE);
}
else {
- jsonMessageBox("System settings save failed:", "Unable to write config file");
+ jsonLogMessage(F("System settings save failed: Unable to write config file"), WEBINTERFACE);
}
}
}
@@ -161,10 +185,10 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
JsonObject obj = p.value();
if (wifiConfig.set(obj)) {
if (saveWifiConfig()) {
- jsonMessageBox("Wifi settings saved successful,", "reboot the device");
+ jsonLogMessage(F("Wifi settings saved successful, reboot the device"), WEBINTERFACE);
}
else {
- jsonMessageBox("Wifi settings save failed:", "Unable to write config file");
+ jsonLogMessage(F("Wifi settings save failed: Unable to write config file"), WEBINTERFACE);
}
}
}
@@ -219,25 +243,25 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
remotes.updateRemoteName(index, remoteName);
saveRemotes = true;
}
- }
-#endif
+ }
+#endif
else if (msg.startsWith("{\"reboot")) {
shouldReboot = true;
}
else if (msg.startsWith("{\"resetwificonf")) {
if (resetWifiConfig()) {
- jsonMessageBox("Wifi settings restored,", "reboot the device");
+ jsonLogMessage(F("Wifi settings restored, reboot the device"), WEBINTERFACE);
}
else {
- jsonMessageBox("Wifi settings restore failed,", "please try again");
+ jsonLogMessage(F("Wifi settings restore failed, please try again"), WEBINTERFACE);
}
}
else if (msg.startsWith("{\"resetsysconf")) {
if (resetSystemConfig()) {
- jsonMessageBox("System settings restored,", "reboot the device");
+ jsonLogMessage(F("System settings restored, reboot the device"), WEBINTERFACE);
}
else {
- jsonMessageBox("System settings restore failed,", "please try again");
+ jsonLogMessage(F("System settings restore failed, please try again"), WEBINTERFACE);
}
}
else if (msg.startsWith("{\"itho")) {
@@ -264,7 +288,7 @@ void sendScanDataWs()
else if (n) {
sprintf(logBuff, "Wifi scan found %d networks", n);
logInput(logBuff);
- jsonMessageBox(logBuff, "");
+ jsonLogMessage(logBuff, WEBINTERFACE);
strcpy(logBuff, "");
//sort networks
int indices[n];
diff --git a/software/NRG_itho_wifi/08_Config.ino b/software/NRG_itho_wifi/08_Config.ino
index f998b1a2..cd71c6d6 100644
--- a/software/NRG_itho_wifi/08_Config.ino
+++ b/software/NRG_itho_wifi/08_Config.ino
@@ -67,6 +67,7 @@ bool resetWifiConfig() {
return false;
}
if (!SPIFFS.exists("/wifi.json")) {
+ dontSaveConfig = true;
return true;
}
}
@@ -131,6 +132,7 @@ bool resetSystemConfig() {
return false;
}
if (!SPIFFS.exists("/config.json")) {
+ dontSaveConfig = true;
return true;
}
}
diff --git a/software/NRG_itho_wifi/09_init_code.ino b/software/NRG_itho_wifi/09_init_code.ino
index a0a44a48..c5586ba0 100644
--- a/software/NRG_itho_wifi/09_init_code.ino
+++ b/software/NRG_itho_wifi/09_init_code.ino
@@ -88,6 +88,7 @@ void failSafeBoot() {
}
}
+ digitalWrite(WIFILED, HIGH);
}
#endif
@@ -105,7 +106,6 @@ bool initFileSystem() {
ESP.restart();
}
else {
- FSInfo fs_info;
if (!SPIFFS.info(fs_info)) {
//Serial.println("fs_info failed");
return false;
@@ -167,11 +167,20 @@ void setupWiFiAP() {
IPAddress apIP(192, 168, 4, 1);
IPAddress netMsk(255, 255, 255, 0);
- WiFi.persistent(false);
- // disconnect sta, start ap
- WiFi.disconnect(); // this alone is not enough to stop the autoconnecter
+ WiFi.disconnect(true);
+ delay(30);
+ WiFi.mode(WIFI_OFF);
+ WiFi.persistent(false);
+ WiFi.setAutoReconnect(false);
+
+#if defined (__HW_VERSION_ONE__)
+ WiFi.forceSleepWake();
+#elif defined (__HW_VERSION_TWO__)
+ esp_wifi_set_ps(WIFI_PS_NONE);
+#endif
+
+ delay(100);
WiFi.mode(WIFI_AP);
- WiFi.persistent(true);
WiFi.softAPConfig(apIP, apIP, netMsk);
WiFi.softAP(hostName(), WiFiAPPSK);
@@ -183,17 +192,28 @@ void setupWiFiAP() {
dnsServer.start(53, "*", apIP);
wifiModeAP = true;
+
APmodeTimeout = millis();
-
- digitalWrite(WIFILED, LOW);
+
}
bool connectWiFiSTA()
{
wifiModeAP = false;
- //Serial.println("Connecting wifi network");
+
WiFi.disconnect(true);
+ delay(30);
+ WiFi.mode(WIFI_OFF);
+ WiFi.persistent(false);
+ WiFi.setAutoReconnect(false);
+
+#if defined (__HW_VERSION_ONE__)
+ WiFi.forceSleepWake();
+#elif defined (__HW_VERSION_TWO__)
+ esp_wifi_set_ps(WIFI_PS_NONE);
+#endif
+
delay(100);
WiFi.mode(WIFI_STA);
@@ -238,30 +258,32 @@ bool connectWiFiSTA()
int i = 0;
#if defined (__HW_VERSION_ONE__)
- while (wifi_station_get_connect_status() != STATION_GOT_IP && i < 31) {
+ while (wifi_station_get_connect_status() != STATION_GOT_IP && i < 16) {
#elif defined (__HW_VERSION_TWO__)
- while ((WiFi.status() != WL_CONNECTED) && i < 31) {
+ while ((WiFi.status() != WL_CONNECTED) && i < 16) {
#endif
- delay(1000);
- //Serial.print(".");
+ delay(2000);
+ if (digitalRead(WIFILED) == LOW) {
+ digitalWrite(WIFILED, HIGH);
+ }
+ else {
+ digitalWrite(WIFILED, LOW);
+ }
++i;
}
#if defined (__HW_VERSION_ONE__)
- if (wifi_station_get_connect_status() != STATION_GOT_IP && i >= 30) {
+ if (wifi_station_get_connect_status() != STATION_GOT_IP && i >= 15) {
#elif defined (__HW_VERSION_TWO__)
- if ((WiFi.status() != WL_CONNECTED) && i >= 30) {
+ if ((WiFi.status() != WL_CONNECTED) && i >= 15) {
#endif
//delay(1000);
//Serial.println("");
//Serial.println("Couldn't connect to network :( ");
-
+ digitalWrite(WIFILED, HIGH);
return false;
}
-
-
-
digitalWrite(WIFILED, LOW);
return true;
diff --git a/software/NRG_itho_wifi/10_Gen_func.ino b/software/NRG_itho_wifi/10_Gen_func.ino
index f4291d0b..1289b5fe 100644
--- a/software/NRG_itho_wifi/10_Gen_func.ino
+++ b/software/NRG_itho_wifi/10_Gen_func.ino
@@ -142,7 +142,8 @@ void mqttCallback(char* topic, byte* payload, unsigned int length) {
void updateState(uint16_t newState) {
-
+ systemConfig.itho_fallback = newState;
+
if (mqttClient.connected()) {
char buffer[512];
@@ -234,20 +235,20 @@ void printTimestamp(Print* _logOutput) {
timeinfo = localtime(&now);
char timeStringBuff[50]; // 50 chars should be enough
- strftime(timeStringBuff, sizeof(timeStringBuff), "
%F %T ", timeinfo);
+ strftime(timeStringBuff, sizeof(timeStringBuff), "%F %T ", timeinfo);
_logOutput->print(timeStringBuff);
} else
#elif defined (__HW_VERSION_TWO__)
struct tm timeinfo;
if (getLocalTime(&timeinfo, 0)) {
char timeStringBuff[50]; // 50 chars should be enough
- strftime(timeStringBuff, sizeof(timeStringBuff), "
%F %T ", &timeinfo);
+ strftime(timeStringBuff, sizeof(timeStringBuff), "%F %T ", &timeinfo);
_logOutput->print(timeStringBuff);
} else
#endif
{
char c[32];
- sprintf(c, "
%10lu ", millis());
+ sprintf(c, "%10lu ", millis());
_logOutput->print(c);
}
}
@@ -256,7 +257,6 @@ void printNewline(Print* _logOutput) {
_logOutput->print("\n");
}
-
void logInput(const char * inputString) {
filePrint.open();
diff --git a/software/NRG_itho_wifi/CC1101Task.ino b/software/NRG_itho_wifi/CC1101Task.ino
index 16bef9d2..20adf164 100644
--- a/software/NRG_itho_wifi/CC1101Task.ino
+++ b/software/NRG_itho_wifi/CC1101Task.ino
@@ -26,10 +26,6 @@ void RFDebug(bool chk, int * id, IthoCommand cmd) {
strcpy(debugLog, "");
sprintf(debugLog, "RemoteID=%d,%d,%d,%d,%d,%d,%d,%d / Command=", id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7]);
- if (chk) {
- strcpy(debugLogMsg2, "");
- strlcpy(debugLogMsg2, rf.getLastMessage2CMDstr().c_str(), sizeof(debugLogMsg2));
- }
//log command
switch (cmd) {
case IthoUnknown:
@@ -63,6 +59,10 @@ void RFDebug(bool chk, int * id, IthoCommand cmd) {
strcat(debugLog, "leave");
break;
}
+ if (chk) {
+ strcat(debugLog, "
");
+ strncat(debugLog, rf.getLastMessage2CMDstr().c_str(), sizeof(debugLog)-strlen(debugLog)-1);
+ }
debugLogInput = true;
}
@@ -89,7 +89,7 @@ void setllModeTimer() {
void CC1101Task( void * parameter ) {
Ticker TaskTimeout;
-
+
if (strcmp(systemConfig.itho_rf_support, "on") == 0) {
Ticker reboot;
@@ -118,116 +118,117 @@ void CC1101Task( void * parameter ) {
strlcpy(systemConfig.itho_rf_support, "on", sizeof(systemConfig.itho_rf_support));
loadRemotesConfig();
systemConfig.rfInitOK = true;
- }
- for (;;) {
- delay(1);
- yield();
- TaskTimeout.attach_ms(100, []() {
- logInput("Error: CC1101 Task timed out!");
- });
- if (ithoCheck) {
- ithoCheck = false;
- if (rf.checkForNewPacket()) {
-
- int *lastID = rf.getLastID();
- int id[8];
- for (uint8_t i = 0; i < 8; i++) {
- id[i] = lastID[i];
- }
- IthoCommand cmd = rf.getLastCommand();
- if (++RFTcommandpos > 2) RFTcommandpos = 0; // store information in next entry of ringbuffers
- RFTcommand[RFTcommandpos] = cmd;
- RFTRSSI[RFTcommandpos] = rf.ReadRSSI();
- //int *lastID = rf.getLastID();
- bool chk = remotes.checkID(id);
- //bool chk = rf.checkID(RFTid);
- RFTidChk[RFTcommandpos] = chk;
-
- if (debugLevel >= 2) {
- if (chk || debugLevel == 3) {
- RFDebug(true, id, cmd);
- }
- }
- if (cmd != IthoUnknown) { // only act on good cmd
- if (debugLevel == 1) {
- RFDebug(false, id, cmd);
+ for (;;) {
+ delay(1);
+ yield();
+ TaskTimeout.attach_ms(100, []() {
+ logInput("Error: CC1101 Task timed out!");
+ });
+ if (ithoCheck) {
+ ithoCheck = false;
+ if (rf.checkForNewPacket()) {
+
+ int *lastID = rf.getLastID();
+ int id[8];
+ for (uint8_t i = 0; i < 8; i++) {
+ id[i] = lastID[i];
}
- if (cmd == IthoLeave && remotes.remoteLearnLeaveStatus()) {
- //Serial.print("Leave command received. Trying to remove remote... ");
- int result = remotes.removeRemote(id);
- switch (result) {
- case -1: // failed! - remote not registered
- break;
- case -2: // failed! - no remotes registered
- break;
- case 1: // success!
- saveRemotes = true;
- break;
+ IthoCommand cmd = rf.getLastCommand();
+ if (++RFTcommandpos > 2) RFTcommandpos = 0; // store information in next entry of ringbuffers
+ RFTcommand[RFTcommandpos] = cmd;
+ RFTRSSI[RFTcommandpos] = rf.ReadRSSI();
+ //int *lastID = rf.getLastID();
+ bool chk = remotes.checkID(id);
+ //bool chk = rf.checkID(RFTid);
+ RFTidChk[RFTcommandpos] = chk;
+
+ if (debugLevel >= 2) {
+ if (chk || debugLevel == 3) {
+ RFDebug(true, id, cmd);
}
}
- if (cmd == IthoJoin && remotes.remoteLearnLeaveStatus()) {
- int result = remotes.registerNewRemote(id);
- switch (result) {
- case -1: // failed! - remote already registered
- break;
- case -2: //failed! - max number of remotes reached"
- break;
- case 1:
- saveRemotes = true;
- break;
+ if (cmd != IthoUnknown) { // only act on good cmd
+ if (debugLevel == 1) {
+ RFDebug(false, id, cmd);
}
- }
- if (chk) {
- if (cmd == IthoLow) {
- nextIthoVal = systemConfig.itho_low;
- nextIthoTimer = 0;
- updateItho = true;
+ if (cmd == IthoLeave && remotes.remoteLearnLeaveStatus()) {
+ //Serial.print("Leave command received. Trying to remove remote... ");
+ int result = remotes.removeRemote(id);
+ switch (result) {
+ case -1: // failed! - remote not registered
+ break;
+ case -2: // failed! - no remotes registered
+ break;
+ case 1: // success!
+ saveRemotes = true;
+ break;
+ }
}
- if (cmd == IthoMedium) {
- nextIthoVal = systemConfig.itho_medium;
- nextIthoTimer = 0;
- updateItho = true;
+ if (cmd == IthoJoin && remotes.remoteLearnLeaveStatus()) {
+ int result = remotes.registerNewRemote(id);
+ switch (result) {
+ case -1: // failed! - remote already registered
+ break;
+ case -2: //failed! - max number of remotes reached"
+ break;
+ case 1:
+ saveRemotes = true;
+ break;
+ }
}
- if (cmd == IthoHigh || cmd == IthoFull) {
- nextIthoVal = systemConfig.itho_high;
- nextIthoTimer = 0;
- updateItho = true;
- }
- if (cmd == IthoTimer1) {
- nextIthoVal = systemConfig.itho_high;
- nextIthoTimer = systemConfig.itho_timer1;
- updateItho = true;
- }
- if (cmd == IthoTimer2) {
- nextIthoVal = systemConfig.itho_high;
- nextIthoTimer = systemConfig.itho_timer2;
- updateItho = true;
- }
- if (cmd == IthoTimer3) {
- nextIthoVal = systemConfig.itho_high;
- nextIthoTimer = systemConfig.itho_timer3;
- updateItho = true;
- }
- if (cmd == IthoJoin && !remotes.remoteLearnLeaveStatus()) {
+ if (chk) {
+ if (cmd == IthoLow) {
+ nextIthoVal = systemConfig.itho_low;
+ nextIthoTimer = 0;
+ updateItho = true;
+ }
+ if (cmd == IthoMedium) {
+ nextIthoVal = systemConfig.itho_medium;
+ nextIthoTimer = 0;
+ updateItho = true;
+ }
+ if (cmd == IthoHigh || cmd == IthoFull) {
+ nextIthoVal = systemConfig.itho_high;
+ nextIthoTimer = 0;
+ updateItho = true;
+ }
+ if (cmd == IthoTimer1) {
+ nextIthoVal = systemConfig.itho_high;
+ nextIthoTimer = systemConfig.itho_timer1;
+ updateItho = true;
+ }
+ if (cmd == IthoTimer2) {
+ nextIthoVal = systemConfig.itho_high;
+ nextIthoTimer = systemConfig.itho_timer2;
+ updateItho = true;
+ }
+ if (cmd == IthoTimer3) {
+ nextIthoVal = systemConfig.itho_high;
+ nextIthoTimer = systemConfig.itho_timer3;
+ updateItho = true;
+ }
+ if (cmd == IthoJoin && !remotes.remoteLearnLeaveStatus()) {
+ }
+ if (cmd == IthoLeave && !remotes.remoteLearnLeaveStatus()) {
+ ithoQueue.clear_queue();
+ }
+
}
- if (cmd == IthoLeave && !remotes.remoteLearnLeaveStatus()) {
- ithoQueue.clear_queue();
+ else {
+ //Unknown remote
}
-
+ //Serial.print("Number of know remotes: ");
+ //Serial.println(remotes.getRemoteCount());
}
else {
- //Unknown remote
+ //("--- RF CMD reveiced but of unknown type ---");
}
- //Serial.print("Number of know remotes: ");
- //Serial.println(remotes.getRemoteCount());
- }
- else {
- //("--- RF CMD reveiced but of unknown type ---");
}
}
}
- }
+ } //if (strcmp(systemConfig.itho_rf_support, "on") == 0)
+ //else delete task
vTaskDelete( NULL );
}
diff --git a/software/NRG_itho_wifi/IthoCC1101.cpp b/software/NRG_itho_wifi/IthoCC1101.cpp
index 4e550a46..be50c445 100644
--- a/software/NRG_itho_wifi/IthoCC1101.cpp
+++ b/software/NRG_itho_wifi/IthoCC1101.cpp
@@ -1016,7 +1016,7 @@ String IthoCC1101::getLastMessage2str(bool ashex) {
String IthoCC1101::getLastMessage2CMDstr() {
int startPos = 18;
int endPos = startPos + 15;
- String str = "
msg2cmd: len=" + String(inMessage2.length) + " / ";
+ String str = "msg2cmd: len=" + String(inMessage2.length) + " / ";
for (uint8_t i = 0; i < inMessage2.length; i++) {
if (i == startPos) str += String(inMessage2.data[i] & B00001111) + ",";
if (i > (startPos + 1) && i < endPos) {
diff --git a/software/NRG_itho_wifi/IthoQueue.h b/software/NRG_itho_wifi/IthoQueue.h
index 1025cca9..2fc3d3bb 100644
--- a/software/NRG_itho_wifi/IthoQueue.h
+++ b/software/NRG_itho_wifi/IthoQueue.h
@@ -27,7 +27,7 @@ class IthoQueue {
public:
uint16_t ithoSpeed { 0 };
uint16_t ithoOldSpeed { 0 };
- uint16_t fallBackSpeed { 127 };
+ uint16_t fallBackSpeed { 42 };
void update_queue();
bool add2queue(int speedVal, unsigned long validVal, char* nonQ_cmd_clearsQ);
void clear_queue();
diff --git a/software/NRG_itho_wifi/Loop.ino b/software/NRG_itho_wifi/Loop.ino
index ef013a0e..1d1a0a98 100644
--- a/software/NRG_itho_wifi/Loop.ino
+++ b/software/NRG_itho_wifi/Loop.ino
@@ -20,9 +20,7 @@ void loop() {
debugLogInput = false;
LogMessage.once_ms(150, []() {
-
- jsonMessageBox(debugLog, debugLogMsg2);
- //logInput(debugLog);
+ jsonLogMessage(debugLog, RFLOG);
} );
}
@@ -97,6 +95,9 @@ void loop() {
if (shouldReboot) {
logInput("Reboot requested");
+ if (!dontSaveConfig) {
+ saveSystemConfig();
+ }
delay(1000);
ESP.restart();
delay(2000);
@@ -108,13 +109,11 @@ void loop() {
}
if (wifiModeAP) {
- long now = millis();
- if (now - APmodeTimeout > 900000) { //reboot after 15 min in AP mode
+ if (loopstart - APmodeTimeout > 900000) { //reboot after 15 min in AP mode
shouldReboot = true;
}
dnsServer.processNextRequest();
-
if (loopstart - wifiLedUpdate >= 500) {
wifiLedUpdate = loopstart;
if (digitalRead(WIFILED) == LOW) {
diff --git a/software/NRG_itho_wifi/NRG_itho_wifi.ino b/software/NRG_itho_wifi/NRG_itho_wifi.ino
index 7e50c0a6..6bedd565 100644
--- a/software/NRG_itho_wifi/NRG_itho_wifi.ino
+++ b/software/NRG_itho_wifi/NRG_itho_wifi.ino
@@ -1,4 +1,4 @@
-#define FWVERSION "2.0.10"
+#define FWVERSION "2.1"
#define LOGGING_INTERVAL 21600000
#define ENABLE_FAILSAVE_BOOT
@@ -41,6 +41,7 @@
#elif defined (ESP32)
#include
#include
+#include "esp_wifi.h"
#include
#include
#include "SPIFFS.h"
@@ -50,8 +51,7 @@
#include "IthoCC1101.h" // Largly based on and thanks to https://github.com/supersjimmie/IthoEcoFanRFT
#include "IthoPacket.h" // Largly based on and thanks to https://github.com/supersjimmie/IthoEcoFanRFT
#include "IthoRemote.h"
-char debugLog[80];
-char debugLogMsg2[100];
+char debugLog[200];
bool debugLogInput = false;
uint8_t debugLevel = 0;
Ticker LogMessage;
@@ -73,7 +73,9 @@ SpiffsFilePrint filePrint("/logfile", 2, 10000);
Ticker IthoCMD;
Ticker DelayedReq;
Ticker DelayedSave;
-#if defined (__HW_VERSION_TWO__)
+#if defined (__HW_VERSION_ONE__)
+FSInfo fs_info;
+#elif defined (__HW_VERSION_TWO__)
Ticker timerLearnLeaveMode;
IthoCC1101 rf;
IthoPacket packet;
@@ -114,6 +116,7 @@ unsigned long lastLog = 0;
//flags used
bool shouldReboot = false;
+bool dontSaveConfig = false;
bool clearQueue = false;
bool wifiModeAP = false;
bool sysStatReq = false;
@@ -125,6 +128,8 @@ bool rfInitOK = false;
size_t content_len;
+typedef enum { WEBINTERFACE, RFLOG } logtype;
+
#if defined (__HW_VERSION_TWO__)
IthoCommand RFTcommand[3] = {IthoUnknown, IthoUnknown, IthoUnknown};
byte RFTRSSI[3] = {0, 0, 0};
diff --git a/software/NRG_itho_wifi/Setup.ino b/software/NRG_itho_wifi/Setup.ino
index 55bdd87b..70377cbf 100644
--- a/software/NRG_itho_wifi/Setup.ino
+++ b/software/NRG_itho_wifi/Setup.ino
@@ -37,7 +37,8 @@ void setup() {
if (!loadSystemConfig()) {
//Serial.println("System config error :( ");
}
-
+ ithoQueue.set_itho_fallback_speed(systemConfig.itho_fallback);
+
configTime(0, 0, "pool.ntp.org");
#if defined (__HW_VERSION_ONE__)
@@ -50,6 +51,9 @@ void setup() {
if (!wifiModeAP) {
logWifiInfo();
}
+ else {
+ logInput("Setup: AP mode active");
+ }
if (strcmp(systemConfig.mqtt_active, "on") == 0) {
@@ -234,8 +238,7 @@ void setup() {
Update.onProgress(otaWSupdate);
server.on("/reset", HTTP_GET, [](AsyncWebServerRequest * request) {
- jsonMessageBox("Reset requested ",
- "Device will reboot in a few seconds...");
+ jsonLogMessage(F("Reset requested Device will reboot in a few seconds..."), WEBINTERFACE);
delay(200);
shouldReboot = true;
});
@@ -279,7 +282,7 @@ void setup() {
&CC1101TaskHandle); /* Task handle. */
#endif
- ithoQueue.set_itho_fallback_speed(systemConfig.itho_medium);
+
strcat(i2cstat, "sOk");
logInput("Setup: done");
diff --git a/software/NRG_itho_wifi/SystemConfig.cpp b/software/NRG_itho_wifi/SystemConfig.cpp
index ad358a4e..bc30abec 100644
--- a/software/NRG_itho_wifi/SystemConfig.cpp
+++ b/software/NRG_itho_wifi/SystemConfig.cpp
@@ -19,6 +19,7 @@ SystemConfig::SystemConfig() {
strlcpy(mqtt_domoticz_active, "off", sizeof(mqtt_domoticz_active));
mqtt_updated = false;
get_mqtt_settings = false;
+ itho_fallback = 20;
itho_low = 20;
itho_medium = 120;
itho_high = 220;
@@ -95,6 +96,11 @@ bool SystemConfig::set(JsonObjectConst obj) {
updated = true;
mqtt_idx = obj["mqtt_idx"];
}
+ if (!(const char*)obj["itho_fallback"].isNull()) {
+ //itho_updated = true;
+ updated = true;
+ itho_fallback = obj["itho_fallback"];
+ }
if (!(const char*)obj["itho_low"].isNull()) {
//itho_updated = true;
updated = true;
@@ -158,6 +164,7 @@ void SystemConfig::get(JsonObject obj) const {
}
if (complete || get_itho_settings) {
get_itho_settings = false;
+ obj["itho_fallback"] = itho_fallback;
obj["itho_low"] = itho_low;
obj["itho_medium"] = itho_medium;
obj["itho_high"] = itho_high;
diff --git a/software/NRG_itho_wifi/SystemConfig.h b/software/NRG_itho_wifi/SystemConfig.h
index 200f38fc..a34ae170 100644
--- a/software/NRG_itho_wifi/SystemConfig.h
+++ b/software/NRG_itho_wifi/SystemConfig.h
@@ -24,6 +24,7 @@ class SystemConfig {
uint16_t mqtt_idx;
mutable bool mqtt_updated;
mutable bool get_mqtt_settings;
+ uint8_t itho_fallback;
uint8_t itho_low;
uint8_t itho_medium;
uint8_t itho_high;