Skip to content

Commit

Permalink
20240417
Browse files Browse the repository at this point in the history
Web UI:
- Add reconnect interval in MQTT preferences page
- Fix continues event open tries if error
- Fix root page some static values update if language change

Code:
- Switched to Async-MQTT-Client - much faster, more stability while multi-tasking

Build and Development:
- Fix release info download counts badge clear line before description
- Renamed i18next root objects to 1 letter, next to 2 letters
- Add prod and debug UART log levels
- Colored UART logs
- Colored build logs

Docs:

Hardware:
  • Loading branch information
xyzroe committed Apr 17, 2024
1 parent f223136 commit 1553999
Show file tree
Hide file tree
Showing 55 changed files with 1,115 additions and 1,116 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ jobs:
id: get_commit_message
run: |
currentTag=${GITHUB_REF#refs/tags/}
badgeText="![GitHub Downloads](https://img.shields.io/github/downloads/xyzroe/XZG/$currentTag/total)%0A"
commitMessage=$(git log -1 --pretty=%B | tail -n +3)
badgeText=`![GitHub Downloads](https://img.shields.io/github/downloads/xyzroe/XZG/$currentTag/total}
`
commitMessage=$(git log -1 --pretty=%B | tail -n +2)
fullCommitMessage="$badgeText$commitMessage"
echo "commitMessage<<EOF" >> $GITHUB_ENV
echo "$fullCommitMessage" >> $GITHUB_ENV
Expand Down
6 changes: 3 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,19 @@ makes it unnecessary.

3. Protecting Users' Legal Rights From Anti-Circumvention Law.

No covered work shall be deemed part of an effective technological
No covered work shall be deemed part of an effective technoLOGDcal
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.

When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
circumvention of technoLOGDcal measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
technoLOGDcal measures.

4. Conveying Verbatim Copies.

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Firmware is opensource, so feel free to improve it <br> by making a commit to th
- Change Ethernet/USB adapter mode through firmware or by physical button short press (Red LED On = USB mode, RED LED Off = Ethernet mode);
- Adapter mode selector through web-interface: `Zigbee-to-Network` or `Zigbee-to-USB`;
- Support mDNS autodiscovery in your network (go in the browser to `xzg.local`), in Zigbee2MQTT (set `port: mdns://xzg`), and in ZHA;
- Secure login through username and password;
- Secure LOGDn through username and password;
- Zigbee2MQTT and ZHA config helper;

- ESP32 (peripheral) and CC2652P (Zigbee) OTA updates, ESP32 and CC2652P restart;
Expand Down Expand Up @@ -136,14 +136,14 @@ Special thanks to all third-party library authors. Their work has significantly
- [esprfid / esp-rfid](https://github.com/esprfid/esp-rfid),
- [fairecasoimeme / zigate-ethernet](https://github.com/fairecasoimeme/ZiGate-Ethernet),
- [bblanchon / arduinojson](https://github.com/bblanchon/ArduinoJson),
- [rlogiacco / circularbuffer](https://github.com/rlogiacco/CircularBuffer),
- [rLOGDacco / circularbuffer](https://github.com/rLOGDacco/CircularBuffer),
- [sstaub / ticker](https://github.com/sstaub/Ticker),
- [vurtun / lib](https://github.com/vurtun/lib),
- [Tinkerforge / WireGuard-ESP32-Arduino](https://github.com/Tinkerforge/WireGuard-ESP32-Arduino),
- [sstaub / Ticker](https://github.com/sstaub/Ticker),
- [knolleary / PubSubClient](https://github.com/knolleary/pubsubclient),
- [Martin-Laclaustra / CronAlarms](https://github.com/Martin-Laclaustra/CronAlarms),
- [xreef / WebServer-Esp8266-ESP32-Tutorial](https://github.com/xreef/WebServer-Esp8266-ESP32-Tutorial)
- [xreef / WebServer-Esp8266-ESP32-Tutorial](https://github.com/xreef/WebServer-Esp8266-ESP32-Tutorial),
- [marvinroger / async-mqtt-client](https://github.com/marvinroger/async-mqtt-client)


## 📄 License
Expand Down
Binary file removed bin/XZG_20240415.full.bin
Binary file not shown.
Binary file removed bin/XZG_20240415.ota.bin
Binary file not shown.
Binary file added bin/XZG_20240417.full.bin
Binary file not shown.
Binary file added bin/XZG_20240417.ota.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ lib_deps =
bblanchon/[email protected]
rlogiacco/CircularBuffer@>=1.4.0
sstaub/Ticker@>=4.4.0
knolleary/PubSubClient@^2.8
Martin-Laclaustra/CronAlarms
husarnet/Husarnet ESP32 @ 1.2.0-5 ;husarnet example
marvinroger/AsyncMqttClient@^0.9.0
;plerup/[email protected]
;marian-craciunescu/ESP32Ping@>=1.7
;me-no-dev/[email protected]
Expand Down
85 changes: 46 additions & 39 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "config.h"
#include "etc.h"
#include "web.h"
#include "keys.h"
#include "const/keys.h"

Preferences preferences;

Expand Down Expand Up @@ -38,31 +38,31 @@ void printNVSFreeSpace()
{
int total, used;
getNvsStats(&total, &used);
LOGI(tag, "Total Entries: %d, Used Entries: %d, Free Entries: %d", total, used, (total - used));
LOGD("Total Entries: %d, Used Entries: %d, Free Entries: %d", total, used, (total - used));
}

void eraseNVS()
{
LOGI(tag, "Going to erase NVS. It will factory reset device.");
LOGD("Going to erase NVS. It will factory reset device.");
int timeDelay = 3;
for (int i = 0; i < timeDelay; i++)
{
LOGI(tag, "%d seconds left..", (timeDelay - i));
LOGD("%d seconds left..", (timeDelay - i));
delay(1000);
}
LOGI(tag, "Erasing NVS. It will factory reset device!");
LOGD("Erasing NVS. It will factory reset device!");
ESP_ERROR_CHECK(nvs_flash_erase());
esp_err_t ret = nvs_flash_init();
ESP_ERROR_CHECK(ret);
LOGI(tag, "Erase complete!");
LOGD("Erase complete!");
}

void initNVS()
{
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
{
LOGI(tag, "ESP_ERR_NVS_NO_FREE_PAGES || ESP_ERR_NVS_NEW_VERSION_FOUND . DOWNGRADE and BACKUP CONFIG");
LOGD("ESP_ERR_NVS_NO_FREE_PAGES || ESP_ERR_NVS_NEW_VERSION_FOUND . DOWNGRADE and BACKUP CONFIG");
while (true)
{
delay(1); // stop any work
Expand Down Expand Up @@ -387,15 +387,15 @@ void updateConfiguration(WebServer &serverWeb, SystemConfigStruct &configSys, Ne

if (serverWeb.hasArg(nmStartHourKey))
{
LOGI(tag, "nmStartHourKey %s", String(serverWeb.arg(nmStartHourKey)));
//Serial.println(convertTimeToCron(serverWeb.arg(nmStartHourKey)));
LOGD("nmStartHourKey %s", String(serverWeb.arg(nmStartHourKey)));
// Serial.println(convertTimeToCron(serverWeb.arg(nmStartHourKey)));
strncpy(configSys.nmStart, serverWeb.arg(nmStartHourKey).c_str(), sizeof(configSys.nmStart) - 1);
configSys.nmStart[sizeof(configSys.nmStart) - 1] = '\0'; // Guarantee a null terminator at the end
}
if (serverWeb.hasArg(nmEndHourKey))
{
LOGI(tag, "nmEndHourKey %s", String(serverWeb.arg(nmEndHourKey)));
//Serial.println(convertTimeToCron(serverWeb.arg(nmEndHourKey)));
LOGD("nmEndHourKey %s", String(serverWeb.arg(nmEndHourKey)));
// Serial.println(convertTimeToCron(serverWeb.arg(nmEndHourKey)));
strncpy(configSys.nmEnd, serverWeb.arg(nmEndHourKey).c_str(), sizeof(configSys.nmEnd) - 1);
configSys.nmEnd[sizeof(configSys.nmEnd) - 1] = '\0'; // Guarantee a null terminator at the end
}
Expand Down Expand Up @@ -581,6 +581,12 @@ void updateConfiguration(WebServer &serverWeb, SystemConfigStruct &configSys, Ne
configMqtt.updateInt = serverWeb.arg(MqttIntervalKey).toInt();
}

const char *mqttReconnectKey = "mqttReconnect";
if (serverWeb.hasArg(mqttReconnectKey))
{
configMqtt.reconnectInt = serverWeb.arg(mqttReconnectKey).toInt();
}

const char *MqttDiscoveryKey = "MqttDiscovery";
configMqtt.discovery = serverWeb.hasArg(MqttDiscoveryKey) == true;

Expand Down Expand Up @@ -742,7 +748,7 @@ void serializeSysVarsToJson(const SysVarsStruct &vars, JsonObject obj)
obj[hwZigbeeIsKey] = vars.hwZigbeeIs;

// Assuming WORK_MODE_t can be directly cast to int for serialization
// obj[workModeKey] = static_cast<int>(systemCfg.workMode);
// obj[workModeKey] = static_cast<int>(systemCfg.workMode);

// Serializing an array of connectedSocket
/*JsonArray connectedSocketArray = obj.createNestedArray(connectedSocket);
Expand Down Expand Up @@ -828,12 +834,12 @@ bool loadFileConfigHW()

if (hwConfig.board[0] != '\0' && strlen(hwConfig.board) > 0)
{
LOGI(tag, "LOAD - OK");
LOGD("LOAD - OK");
return true;
}
else
{
LOGE(tag, "LOAD - ERROR");
LOGP("LOAD - ERROR");

int searchId = 0;
if (config["searchId"])
Expand All @@ -843,7 +849,7 @@ bool loadFileConfigHW()
BrdConfigStruct *newConfig = findBrdConfig(searchId);
if (newConfig)
{
LOGI(tag, "Find. Saving config");
LOGD("Find. Saving config");

DynamicJsonDocument config(512);
config[board] = newConfig->board;
Expand All @@ -864,13 +870,13 @@ bool loadFileConfigHW()
config[zbBslPin] = newConfig->zb.bslPin;
writeDefaultConfig(configFileHw, config);

LOGI(tag, "Calc and save temp offset");
LOGD("Calc and save temp offset");
float CPUtemp = getCPUtemp(true);
int offset = CPUtemp - 30;
systemCfg.tempOffset = int(offset);
saveSystemConfig(systemCfg);

LOGI(tag, "Restarting...");
LOGD("Restarting...");
ESP.restart();
}
}
Expand All @@ -888,18 +894,18 @@ void fileReadError(String tag, DeserializationError error, const char *fileName)
File configFile = LittleFS.open(fileName, FILE_READ);
if (!configFile)
{
LOGE(tag, "Failed to open file: %s", fileName);
LOGP("Failed to open file: %s", fileName);
return;
}
while (configFile.available())
{
fileContent += (char)configFile.read();
}
LOGE(tag, "%s - %s - %s", fileName, error.f_str(), fileContent.c_str());
LOGP("%s - %s - %s", fileName, error.f_str(), fileContent.c_str());
configFile.close();
if (error == DeserializationError::EmptyInput)
{
LOGI(tag, "%s %s", fileName, msg_file_rm);
LOGD("%s %s", fileName, msg_file_rm);
LittleFS.remove(fileName);
}
}
Expand All @@ -911,7 +917,7 @@ bool loadFileSystemVar()
File configFile = LittleFS.open(configFileSystem, FILE_READ);
if (!configFile)
{
LOGI(tag, "%s %s", configFileSystem, msg_open_f);
LOGD("%s %s", configFileSystem, msg_open_f);
return false;
}

Expand All @@ -928,7 +934,7 @@ bool loadFileSystemVar()
systemCfg.tempOffset = (int)doc[tempOffsetKey];

configFile.close();
LOGI(tag, "%s %s", configFileSystem, msg_file_rm);
LOGD("%s %s", configFileSystem, msg_file_rm);
saveSystemConfig(systemCfg);
LittleFS.remove(configFileSystem);
return true;
Expand All @@ -948,7 +954,7 @@ bool loadFileConfigWifi()
File configFile = LittleFS.open(configFileWifi, FILE_READ);
if (!configFile)
{
LOGI(tag, "%s %s", configFileWifi, msg_open_f);
LOGD("%s %s", configFileWifi, msg_open_f);
return false;
}

Expand All @@ -971,7 +977,7 @@ bool loadFileConfigWifi()
networkCfg.wifiGate.fromString(doc[gw] | "");

configFile.close();
LOGI(tag, "%s %s", configFileWifi, msg_file_rm);
LOGD("%s %s", configFileWifi, msg_file_rm);
saveNetworkConfig(networkCfg);
LittleFS.remove(configFileWifi);
return true;
Expand All @@ -989,7 +995,7 @@ bool loadFileConfigEther()
File configFile = LittleFS.open(configFileEther, FILE_READ);
if (!configFile)
{
LOGI(tag, "%s %s", configFileEther, msg_open_f);
LOGD("%s %s", configFileEther, msg_open_f);
return false;
}

Expand All @@ -1009,7 +1015,7 @@ bool loadFileConfigEther()
networkCfg.ethGate.fromString(doc[gw] | "");

configFile.close();
LOGI(tag, "%s %s", configFileEther, msg_file_rm);
LOGD("%s %s", configFileEther, msg_file_rm);
saveNetworkConfig(networkCfg);
LittleFS.remove(configFileEther);
return true;
Expand All @@ -1024,7 +1030,7 @@ bool loadFileConfigGeneral()
File configFile = LittleFS.open(configFileGeneral, FILE_READ);
if (!configFile)
{
LOGI(tag, "%s %s", configFileGeneral, msg_open_f);
LOGD("%s %s", configFileGeneral, msg_open_f);
return false;
}

Expand Down Expand Up @@ -1052,9 +1058,9 @@ bool loadFileConfigGeneral()
strlcpy(systemCfg.hostname, doc[hostnameKey] | "", sizeof(systemCfg.hostname));

systemCfg.workMode = static_cast<WORK_MODE_t>((uint8_t)doc[coordMode]);
//systemCfg.prevWorkMode = static_cast<WORK_MODE_t>((uint8_t)doc[prevCoordMode]);
// DEBUG_PRINT(F("[loadFileConfigGeneral] 'vars.workMode' res is: "));
// DEBUG_PRINTLN(String(vars.workMode));
// systemCfg.prevWorkMode = static_cast<WORK_MODE_t>((uint8_t)doc[prevCoordMode]);
// DEBUG_PRINT(F("[loadFileConfigGeneral] 'vars.workMode' res is: "));
// DEBUG_PRINTLN(String(vars.workMode));

systemCfg.disableLedPwr = (uint8_t)doc[disableLedPwrKey];
// DEBUG_PRINTLN(F("[loadFileConfigGeneral] disableLedPwr"));
Expand All @@ -1067,7 +1073,7 @@ bool loadFileConfigGeneral()
strlcpy(systemCfg.timeZone, doc[timeZoneKey] | "", sizeof(systemCfg.timeZone));

configFile.close();
LOGI(tag, "%s %s", configFileGeneral, msg_file_rm);
LOGD("%s %s", configFileGeneral, msg_file_rm);
saveSystemConfig(systemCfg);
LittleFS.remove(configFileGeneral);
return true;
Expand All @@ -1080,7 +1086,7 @@ bool loadFileConfigSecurity()
File configFile = LittleFS.open(configFileSecurity, FILE_READ);
if (!configFile)
{
LOGI(tag, "%s %s", configFileSecurity, msg_open_f);
LOGD("%s %s", configFileSecurity, msg_open_f);
return false;
}

Expand All @@ -1102,7 +1108,7 @@ bool loadFileConfigSecurity()
systemCfg.fwIp.fromString(doc[fwIpKey] | "0.0.0.0");

configFile.close();
LOGI(tag, "%s %s", configFileSecurity, msg_file_rm);
LOGD("%s %s", configFileSecurity, msg_file_rm);
saveSystemConfig(systemCfg);
LittleFS.remove(configFileSecurity);
return true;
Expand All @@ -1117,7 +1123,7 @@ bool loadFileConfigSerial()
File configFile = LittleFS.open(configFileSerial, FILE_READ);
if (!configFile)
{
LOGI(tag, "%s %s", configFileSerial, msg_open_f);
LOGD("%s %s", configFileSerial, msg_open_f);
return false;
}

Expand All @@ -1135,7 +1141,7 @@ bool loadFileConfigSerial()
systemCfg.socketPort = (int)doc[portKey];

configFile.close();
LOGI(tag, "%s %s", configFileSerial, msg_file_rm);
LOGD("%s %s", configFileSerial, msg_file_rm);
saveSystemConfig(systemCfg);
LittleFS.remove(configFileSerial);
return true;
Expand All @@ -1148,7 +1154,7 @@ bool loadFileConfigMqtt()
File configFile = LittleFS.open(configFileMqtt, FILE_READ);
if (!configFile)
{
LOGI(tag, "%s %s", configFileMqtt, msg_open_f);
LOGD("%s %s", configFileMqtt, msg_open_f);
return false;
}

Expand All @@ -1170,9 +1176,10 @@ bool loadFileConfigMqtt()
strlcpy(mqttCfg.topic, doc[topicKey] | "", sizeof(mqttCfg.topic));
mqttCfg.updateInt = (int)doc[intervalKey];
mqttCfg.discovery = (int)doc[discoveryKey];
mqttCfg.reconnectInt = (int)doc[reconnectIntKey];

configFile.close();
LOGI(tag, "%s %s", configFileMqtt, msg_file_rm);
LOGD("%s %s", configFileMqtt, msg_file_rm);
saveMqttConfig(mqttCfg);
LittleFS.remove(configFileMqtt);
return true;
Expand All @@ -1191,7 +1198,7 @@ bool loadFileConfigWg()
File configFile = LittleFS.open(configFileWg, FILE_READ);
if (!configFile)
{
LOGI(tag, "%s %s", configFileWg, msg_open_f);
LOGD("%s %s", configFileWg, msg_open_f);
return false;
}

Expand All @@ -1215,7 +1222,7 @@ bool loadFileConfigWg()
vpnCfg.wgEndPort = (int)doc[endPort];

configFile.close();
LOGI(tag, "%s %s", configFileWg, msg_file_rm);
LOGD("%s %s", configFileWg, msg_file_rm);
saveVpnConfig(vpnCfg);
LittleFS.remove(configFileWg);
return true;
Expand Down
Loading

0 comments on commit 1553999

Please sign in to comment.