Skip to content

Commit

Permalink
Version 2.4.0-alpha5
Browse files Browse the repository at this point in the history
fix: correct rounding issues since ArduinoJSON library update
fix: restore RF debug function to show all devices when in debug level 1 or 3 mode
fix: domoticz slider value cannot go to 0
fix: remove unused DHCP renew option
  • Loading branch information
arjenhiemstra committed Mar 23, 2022
1 parent d681d92 commit 2c3dabd
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 45 deletions.
Binary file not shown.
Binary file not shown.
8 changes: 1 addition & 7 deletions software/NRG_itho_wifi/02_JS_UI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ $(document).ready(function() {
ssid: $('#ssid').val(),
passwd: $('#passwd').val(),
dhcp: $('input[name=\'option-dhcp\']:checked').val(),
renew: $('#renew').val(),
ip: $('#ip').val(),
subnet: $('#subnet').val(),
gateway: $('#gateway').val(),
Expand Down Expand Up @@ -562,12 +561,11 @@ function radio(origin, state) {
if (origin == "dhcp") {
if (state == 'on') {
$('#ip, #subnet, #gateway, #dns1, #dns2').prop('readonly', true);
$('#renew, #port').prop('readonly', false);
$('#port').prop('readonly', false);
$('#option-dhcp-on, #option-dhcp-off').prop('disabled', false);
}
else {
$('#ip, #subnet, #gateway, #dns1, #dns2, #port').prop('readonly', false);
$('#renew').prop('readonly', true);
$('#option-dhcp-on, #option-dhcp-off').prop('disabled', false);
}
}
Expand Down Expand Up @@ -1120,10 +1118,6 @@ var html_wifisetup = `
<input id="option-dhcp-on" type="radio" name="option-dhcp" onchange='radio("dhcp", "on")' value="on"> on
<input id="option-dhcp-off" type="radio" name="option-dhcp" onchange='radio("dhcp", "off")' value="off"> off
</div>
<div class="pure-control-group">
<label for="renew">DHCP Renew interval</label>
<input id="renew" type="text">
</div>
<div class="pure-control-group">
<label for="hostname">Hostname</label>
<input id="hostname" type="text">
Expand Down
17 changes: 8 additions & 9 deletions software/NRG_itho_wifi/06_Websock_func.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ void jsonWsSend(const char* rootName) {
nested["ssid"] = wifiConfig.ssid;
nested["passwd"] = wifiConfig.passwd;
nested["dhcp"] = wifiConfig.dhcp;
nested["renew"] = wifiConfig.renew;
if (strcmp(wifiConfig.dhcp, "off") == 0) {
nested["ip"] = wifiConfig.ip;
nested["subnet"] = wifiConfig.subnet;
Expand Down Expand Up @@ -146,16 +145,16 @@ static void wsEvent(struct mg_connection *c, int ev, void *ev_data, void *fn_dat
if (ithoSettingsArray != nullptr) {
uint8_t index = root["ithosetupdate"].as<uint8_t>();
if (ithoSettingsArray[index].type == ithoSettings::is_float2) {
updateSetting(root["ithosetupdate"].as<uint8_t>(), static_cast<int32_t>(root["value"].as<float>() * 2), true);
updateSetting(root["ithosetupdate"].as<uint8_t>(), static_cast<int32_t>(root["value"].as<double>() * 2), true);
}
else if (ithoSettingsArray[index].type == ithoSettings::is_float10) {
updateSetting(root["ithosetupdate"].as<uint8_t>(), static_cast<int32_t>(root["value"].as<float>() * 10), true);
updateSetting(root["ithosetupdate"].as<uint8_t>(), static_cast<int32_t>(root["value"].as<double>() * 10), true);
}
else if (ithoSettingsArray[index].type == ithoSettings::is_float100) {
updateSetting(root["ithosetupdate"].as<uint8_t>(), static_cast<int32_t>(root["value"].as<float>() * 100), true);
updateSetting(root["ithosetupdate"].as<uint8_t>(), static_cast<int32_t>(root["value"].as<double>() * 100), true);
}
else if (ithoSettingsArray[index].type == ithoSettings::is_float1000) {
updateSetting(root["ithosetupdate"].as<uint8_t>(), static_cast<int32_t>(root["value"].as<float>() * 1000), true);
updateSetting(root["ithosetupdate"].as<uint8_t>(), static_cast<int32_t>(root["value"].as<double>() * 1000), true);
}
else {
updateSetting(root["ithosetupdate"].as<uint8_t>(), root["value"].as<int32_t>(), true);
Expand Down Expand Up @@ -210,16 +209,16 @@ static void wsEvent(struct mg_connection *c, int ev, void *ev_data, void *fn_dat
if (ithoSettingsArray != nullptr) {
uint8_t index = root["ithosetupdate"].as<uint8_t>();
if (ithoSettingsArray[index].type == ithoSettings::is_float2) {
updateSetting(root["ithosetupdate"].as<uint8_t>(), static_cast<int32_t>(root["value"].as<float>() * 2), false);
updateSetting(root["ithosetupdate"].as<uint8_t>(), static_cast<int32_t>(root["value"].as<double>() * 2), false);
}
else if (ithoSettingsArray[index].type == ithoSettings::is_float10) {
updateSetting(root["ithosetupdate"].as<uint8_t>(), static_cast<int32_t>(root["value"].as<float>() * 10), false);
updateSetting(root["ithosetupdate"].as<uint8_t>(), static_cast<int32_t>(root["value"].as<double>() * 10), false);
}
else if (ithoSettingsArray[index].type == ithoSettings::is_float100) {
updateSetting(root["ithosetupdate"].as<uint8_t>(), static_cast<int32_t>(root["value"].as<float>() * 100), false);
updateSetting(root["ithosetupdate"].as<uint8_t>(), static_cast<int32_t>(root["value"].as<double>() * 100), false);
}
else if (ithoSettingsArray[index].type == ithoSettings::is_float1000) {
updateSetting(root["ithosetupdate"].as<uint8_t>(), static_cast<int32_t>(root["value"].as<float>() * 1000), false);
updateSetting(root["ithosetupdate"].as<uint8_t>(), static_cast<int32_t>(root["value"].as<double>() * 1000), false);
}
else {
updateSetting(root["ithosetupdate"].as<uint8_t>(), root["value"].as<int32_t>(), false);
Expand Down
14 changes: 11 additions & 3 deletions software/NRG_itho_wifi/10_Gen_func.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
void getIthoStatusJSON(JsonObject root) {
if (SHT3x_original || SHT3x_alternative || itho_internal_hum_temp) {
root["temp"] = static_cast<int>(ithoTemp * 10 + 0.5) / 10.0;
root["hum"] = static_cast<int>(ithoHum * 10 + 0.5) / 10.0;
root["temp"] = round(ithoTemp, 1);
root["hum"] = round(ithoHum, 1);

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;
Expand Down Expand Up @@ -456,9 +456,17 @@ void logWifiInfo() {
void setRFdebugLevel(uint8_t level) {
char logBuff[LOG_BUF_SIZE] {};
debugLevel = level;
rf.setAllowAll(false);
rf.setAllowAll(true);
if(level == 2) {
rf.setAllowAll(false);
}
sprintf(logBuff, "Debug level = %d", debugLevel);
logMessagejson(logBuff, WEBINTERFACE);
strcpy(logBuff, "");

}

double round(double value, int precision) {
double pow10 = pow(10.0, precision);
return static_cast<int>(value * pow10 + 0.5) / pow10;
}
2 changes: 1 addition & 1 deletion software/NRG_itho_wifi/IthoRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void IthoRemote::updateRemoteType(const uint8_t index, const uint16_t type) {

void IthoRemote::addCapabilities(uint8_t remoteIndex, const char* name, int32_t value) {
if (strcmp(name, "temp") == 0 || strcmp(name, "dewpoint") == 0) {
remotes[remoteIndex].capabilities[name] = static_cast<int>((value / 100.0f) * 10 + 0.5) / 10.0;
remotes[remoteIndex].capabilities[name] = static_cast<int>((value / 100.0) * 10 + 0.5) / 10.0;
}
else {
remotes[remoteIndex].capabilities[name] = value;
Expand Down
15 changes: 8 additions & 7 deletions software/NRG_itho_wifi/IthoSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ int32_t * resultPtr2410 = nullptr;
bool i2c_result_updateweb = false;

bool itho_internal_hum_temp = false;
float ithoHum = 0;
float ithoTemp = 0;
double ithoHum = 0;
double ithoTemp = 0;

Ticker getSettingsHack;
SemaphoreHandle_t mutexI2Ctask;
Expand Down Expand Up @@ -705,7 +705,7 @@ void sendQueryStatus(bool updateweb) {
ithoStat.value.intval = tempVal;
}
if (ithoStat.type == ithoDeviceStatus::is_float) {
ithoStat.value.floatval = (float)tempVal / ithoStat.divider;
ithoStat.value.floatval = static_cast<double>(tempVal) / ithoStat.divider;
}

statusPos += ithoStat.length;
Expand Down Expand Up @@ -1101,7 +1101,7 @@ void sendQuery31D9(bool updateweb) {
}
}

float tempVal = i2cbuf[1 + dataStart] / 2.0;
double tempVal = i2cbuf[1 + dataStart] / 2.0;
ithoDeviceMeasurements sTemp = {labels31D9[0], ithoDeviceMeasurements::is_float, {.floatval = tempVal} } ;
ithoInternalMeasurements.push_back(sTemp);

Expand Down Expand Up @@ -1284,7 +1284,7 @@ int32_t * sendQuery2410(bool & updateweb) {
sprintf(tempbuffer2, "%d", values[2]);
}
else if (ithoSettingsArray[index2410].type == ithoSettings::is_float10) {
float val[3];
double val[3];
val[0] = values[0] / 10.0f;
val[1] = values[1] / 10.0f;
val[2] = values[2] / 10.0f;
Expand All @@ -1293,7 +1293,7 @@ int32_t * sendQuery2410(bool & updateweb) {
sprintf(tempbuffer2, "%.1f", val[2]);
}
else if (ithoSettingsArray[index2410].type == ithoSettings::is_float100) {
float val[3];
double val[3];
val[0] = values[0] / 100.0f;
val[1] = values[1] / 100.0f;
val[2] = values[2] / 100.0f;
Expand All @@ -1302,7 +1302,7 @@ int32_t * sendQuery2410(bool & updateweb) {
sprintf(tempbuffer2, "%.2f", val[2]);
}
else if (ithoSettingsArray[index2410].type == ithoSettings::is_float1000) {
float val[3];
double val[3];
val[0] = values[0] / 1000.0f;
val[1] = values[1] / 1000.0f;
val[2] = values[2] / 1000.0f;
Expand Down Expand Up @@ -1439,6 +1439,7 @@ int quick_pow10(int n) {
1, 10, 100, 1000, 10000,
100000, 1000000, 10000000, 100000000, 1000000000
};
if(n>(sizeof(pow10)/sizeof(pow10[0])-1)) return 1;
return pow10[n];
}

Expand Down
8 changes: 4 additions & 4 deletions software/NRG_itho_wifi/IthoSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ extern int32_t *resultPtr2410;
extern bool i2c_result_updateweb;

extern bool itho_internal_hum_temp;
extern float ithoHum;
extern float ithoTemp;
extern double ithoHum;
extern double ithoTemp;

extern Ticker getSettingsHack;
extern SemaphoreHandle_t mutexI2Ctask;
Expand All @@ -51,7 +51,7 @@ struct ithoDeviceStatus {
byte byteval;
int32_t intval;
uint32_t uintval;
float floatval;
double floatval;
const char* stringval;
} value;
uint32_t divider;
Expand All @@ -63,7 +63,7 @@ struct ithoDeviceMeasurements {
enum : uint8_t { is_int, is_float, is_string } type;
union {
int32_t intval;
float floatval;
double floatval;
const char* stringval;
} value;
};
Expand Down
4 changes: 2 additions & 2 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.4.0-alpha4"
#define FWVERSION "2.4.0-alpha5"

#define LOGGING_INTERVAL 21600000 //Log system status at regular intervals
#define ENABLE_FAILSAVE_BOOT
Expand Down Expand Up @@ -43,7 +43,7 @@
#include "IthoSystem.h"
#include "notifyClients.h"
#include "IthoCC1101.h"
#include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson [6.18.5]
#include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson [6.19.3]
#include <ESPAsyncWebServer.h> // https://github.com/me-no-dev/ESPAsyncWebServer [latest]
#include <SPIFFSEditor.h> // https://github.com/me-no-dev/ESPAsyncWebServer [latest]
#include <DNSServer.h>
Expand Down
13 changes: 8 additions & 5 deletions software/NRG_itho_wifi/TaskMQTT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,15 @@ void updateState(uint16_t newState) {

if (systemConfig.mqtt_domoticz_active) {
int nvalue = 1;
double state = 1.0;
if (newState > 0) {
state = newState / 2.54;
double state = 0.0;
if (newState > 0.5) {
state = (newState / 2.54) + 0.5;
}

newState = uint16_t(state + 0.5);
else {
state = 0.0;
nvalue = 0;
}
newState = uint16_t(state);
char buf[10];
sprintf(buf, "%d", newState);

Expand Down
6 changes: 0 additions & 6 deletions software/NRG_itho_wifi/WifiConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ WifiConfig::WifiConfig() {
strlcpy(ssid, "", sizeof(ssid));
strlcpy(passwd, "", sizeof(passwd));
strlcpy(dhcp, "on", sizeof(dhcp));
renew = 60;
strlcpy(ip, "192.168.4.1", sizeof(ip));
strlcpy(subnet, "255.255.255.0", sizeof(subnet));
strlcpy(gateway, "127.0.0.1", sizeof(gateway));
Expand Down Expand Up @@ -44,10 +43,6 @@ bool WifiConfig::set(JsonObjectConst obj) {
updated = true;
strlcpy(dhcp, obj["dhcp"], sizeof(dhcp));
}
if (!(const char*)obj["renew"].isNull()) {
updated = true;
renew = obj["renew"];
}
if (!(const char*)obj["ip"].isNull()) {
updated = true;
strlcpy(ip, obj["ip"], sizeof(ip));
Expand Down Expand Up @@ -87,7 +82,6 @@ void WifiConfig::get(JsonObject obj) const {
obj["ssid"] = ssid;
obj["passwd"] = passwd;
obj["dhcp"] = dhcp;
obj["renew"] = renew;
obj["ip"] = ip;
obj["subnet"] = subnet;
obj["gateway"] = gateway;
Expand Down
1 change: 0 additions & 1 deletion software/NRG_itho_wifi/WifiConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class WifiConfig {
char ssid[33];
char passwd[65];
char dhcp[5];
uint8_t renew;
char ip[16];
char subnet[16];
char gateway[16];
Expand Down

0 comments on commit 2c3dabd

Please sign in to comment.