Skip to content

Commit

Permalink
Version 2.2.2 - maintenance release for CVE HW version 1
Browse files Browse the repository at this point in the history
!Warning!
Upgrading to this version will reset all config files due to the move to another file system

Changelog:
- FIX: iOS 15 / Safari websocket issues
- FIX: Move to LittleFS for long term stability.
- FIX: MQTT evaluation always true
  • Loading branch information
arjenhiemstra committed Jan 9, 2022
1 parent 8e64b78 commit 42e10b6
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 160 deletions.
4 changes: 2 additions & 2 deletions compiled_firmware_files/firmware.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"hw_rev": {
"1": {
"latest_fw":"2.2",
"link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_1/nrgitho-hw1-v2.2.bin"
"latest_fw":"2.2.2",
"link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_1/nrgitho-hw1-v2.2.2.bin"
},
"2": {
"latest_fw":"2.2.1",
Expand Down
Binary file not shown.
20 changes: 10 additions & 10 deletions software/NRG_itho_wifi/02_HTML.ino
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,16 @@ void handleDebug(AsyncWebServerRequest *request) {

response->print(F("<br><span>File system: </span><span>"));
#if defined (__HW_VERSION_ONE__)
SPIFFS.info(fs_info);
ACTIVE_FS.info(fs_info);
response->print(fs_info.usedBytes);
#elif defined (__HW_VERSION_TWO__)
response->print(SPIFFS.usedBytes());
response->print(ACTIVE_FS.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());
response->print(ACTIVE_FS.totalBytes());
#endif
response->print(F(" bytes total</span><br><a href='#' class='pure-button' onclick=\"$('#main').empty();$('#main').append( html_edit );\">Edit filesystem</a>&nbsp;<button id=\"format\" class=\"pure-button\">Format filesystem</button>"));
#if defined (__HW_VERSION_TWO__)
Expand All @@ -281,7 +281,7 @@ void handleDebug(AsyncWebServerRequest *request) {
char link[24] = "";
char linkcur[24] = "";

if ( SPIFFS.exists("/logfile0.current.log") ) {
if ( ACTIVE_FS.exists("/logfile0.current.log") ) {
strlcpy(linkcur, "/logfile0.current.log", sizeof(linkcur));
strlcpy(link, "/logfile1.log", sizeof(link));
}
Expand All @@ -290,7 +290,7 @@ void handleDebug(AsyncWebServerRequest *request) {
strlcpy(link, "/logfile0.log", sizeof(link));
}

File file = SPIFFS.open(linkcur, FILE_READ);
File file = ACTIVE_FS.open(linkcur, FILE_READ);
while (file.available()) {
if(char(file.peek()) == '\n') response->print("<br>");
response->print(char(file.read()));
Expand All @@ -299,7 +299,7 @@ void handleDebug(AsyncWebServerRequest *request) {

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

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

}
Expand All @@ -323,13 +323,13 @@ void handleCurLogDownload(AsyncWebServerRequest *request) {
return request->requestAuthentication();
}
char link[24] = "";
if ( SPIFFS.exists("/logfile0.current.log") ) {
if ( ACTIVE_FS.exists("/logfile0.current.log") ) {
strlcpy(link, "/logfile0.current.log", sizeof(link));
}
else {
strlcpy(link, "/logfile1.current.log", sizeof(link));
}
request->send(SPIFFS, link, "", true);
request->send(ACTIVE_FS, link, "", true);
}

void handlePrevLogDownload(AsyncWebServerRequest *request) {
Expand All @@ -338,11 +338,11 @@ void handlePrevLogDownload(AsyncWebServerRequest *request) {
return request->requestAuthentication();
}
char link[24] = "";
if ( SPIFFS.exists("/logfile0.current.log") ) {
if ( ACTIVE_FS.exists("/logfile0.current.log") ) {
strlcpy(link, "/logfile1.log", sizeof(link));
}
else {
strlcpy(link, "/logfile0.log", sizeof(link));
}
request->send(SPIFFS, link, "", true);
request->send(ACTIVE_FS, link, "", true);
}
28 changes: 15 additions & 13 deletions software/NRG_itho_wifi/08_Config.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


bool loadWifiConfig() {
if (!SPIFFS.exists("/wifi.json")) {
if (!ACTIVE_FS.exists("/wifi.json")) {
#if defined (INFORMATIVE_LOGGING)
logInput("Setup: writing initial wifi config");
#endif
Expand All @@ -15,15 +15,15 @@ bool loadWifiConfig() {
}
}

File configFile = SPIFFS.open("/wifi.json", "r");
File configFile = ACTIVE_FS.open("/wifi.json", "r");
if (!configFile) {
#if defined (INFORMATIVE_LOGGING)
logInput("Setup: failed to open wifi config file");
#endif
//Serial.println("Failed to open wifi config file");
return false;
}
//SPIFFS.exists(path)
//ACTIVE_FS.exists(path)

size_t size = configFile.size();
if (size > 1024) {
Expand Down Expand Up @@ -70,7 +70,7 @@ bool saveWifiConfig() {
JsonObject root = doc.to<JsonObject>(); // Fill the object
wifiConfig.get(root);

File configFile = SPIFFS.open("/wifi.json", "w");
File configFile = ACTIVE_FS.open("/wifi.json", "w");
if (!configFile) {
//Serial.println("Failed to open default config file for writing");
return false;
Expand All @@ -84,25 +84,26 @@ bool saveWifiConfig() {
}

bool resetWifiConfig() {
if (!SPIFFS.remove("/wifi.json")) {
if (!ACTIVE_FS.remove("/wifi.json")) {
return false;
}
if (!SPIFFS.exists("/wifi.json")) {
if (!ACTIVE_FS.exists("/wifi.json")) {
dontSaveConfig = true;
return true;
}
return false;
}

bool loadSystemConfig() {

if (!SPIFFS.exists("/config.json")) {
if (!ACTIVE_FS.exists("/config.json")) {
//Serial.println("Writing initial default config");
if (!saveSystemConfig()) {
//Serial.println("Failed writing initial default config");
return false;
}
}
File configFile = SPIFFS.open("/config.json", "r");
File configFile = ACTIVE_FS.open("/config.json", "r");
if (!configFile) {
//Serial.println("Failed to open system config file");
return false;
Expand Down Expand Up @@ -139,7 +140,7 @@ bool saveSystemConfig() {
JsonObject root = doc.to<JsonObject>(); // Fill the object
systemConfig.get(root);

File configFile = SPIFFS.open("/config.json", "w");
File configFile = ACTIVE_FS.open("/config.json", "w");
if (!configFile) {
//Serial.println("Failed to open default config file for writing");
return false;
Expand All @@ -151,13 +152,14 @@ bool saveSystemConfig() {
}

bool resetSystemConfig() {
if (!SPIFFS.remove("/config.json")) {
if (!ACTIVE_FS.remove("/config.json")) {
return false;
}
if (!SPIFFS.exists("/config.json")) {
if (!ACTIVE_FS.exists("/config.json")) {
dontSaveConfig = true;
return true;
}
return false;
}
#if defined (__HW_VERSION_TWO__)

Expand All @@ -178,7 +180,7 @@ bool saveRemotesConfig() {
}

bool saveFileRemotes(const char *filename, const IthoRemote &remotes) { // Open file for writing
File file = SPIFFS.open(filename, "w");
File file = ACTIVE_FS.open(filename, "w");
if (!file) {
//Serial.println(F("Failed to create remotes file"));
return false;
Expand Down Expand Up @@ -238,7 +240,7 @@ bool loadRemotesConfig() {
}

bool loadFileRemotes(const char *filename, IthoRemote &remotes) { // Open file for reading
File file = SPIFFS.open(filename, "r");
File file = ACTIVE_FS.open(filename, "r");
// This may fail if the file is missing
if (!file) {
//Serial.println(F("Failed to open config file")); return false;
Expand Down
47 changes: 24 additions & 23 deletions software/NRG_itho_wifi/09_init_code.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ void failSafeBoot() {

if (digitalRead(FAILSAVE_PIN) == HIGH) {

SPIFFS.format();
ACTIVE_FS.begin(true);
ACTIVE_FS.format();

IPAddress apIP(192, 168, 4, 1);
IPAddress netMsk(255, 255, 255, 0);
Expand Down Expand Up @@ -125,7 +126,7 @@ bool ithoInitCheck() {
ithoInitResult = 1;
return false;
}
ithoInitResult = -1;
ithoInitResult = -1;
return true;
}

Expand Down Expand Up @@ -214,21 +215,21 @@ bool initFileSystem() {

#if defined (__HW_VERSION_ONE__)

if (!SPIFFS.begin()) {
//Serial.println("SPIFFS failed, needs formatting");
if (!ACTIVE_FS.begin()) {
//Serial.println("ACTIVE_FS failed, needs formatting");
handleFormat();
delay(500);
ESP.restart();
}
else {
if (!SPIFFS.info(fs_info)) {
if (!ACTIVE_FS.info(fs_info)) {
//Serial.println("fs_info failed");
return false;
}
}

#elif defined (__HW_VERSION_TWO__)
SPIFFS.begin(true);
ACTIVE_FS.begin(true);
#endif

return true;
Expand All @@ -237,25 +238,25 @@ bool initFileSystem() {

void handleFormat()
{
//Serial.println("Format SPIFFS");
if (SPIFFS.format())
//Serial.println("Format ACTIVE_FS");
if (ACTIVE_FS.format())
{
if (!SPIFFS.begin())
if (!ACTIVE_FS.begin())
{
//Serial.println("Format SPIFFS failed");
//Serial.println("Format ACTIVE_FS failed");
}
}
else
{
//Serial.println("Format SPIFFS failed");
//Serial.println("Format ACTIVE_FS failed");
}
if (!SPIFFS.begin())
if (!ACTIVE_FS.begin())
{
//Serial.println("SPIFFS failed, needs formatting");
//Serial.println("ACTIVE_FS failed, needs formatting");
}
else
{
//Serial.println("SPIFFS mounted");
//Serial.println("ACTIVE_FS mounted");
}
}

Expand Down Expand Up @@ -479,10 +480,10 @@ void HADiscoveryFan() {
sprintf(s, "%s/not_used/but_needed_for_HA", systemConfig.mqtt_cmd_topic);
root["cmd_t"] = s;
root["pct_cmd_t"] = (const char*)systemConfig.mqtt_cmd_topic;
root["pct_cmd_tpl"] = "{{ value * 2.54 }}";
root["pct_cmd_tpl"] = "{{ value * 2.54 }}";
root["pct_stat_t"] = (const char*)systemConfig.mqtt_state_topic;
root["pct_val_tpl"] = "{{ ((value | int) / 2.54) | round}}";

sprintf(s, "%s/fan/%s/config" , (const char*)systemConfig.mqtt_ha_topic, hostName());

sendHADiscovery(root, s);
Expand Down Expand Up @@ -571,13 +572,13 @@ bool setupMQTTClient() {

if (systemConfig.mqtt_active) {

if (systemConfig.mqtt_serverName != "") {
if (strcmp(systemConfig.mqtt_serverName, "") != 0) {

mqttClient.setServer(systemConfig.mqtt_serverName, systemConfig.mqtt_port);
mqttClient.setCallback(mqttCallback);
mqttClient.setBufferSize(MQTT_BUFFER_SIZE);

if (systemConfig.mqtt_username == "") {
if (strcmp(systemConfig.mqtt_username, "") == 0) {
connectResult = mqttClient.connect(hostName(), systemConfig.mqtt_lwt_topic, 0, true, "offline");
}
else {
Expand All @@ -603,7 +604,7 @@ bool setupMQTTClient() {
mqttClient.disconnect();
return false;
}

return false;
}

boolean reconnect() {
Expand Down Expand Up @@ -736,17 +737,17 @@ void webServerInit() {

#if defined (__HW_VERSION_ONE__)
if (systemConfig.syssec_edit) {
server.addHandler(new SPIFFSEditor(systemConfig.sys_username, systemConfig.sys_password));
server.addHandler(new SPIFFSEditor(systemConfig.sys_username, systemConfig.sys_password, ACTIVE_FS));
}
else {
server.addHandler(new SPIFFSEditor("", ""));
server.addHandler(new SPIFFSEditor("", "", ACTIVE_FS));
}
#elif defined (__HW_VERSION_TWO__)
if (systemConfig.syssec_edit) {
server.addHandler(new SPIFFSEditor(SPIFFS, systemConfig.sys_username, systemConfig.sys_password));
server.addHandler(new SPIFFSEditor(ACTIVE_FS, systemConfig.sys_username, systemConfig.sys_password));
}
else {
server.addHandler(new SPIFFSEditor(SPIFFS, "", ""));
server.addHandler(new SPIFFSEditor(ACTIVE_FS, "", ""));
}
#endif

Expand Down
5 changes: 1 addition & 4 deletions software/NRG_itho_wifi/CC1101.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* Author: Klusjesman, modified bij supersjimmie for Arduino/ESP8266
*/

#ifndef __CC1101_H__
#define __CC1101_H__
#pragma once

#include <stdio.h>
#include "CC1101Packet.h"
Expand Down Expand Up @@ -204,5 +203,3 @@ class CC1101
void reset();

}; //CC1101

#endif //__CC1101_H__
6 changes: 1 addition & 5 deletions software/NRG_itho_wifi/CC1101Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* Author: Klusjesman, modified bij supersjimmie for Arduino/ESP8266
*/

#ifndef CC1101PACKET_H_
#define CC1101PACKET_H_
#pragma once


#include <stdio.h>
Expand All @@ -19,6 +18,3 @@ class CC1101Packet
uint8_t length;
uint8_t data[128];
};


#endif /* CC1101PACKET_H_ */
7 changes: 2 additions & 5 deletions software/NRG_itho_wifi/IthoCC1101.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/*
* Author: Klusjesman, supersjimmie, modified and reworked by arjenhiemstra
*/

#ifndef __ITHOCC1101_H__
#define __ITHOCC1101_H__

#pragma once

#include <stdio.h>
#include "CC1101.h"
Expand Down Expand Up @@ -111,5 +110,3 @@ class IthoCC1101 : protected CC1101


}; //IthoCC1101

#endif //__ITHOCC1101_H__
Loading

0 comments on commit 42e10b6

Please sign in to comment.