Skip to content

Commit

Permalink
Version 2.3.3
Browse files Browse the repository at this point in the history
- Move the Mongoose for WebSocket server to fix stability issues and win10 WebSocket issues
- Round hum and temp values to 1 decimal
- clean-up includes, move to c++ libs
  • Loading branch information
arjenhiemstra committed Dec 5, 2021
1 parent afbde58 commit 36bbefc
Show file tree
Hide file tree
Showing 40 changed files with 6,983 additions and 286 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ url=https://github.com/arjenhiemstra/FS_FilePrint
[submodule "software/lib/ESPAsyncTCP"]
path = software/lib/ESPAsyncTCP
url = https://github.com/me-no-dev/ESPAsyncTCP
[submodule "software/lib/Mongoose"]
path = software/lib/Mongoose
url = https://github.com/cesanta/mongoose.git
8 changes: 4 additions & 4 deletions compiled_firmware_files/firmware.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_1/nrgitho-hw1-v2.2.1.bin"
},
"2": {
"latest_fw":"2.3.2",
"link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_2/nrgitho-hw2-v2.3.2.bin"
"latest_fw":"2.3.3",
"link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_2/nrgitho-hw2-v2.3.3.bin"
},
"NON-CVE 1": {
"latest_fw":"2.3.2",
"link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/non-cve_rev_1/nrgitho-noncve-v2.3.2.bin"
"latest_fw":"2.3.3",
"link":"https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/non-cve_rev_1/nrgitho-noncve-v2.3.3.bin"
}
}
}
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion software/NRG_itho_wifi/02_JS_UI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var sensor = -1;
sessionStorage.setItem("statustimer", 0);
var websocketServerLocation = 'ws://' + window.location.hostname + '/ws';
var websocketServerLocation = 'ws://' + window.location.hostname + ':8000/ws';
function startWebsock(websocketServerLocation){
Expand Down
383 changes: 183 additions & 200 deletions software/NRG_itho_wifi/06_Websock_func.ino

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions software/NRG_itho_wifi/09_init_code.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void failSafeBoot() {
yield();

if (digitalRead(FAILSAVE_PIN) == HIGH) {

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

Expand Down Expand Up @@ -71,6 +71,7 @@ void failSafeBoot() {
for (;;) {
yield();
if (shouldReboot) {
ACTIVE_FS.end();
delay(1000);
esp_task_wdt_init(1, true);
esp_task_wdt_add(NULL);
Expand Down Expand Up @@ -487,8 +488,9 @@ void ArduinoOTAinit() {
}

void websocketInit() {
ws.onEvent(onWsEvent);
server.addHandler(&ws);
mg_log_set("0");
mg_mgr_init(&mgr); // Initialise event manager
mg_http_listen(&mgr, s_listen_on_ws, wsEvent, NULL); // Create WS listener
}

void webServerInit() {
Expand Down
6 changes: 3 additions & 3 deletions software/NRG_itho_wifi/10_Gen_func.ino
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
void getIthoStatusJSON(JsonObject root) {
if (SHT3x_original || SHT3x_alternative || itho_internal_hum_temp) {
root["temp"] = ithoTemp;
root["hum"] = ithoHum;
root["temp"] = static_cast<int>(ithoTemp * 10 + 0.5) / 10.0;
root["hum"] = static_cast<int>(ithoHum * 10 + 0.5) / 10.0;

auto b = 611.21 * pow(2.7183, ((18.678 - ithoTemp / 234.5) * ithoTemp) / (257.14 + ithoTemp));
auto ppmw = b / (101325 - b) * ithoHum / 100 * 0.62145 * 1000000;
root["ppmw"] = (int)(ppmw+0.5);
root["ppmw"] = static_cast<int>(ppmw+0.5);
}

if (!ithoInternalMeasurements.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion software/NRG_itho_wifi/CC1101.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include <stdio.h>
#include <cstdio>
#include "CC1101Packet.h"
#include <SPI.h>
// On Arduino, SPI pins are predefined
Expand Down
2 changes: 1 addition & 1 deletion software/NRG_itho_wifi/CC1101Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include <stdio.h>
#include <cstdio>
#include <Arduino.h>

#define CC1101_BUFFER_LEN 64
Expand Down
2 changes: 1 addition & 1 deletion software/NRG_itho_wifi/IthoCC1101.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "IthoCC1101.h"
#include "IthoPacket.h"
#include <string.h>
#include <string>
#include <Arduino.h>
#include <SPI.h>

Expand Down
10 changes: 7 additions & 3 deletions software/NRG_itho_wifi/IthoCC1101.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

#pragma once

#include <stdio.h>
#include <cstdio>
#include <string>

#include <Ticker.h>

#include "CC1101.h"
#include "IthoPacket.h"
#include <Ticker.h>
#include <string>



#define MAX_NUMBER_OF_REMOTES 10

Expand Down
2 changes: 1 addition & 1 deletion software/NRG_itho_wifi/IthoPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include <stdint.h>
#include <cstdint>

enum IthoCommand
{
Expand Down
4 changes: 3 additions & 1 deletion software/NRG_itho_wifi/IthoQueue.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "IthoQueue.h"
#include <algorithm>

#include "IthoQueue.h"



// default constructor
IthoQueue::IthoQueue() {
Expand Down
6 changes: 3 additions & 3 deletions software/NRG_itho_wifi/IthoQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#define MAX_QUEUE 10
#define QUEUE_UPDATE_MS 100


#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <string>

#include <Arduino.h>
#include <ArduinoJson.h>
#include <Ticker.h>
Expand Down
2 changes: 1 addition & 1 deletion software/NRG_itho_wifi/IthoRemote.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "IthoRemote.h"

#include <string.h>
#include <string>
#include <Arduino.h>


Expand Down
6 changes: 4 additions & 2 deletions software/NRG_itho_wifi/IthoRemote.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#define MAX_NUMBER_OF_REMOTES 10
#define REMOTE_CONFIG_VERSION "002"

#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <string>

#include <Arduino.h>
#include <ArduinoJson.h>
#include <Ticker.h>

#include "IthoPacket.h"

class IthoRemote {
Expand Down
10 changes: 5 additions & 5 deletions software/NRG_itho_wifi/IthoSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ int getSettingsLength(const uint8_t deviceID, const uint8_t version) {
}

for (int i = 0; i < 999; i++) {
if ((int) * (*(ithoDevicesptr->settingsMapping + version) + i) == 999) {
if (static_cast<int>( * (*(ithoDevicesptr->settingsMapping + version) + i) == 999 )) {
//end of array
if (ithoSettingsArray == nullptr) ithoSettingsArray = new ithoSettings[i];
return i;
Expand Down Expand Up @@ -156,7 +156,7 @@ void getSetting(const uint8_t i, const bool updateState, const bool updateweb, c
JsonObject root = doc.to<JsonObject>();

root["Index"] = i;
root["Description"] = settingsPtr->settingsDescriptions[(int) * (*(settingsPtr->settingsMapping + version) + i)];
root["Description"] = settingsPtr->settingsDescriptions[static_cast<int>( * (*(settingsPtr->settingsMapping + version) + i ))];

if (!updateState && !updateweb) {
root["update"] = false;
Expand Down Expand Up @@ -250,7 +250,7 @@ int getStatusLabelLength(const uint8_t deviceID, const uint8_t version) {
}

for (int i = 0; i < 255; i++) {
if ((int) * (*(ithoDevicesptr->statusLabelMapping + version) + i) == 255) {
if (static_cast<int>( * (*(ithoDevicesptr->statusLabelMapping + version) + i) == 255 )) {
//end of array
return i;
}
Expand Down Expand Up @@ -297,10 +297,10 @@ const char* getSatusLabel(const uint8_t i, const struct ihtoDeviceType* statusPt
}
else {
if (systemConfig.api_normalize == 0) {
return (statusPtr->settingsStatusLabels[(int) * (*(statusPtr->statusLabelMapping + version) + i)].labelFull);
return (statusPtr->settingsStatusLabels[static_cast<int>( * (*(statusPtr->statusLabelMapping + version) + i) )].labelFull);
}
else {
return (statusPtr->settingsStatusLabels[(int) * (*(statusPtr->statusLabelMapping + version) + i)].labelNormalized);
return (statusPtr->settingsStatusLabels[static_cast<int>( * (*(statusPtr->statusLabelMapping + version) + i) )].labelNormalized);
}
}

Expand Down
9 changes: 5 additions & 4 deletions software/NRG_itho_wifi/IthoSystem.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#pragma once

#include <stdio.h>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <cstring>

#include <Arduino.h>
#include <Ticker.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>

extern uint8_t ithoDeviceID;
extern uint8_t itho_fwversion;
Expand Down
8 changes: 5 additions & 3 deletions software/NRG_itho_wifi/NRG_itho_wifi.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define FWVERSION "2.3.2"
#define FWVERSION "2.3.3"

#define LOGGING_INTERVAL 21600000 //Log system status at regular intervals
#define ENABLE_FAILSAVE_BOOT
Expand Down Expand Up @@ -50,6 +50,7 @@
#include <time.h>
#include <Ticker.h>
#include <string>
#include <cstring>

#include "IthoQueue.h"
#include "System.h"
Expand All @@ -68,8 +69,8 @@
#include "esp_wifi.h"
#include <ESPmDNS.h>
#include <AsyncTCP.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "esp_task_wdt.h"
#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
Expand Down Expand Up @@ -169,6 +170,7 @@ unsigned long wifiLedUpdate = 0;
unsigned long SHT3x_readout = 0;
unsigned long query2401tim = 0;
unsigned long lastLog = 0;
unsigned long lastVersionCheck;

//flags used
bool joinSend = false;
Expand Down
3 changes: 2 additions & 1 deletion software/NRG_itho_wifi/SHTSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <inttypes.h>
#include <cinttypes>

#include <Wire.h>
#include <Arduino.h>

Expand Down
2 changes: 1 addition & 1 deletion software/NRG_itho_wifi/SHTSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#pragma once

#include <inttypes.h>
#include <cinttypes>

// Forward declaration
class SHTSensorDriver;
Expand Down
6 changes: 4 additions & 2 deletions software/NRG_itho_wifi/SystemConfig.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "SystemConfig.h"
#include <string.h>
#include <string>

#include <Arduino.h>

#include "SystemConfig.h"

SystemConfig systemConfig;

// default constructor
Expand Down
5 changes: 3 additions & 2 deletions software/NRG_itho_wifi/SystemConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

#define CONFIG_VERSION "005" //Change when SystemConfig struc changes

#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <string>

#include <Arduino.h>
#include <ArduinoJson.h>

Expand Down
2 changes: 2 additions & 0 deletions software/NRG_itho_wifi/TaskCC1101.ino
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ void TaskCC1101( void * pvParameters ) {
reboot.attach(2, []() {
logInput("Setup: init of CC1101 RF module failed");
saveSystemConfig();
delay(1000);
ACTIVE_FS.end();
esp_task_wdt_init(1, true);
esp_task_wdt_add(NULL);
while (true);
Expand Down
2 changes: 1 addition & 1 deletion software/NRG_itho_wifi/TaskMQTT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void mqttCallback(const char* topic, const byte* payload, unsigned int length) {
if (length > 1023) length = 1023;

char s_payload[length];
memcpy(s_payload, payload, length);
std::memcpy(s_payload, payload, length);
s_payload[length] = '\0';

if (strcmp(topic, systemConfig.mqtt_cmd_topic) == 0) {
Expand Down
9 changes: 9 additions & 0 deletions software/NRG_itho_wifi/TaskSysControl.ino
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ void TaskSysControl( void * pvParameters ) {
if (!dontSaveConfig) {
saveSystemConfig();
}
delay(1000);
ACTIVE_FS.end();
esp_task_wdt_init(1, true);
esp_task_wdt_add(NULL);
while (true);
Expand Down Expand Up @@ -160,6 +162,13 @@ void execSystemControlTasks() {
}

}
if (!(itho_fwversion > 0) && millis() - lastVersionCheck > 60000) {
lastVersionCheck = millis();
if (xSemaphoreTake(mutexI2Ctask, (TickType_t) 1000 / portTICK_PERIOD_MS) == pdTRUE) {
sendQueryDevicetype(i2c_result_updateweb);
xSemaphoreGive(mutexI2Ctask);
}
}
//request itho status every 5 sec.
if (millis() - query2401tim >= systemConfig.itho_updatefreq * 1000UL && i2cStartCommands) {
query2401tim = millis();
Expand Down
5 changes: 3 additions & 2 deletions software/NRG_itho_wifi/TaskWeb.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ void TaskWeb( void * pvParameters ) {
TaskWebHWmark = uxTaskGetStackHighWaterMark( NULL );
vTaskDelay(25 / portTICK_PERIOD_MS);
}

mg_mgr_free(&mgr);
//else delete task
vTaskDelete( NULL );
}

void execWebTasks() {
ArduinoOTA.handle();
ws.cleanupClients();
//ws.cleanupClients();
mg_mgr_poll(&mgr, 1000);
if (millis() - previousUpdate >= 5000 || sysStatReq) {
if (millis() - lastSysMessage >= 1000 && !onOTA) { //rate limit messages to once a second
sysStatReq = false;
Expand Down
6 changes: 4 additions & 2 deletions software/NRG_itho_wifi/WifiConfig.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "WifiConfig.h"
#include <string.h>
#include <string>

#include <Arduino.h>

#include "WifiConfig.h"


// default constructor
WifiConfig::WifiConfig() {
Expand Down
Loading

0 comments on commit 36bbefc

Please sign in to comment.