Skip to content

Commit

Permalink
Version 2.1
Browse files Browse the repository at this point in the history
IMPORTANT FIX: To prevent flash issues, don't store WiFi RF calibration data on flash. In some situations this may lead to flash wear out and stability issues (thanks TD-er!)
FEATURE: itho speed is retained after reboot (not in case of config reset and file system format)
FEATURE: File system usage info on debug page
FEATURE: RF debug logging moved to debug page (will show up at first RF debug message, see manual for debugging details)
FEATURE: Improved handling of logging and memory use (moved const strings to flash)
  • Loading branch information
arjenhiemstra committed Feb 4, 2021
1 parent 2cf8071 commit bd271a4
Show file tree
Hide file tree
Showing 18 changed files with 280 additions and 183 deletions.
8 changes: 4 additions & 4 deletions compiled_firmware_files/firmware.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Binary file not shown.
Binary file not shown.
55 changes: 38 additions & 17 deletions software/NRG_itho_wifi/02_HTML.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -213,11 +214,29 @@ void handleAPI(AsyncWebServerRequest *request) {
void handleDebug(AsyncWebServerRequest *request) {
AsyncResponseStream *response = request->beginResponseStream("text/html");

response->print("<div class=\"header\"><h1>Debug page</h1></div><br><br>");
response->print("<div>Config version: ");
response->print(F("<div class=\"header\"><h1>Debug page</h1></div><br><br>"));
response->print(F("<div>Config version: "));
response->print(CONFIG_VERSION);
response->print("<br><br><span>Itho I2C connection status: </span><span id=\'i2cstat\'>unknown</span><br><br></div>");
response->print("<div style='padding: 10px;background-color: black;background-image: radial-gradient(rgba(0, 150, 0, 0.55), black 140%);height: 60vh;} color: white; font: 0.9rem Inconsolata, monospace;border-radius: 10px;overflow:auto'>--- System Log ---<br>");
response->print(F("<br><br><span>Itho I2C connection status: </span><span id=\'i2cstat\'>unknown</span></div>"));
response->print(F("<span>File system: </span><span>"));
#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</span></div>"));
response->print(F("<br><br><div id='syslog_outer'><div style='display:inline-block;vertical-align:top;overflow:hidden;padding-bottom:5px;'>System Log:</div>"));



response->print(F("<div style='padding:10px;background-color:black;min-height:30vh;max-height:60vh;font: 0.9rem Inconsolata, monospace;border-radius:7px;overflow:auto'>"));
char link[24] = "";
char linkcur[24] = "";

Expand All @@ -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("<br>");
response->print(char(file.read()));

}
file.close();

response->print("</div><br><br><a class='pure-button' href='/curlog'>Download current logfile</a>");
response->print(F("</div><div style='padding-top:5px;'><a class='pure-button' href='/curlog'>Download current logfile</a>"));

if ( SPIFFS.exists(link) ) {
response->print("&nbsp;<a class='pure-button' href='/prevlog'>Download previous logfile</a>");
response->print(F("&nbsp;<a class='pure-button' href='/prevlog'>Download previous logfile</a>"));

}
response->print("<br><br>");


#if defined (__HW_VERSION_TWO__)
response->print(F("</div></div><br><br><div id='rflog_outer' class='hidden'><div style='display:inline-block;vertical-align:top;overflow:hidden;padding-bottom:5px;'>RF Log:</div>"));
response->print(F("<div id='rflog' style='padding:10px;background-color:black;min-height:30vh;max-height:60vh;font: 0.9rem Inconsolata, monospace;border-radius:7px;overflow:auto'>"));
response->print(F("</div><div style='padding-top:5px;'><a href='#' class='pure-button' onclick=\"$('#rflog').empty()\">Clear</a></div></div></div><br><br>"));
#endif

request->send(response);

Expand Down
8 changes: 7 additions & 1 deletion software/NRG_itho_wifi/04_JS_UI_HW1.ino
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,15 @@ function startWebsock(websocketServerLocation){
count += 1;
resetTimer();
$('#message_box').show();
$('#message_box').append('<p class=\'messageP\' id=\'mbox_p' + count + '\'>Message: ' + x.message1 + ' ' + x.message2 + '</p>');
$('#message_box').append('<p class=\'messageP\' id=\'mbox_p' + count + '\'>Message: ' + x.message + '</p>');
removeAfter5secs(count);
}
else if (f.rflog) {
let x = f.rflog;
$('#rflog_outer').removeClass('hidden');
$('#rflog').append(x.message + '<br>');
$('#rflog').scrollTop($('#rflog').height());
}
else if (f.ota) {
let x = f.ota;
$('#updateprg').html('Firmware update progress: ' + x.percent + '%');
Expand Down
8 changes: 7 additions & 1 deletion software/NRG_itho_wifi/04_JS_UI_HW2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,15 @@ function startWebsock(websocketServerLocation){
count += 1;
resetTimer();
$('#message_box').show();
$('#message_box').append('<p class=\'messageP\' id=\'mbox_p' + count + '\'>Message: ' + x.message1 + ' ' + x.message2 + '</p>');
$('#message_box').append('<p class=\'messageP\' id=\'mbox_p' + count + '\'>Message: ' + x.message + '</p>');
removeAfter5secs(count);
}
else if (f.rflog) {
let x = f.rflog;
$('#rflog_outer').removeClass('hidden');
$('#rflog').append(x.message + '<br>');
$('#rflog').scrollTop($('#rflog').height());
}
else if (f.ota) {
let x = f.ota;
$('#updateprg').html('Firmware update progress: ' + x.percent + '%');
Expand Down
66 changes: 45 additions & 21 deletions software/NRG_itho_wifi/06_Websock_func.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void jsonWsSend(const char* rootName) {
JsonObject obj = root.to<JsonObject>(); // 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) {
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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];
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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")) {
Expand All @@ -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];
Expand Down
2 changes: 2 additions & 0 deletions software/NRG_itho_wifi/08_Config.ino
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ bool resetWifiConfig() {
return false;
}
if (!SPIFFS.exists("/wifi.json")) {
dontSaveConfig = true;
return true;
}
}
Expand Down Expand Up @@ -131,6 +132,7 @@ bool resetSystemConfig() {
return false;
}
if (!SPIFFS.exists("/config.json")) {
dontSaveConfig = true;
return true;
}
}
Expand Down
Loading

0 comments on commit bd271a4

Please sign in to comment.