Skip to content

Commit

Permalink
20240607
Browse files Browse the repository at this point in the history
### Zigbee Updates
- Add Zigbee role on root page and MQTT
- Display saved Zigbee version if unable to detect the installed version (Web UI and MQTT)
- Add check for available Zigbee updates
- Fix Zigbee version detection after Zigbee firmware update
- Add **automatic change of baud rate** after installing new Zigbee firmware
- Add NV parameters for last installed Zigbee firmware version and role
- Add MQTT sensor for Zigbee update availability
- HTTP API command to update Zigbee firmware now uses the role and gets the latest firmware from GitHub
- Remove Zigbee firmware check during boot if not in coordinator role

### General Improvements
- Add Wi-Fi mode and TX power options to configure on the network page
- Revert Wi-Fi RSSI bar. Lower values are green (better), higher values are red (worse)
- Add tooltips for any element with a title attribute (currently only on General and MQTT pages)
- Set Debug tab cards width to 100%
- Rework DNS check and restore to avoid saving every time
- Remove cron-based DNS check and restore, only before HTTP, MQTT, WG actions Fix #11, #24, #42, #43 ?
- Fix **MQTT Discovery** option. No more publications to **/homeassistant/** if disabled
- Attempt to fix memory leak during long events
- Remove in-browser JS-based ESP update check availability

### Hardware Support
- Remove alternative power pin from ETH config, as it is deprecated
- Fix some UZG-01 v0.5 boards not starting ETH. Fix #44 ?
- Add support for HamGeek POE Plus board. Thanks @radioelf 🥇 Done #50 *(Still no ability to select, if more than one same board configs)*
- Add support for SLS board. Thanks t.me/Novgorod73 *(Still no ability to select, if more than one same board configs)*
  • Loading branch information
xyzroe committed Jun 6, 2024
1 parent 9859ee8 commit 2550e56
Show file tree
Hide file tree
Showing 35 changed files with 1,283 additions and 382 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# XZG Firmware
<div align="center">
<a href="https://github.com/xyzroe/xzg/releases"><img src="https://img.shields.io/github/release/xyzroe/xzg.svg" alt="GitHub version"></img></a>
<a href="https://github.com/xyzroe/XZG/releases"><img src="https://img.shields.io/github/release/xyzroe/xzg.svg" alt="GitHub version"></img></a>
<a href="https://github.com/xyzroe/XZG/actions/workflows/build_fw.yml"><img src="https://img.shields.io/github/actions/workflow/status/xyzroe/XZG/build_fw.yml" alt="GitHub Actions Workflow Status"></img></a>
<a href="https://github.com/xyzroe/xzg/releases/latest"><img src="https://img.shields.io/github/downloads/xyzroe/xzg/total.svg" alt="GitHub download"></img></a>
<a href="https://github.com/xyzroe/XZG/releases/latest"><img src="https://img.shields.io/github/downloads/xyzroe/XZG/total.svg" alt="GitHub download"></img></a>
<a href="https://github.com/xyzroe/XZG/issues"><img src="https://img.shields.io/github/issues/xyzroe/XZG" alt="GitHub Issues or Pull Requests"></img></a>
<a href="LICENSE"><img src="https://img.shields.io/github/license/xyzroe/xzg.svg" alt="License"></img></a>
</div>
Expand Down
12 changes: 0 additions & 12 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

;It was difficult to find working platform for https get function on solo board. Here are some logs:
;https://github.com/tasmota/platform-espressif32/releases/download/v2.0.5/platform-espressif32-2.0.5.zip ;- old build. - unkown board
;https://github.com/tasmota/platform-espressif32/releases/download/2023.01.00/platform-espressif32.zip ; fuck yeaar. it works on solo
;https://github.com/tasmota/platform-espressif32/releases/download/2023.07.00/platform-espressif32.zip ; fuck yeaar. it also works on solo
;https://github.com/tasmota/platform-espressif32/releases/download/2023.08.00/platform-espressif32.zip ; bitch. did't work -1
;https://github.com/tasmota/platform-espressif32/releases/download/2023.10.01/platform-espressif32.zip ;- build but -1
;https://github.com/tasmota/platform-espressif32/releases/download/2023.10.03/platform-espressif32.zip ;- last builds version but -1
;https://github.com/tasmota/platform-espressif32/releases/download/2023.10.05/platform-espressif32.zip ;- WiFiClientSecure.h: No such file or directory
;https://github.com/tasmota/platform-espressif32/releases/download/2023.10.10/platform-espressif32.zip ; - logs2.txt
;espressif32 @ ^6.4.0 ;- unkown board
;espressif32 @ 5.1.0 ; - works but no solo

[platformio]
default_envs = prod-solo

Expand Down
76 changes: 67 additions & 9 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ void saveNetworkConfig(const NetworkConfigStruct &config)
preferences.putString(wifiGateKey, config.wifiGate.toString());
preferences.putString(wifiDns1Key, config.wifiDns1.toString());
preferences.putString(wifiDns2Key, config.wifiDns2.toString());
preferences.putInt(wifiPwrKey, static_cast<int>(config.wifiPower));
preferences.putInt(wifiModeKey, config.wifiMode);

preferences.putBool(ethEnblKey, config.ethEnable);
preferences.putBool(ethDhcpKey, config.ethDhcp);
Expand All @@ -151,6 +153,9 @@ void loadNetworkConfig(NetworkConfigStruct &config)
config.wifiDns1.fromString(preferences.getString(wifiDns1Key, DNS_SERV_1));
config.wifiDns2.fromString(preferences.getString(wifiDns2Key, DNS_SERV_2));

config.wifiPower = static_cast<wifi_power_t>(preferences.getInt(wifiPwrKey, WIFI_POWER_19_5dBm));
config.wifiMode = preferences.getInt(wifiModeKey, WIFI_PROTOCOL_11B);

config.ethEnable = preferences.getBool(ethEnblKey, true);
config.ethDhcp = preferences.getBool(ethDhcpKey, true);
config.ethIp.fromString(preferences.getString(ethIpKey));
Expand Down Expand Up @@ -260,7 +265,7 @@ void saveSystemConfig(const SystemConfigStruct &config)
{
preferences.begin(systemConfigKey, false);

//preferences.putBool(keepWebKey, config.keepWeb);
// preferences.putBool(keepWebKey, config.keepWeb);
preferences.putBool(disableWebKey, config.disableWeb);
preferences.putBool(webAuthKey, config.webAuth);
preferences.putString(webUserKey, config.webUser);
Expand All @@ -283,14 +288,21 @@ void saveSystemConfig(const SystemConfigStruct &config)
// preferences.putInt(prevWorkModeKey, static_cast<int>(config.prevWorkMode));
preferences.putInt(workModeKey, static_cast<int>(config.workMode));

preferences.putInt(zbRoleKey, static_cast<int>(config.zbRole));
preferences.putString(zbFwKey, config.zbFw);

preferences.putString(updCheckTimeKey, config.updCheckTime);
preferences.putString(updCheckDayKey, config.updCheckDay);
preferences.putBool(updAutoInstKey, config.updAutoInst);

preferences.end();
}

void loadSystemConfig(SystemConfigStruct &config)
{
preferences.begin(systemConfigKey, true);

//config.keepWeb = preferences.getBool(keepWebKey, true);
// config.keepWeb = preferences.getBool(keepWebKey, true);
config.disableWeb = preferences.getBool(disableWebKey, false);
config.webAuth = preferences.getBool(webAuthKey, false);
strlcpy(config.webUser, preferences.getString(webUserKey, "").c_str(), sizeof(config.webUser));
Expand All @@ -315,6 +327,13 @@ void loadSystemConfig(SystemConfigStruct &config)
// config.prevWorkMode = static_cast<WORK_MODE_t>(preferences.getInt(prevWorkModeKey, WORK_MODE_NETWORK));
config.workMode = static_cast<WORK_MODE_t>(preferences.getInt(workModeKey, WORK_MODE_NETWORK));

config.zbRole = static_cast<ZB_ROLE_t>(preferences.getInt(zbRoleKey, UNDEFINED));
strlcpy(config.zbFw, preferences.getString(zbFwKey, "?").c_str(), sizeof(config.zbFw));

strlcpy(config.updCheckTime, preferences.getString(updCheckTimeKey, UPD_CHK_TIME).c_str(), sizeof(config.updCheckTime));
strlcpy(config.updCheckDay, preferences.getString(updCheckDayKey, UPD_CHK_DAY).c_str(), sizeof(config.updCheckDay));
config.updAutoInst = preferences.getBool(updAutoInstKey, false);

preferences.end();
}

Expand Down Expand Up @@ -398,19 +417,33 @@ void updateConfiguration(WebServer &serverWeb, SystemConfigStruct &configSys, Ne

if (serverWeb.hasArg(nmStartHourKey))
{
LOGD("nmStartHourKey %s", String(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))
{
LOGD("nmEndHourKey %s", String(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
}

if (serverWeb.hasArg(updCheckTimeKey))
{
strncpy(configSys.updCheckTime, serverWeb.arg(updCheckTimeKey).c_str(), sizeof(configSys.updCheckTime) - 1);
configSys.updCheckTime[sizeof(configSys.updCheckTime) - 1] = '\0'; // Guarantee a null terminator at the end
}

if (serverWeb.hasArg(updCheckDayKey))
{
strncpy(configSys.updCheckDay, serverWeb.arg(updCheckDayKey).c_str(), sizeof(configSys.updCheckDay) - 1);
configSys.updCheckDay[sizeof(configSys.updCheckDay) - 1] = '\0'; // Guarantee a null terminator at the end
}

configSys.updAutoInst = serverWeb.hasArg(updAutoInstKey) == true;

saveSystemConfig(configSys);
}
break;
Expand Down Expand Up @@ -449,6 +482,16 @@ void updateConfiguration(WebServer &serverWeb, SystemConfigStruct &configSys, Ne

configNet.wifiDhcp = serverWeb.hasArg(wifiDhcpKey) == true;

if (serverWeb.hasArg(wifiModeKey))
{
configNet.wifiMode = serverWeb.arg(wifiModeKey).toInt();
}
if (serverWeb.hasArg(wifiPwrKey))
{
const uint8_t pwr = serverWeb.arg(wifiPwrKey).toInt();
configNet.wifiPower = static_cast<wifi_power_t>(pwr);
}

if (serverWeb.arg(wifiSsidKey))
{
strncpy(configNet.wifiSsid, serverWeb.arg(wifiSsidKey).c_str(), sizeof(configNet.wifiSsid) - 1);
Expand Down Expand Up @@ -709,6 +752,8 @@ void serializeNetworkConfigToJson(const NetworkConfigStruct &config, JsonObject
obj[wifiGateKey] = config.wifiGate.toString();
obj[wifiDns1Key] = config.wifiDns1.toString();
obj[wifiDns2Key] = config.wifiDns2.toString();
obj[wifiPwrKey] = config.wifiPower;
obj[wifiModeKey] = config.wifiMode;
obj[ethEnblKey] = config.ethEnable;
obj[ethDhcpKey] = config.ethDhcp;
obj[ethIpKey] = config.ethIp.toString();
Expand Down Expand Up @@ -761,7 +806,7 @@ void serializeMqttConfigToJson(const MqttConfigStruct &config, JsonObject obj)
// Serialization SystemConfigStruct into JSON
void serializeSystemConfigToJson(const SystemConfigStruct &config, JsonObject obj)
{
//obj[keepWebKey] = config.keepWeb;
// obj[keepWebKey] = config.keepWeb;
obj[disableWebKey] = config.disableWeb;
obj[webAuthKey] = config.webAuth;
obj[webUserKey] = config.webUser;
Expand All @@ -783,6 +828,13 @@ void serializeSystemConfigToJson(const SystemConfigStruct &config, JsonObject ob
obj[nmEndHourKey] = config.nmEnd;
// obj[prevWorkModeKey] = static_cast<int>(config.prevWorkMode);
obj[workModeKey] = static_cast<int>(config.workMode);

obj[zbRoleKey] = static_cast<int>(config.zbRole);
obj[zbFwKey] = config.zbFw;

obj[updCheckTimeKey] = config.updCheckTime;
obj[updCheckDayKey] = config.updCheckDay;
obj[updAutoInstKey] = config.updAutoInst;
}

// Serializing system variables to JSON
Expand All @@ -791,7 +843,7 @@ void serializeSysVarsToJson(const SysVarsStruct &vars, JsonObject obj)
obj[hwBtnIsKey] = vars.hwBtnIs;
obj[hwLedUsbIsKey] = vars.hwLedUsbIs;
obj[hwLedPwrIsKey] = vars.hwLedPwrIs;
//obj[hwUartSelIsKey] = vars.hwUartSelIs;
// obj[hwUartSelIsKey] = vars.hwUartSelIs;
obj[hwZigbeeIsKey] = vars.hwZigbeeIs;

obj[connectedClientsKey] = vars.connectedClients;
Expand All @@ -815,6 +867,9 @@ void serializeSysVarsToJson(const SysVarsStruct &vars, JsonObject obj)
// obj[zbFlashingKey] = vars.zbFlashing;

obj[deviceIdKey] = vars.deviceId;

obj[espUpdAvailKey] = vars.updateEspAvail;
obj[zbUpdAvailKey] = vars.updateZbAvail;
}

bool loadFileConfigHW()
Expand Down Expand Up @@ -862,7 +917,10 @@ bool loadFileConfigHW()
hwConfig.eth.mdiPin = config[mdiPin];
hwConfig.eth.phyType = config[phyType];
hwConfig.eth.clkMode = config[clkMode];
hwConfig.eth.pwrAltPin = config[pwrAltPin];
if (hwConfig.eth.pwrPin == -1) {
hwConfig.eth.pwrPin = config[pwrAltPin];
}
//hwConfig.eth.pwrAltPin = config[pwrAltPin];
hwConfig.mist.btnPin = config[btnPin];
hwConfig.mist.btnPlr = config[btnPlr];
hwConfig.mist.uartSelPin = config[uartSelPin];
Expand Down Expand Up @@ -903,7 +961,7 @@ bool loadFileConfigHW()
config[mdiPin] = newConfig->eth.mdiPin;
config[phyType] = newConfig->eth.phyType;
config[clkMode] = newConfig->eth.clkMode;
config[pwrAltPin] = newConfig->eth.pwrAltPin;
//config[pwrAltPin] = newConfig->eth.pwrAltPin;
config[btnPin] = newConfig->mist.btnPin;
config[btnPlr] = newConfig->mist.btnPlr;
config[uartSelPin] = newConfig->mist.uartSelPin;
Expand Down Expand Up @@ -1097,7 +1155,7 @@ bool loadFileConfigGeneral()
systemCfg.disableLedPwr = (uint8_t)doc[disableLedPwrKey];
systemCfg.disableLedUSB = (uint8_t)doc[disableLedUSBKey];
vars.disableLeds = (uint8_t)doc[disableLedsKey];
//systemCfg.keepWeb = (uint8_t)doc[keepWebKey];
// systemCfg.keepWeb = (uint8_t)doc[keepWebKey];
strlcpy(systemCfg.timeZone, doc[timeZoneKey] | NTP_TIME_ZONE, sizeof(systemCfg.timeZone));

configFile.close();
Expand Down
59 changes: 42 additions & 17 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#define ZB_TCP_PORT 6638 // any port ever. later setup from config file
#define ZB_SERIAL_SPEED 115200
#define NTP_TIME_ZONE "Europe/Kiev"
#define NTP_TIME_ZONE "Europe/Berlin"
#define NTP_SERV_1 "pool.ntp.org"
#define NTP_SERV_2 "time.google.com"
#define DNS_SERV_1 "1.1.1.1"
Expand All @@ -23,6 +23,8 @@
#define NETWORK_ZERO "0.0.0.0"
#define NM_START_TIME "23:00"
#define NM_END_TIME "07:00"
#define UPD_CHK_TIME "01:00"
#define UPD_CHK_DAY "*"

#define MAX_SOCKET_CLIENTS 5

Expand Down Expand Up @@ -50,6 +52,14 @@ enum LED_t : uint8_t
ZB_LED
};

enum ZB_ROLE_t : uint8_t
{
UNDEFINED,
COORDINATOR,
ROUTER,
OPENTHREAD
};

extern const char *coordMode; // coordMode node name
extern const char *configFileSystem;
extern const char *configFileWifi;
Expand All @@ -66,7 +76,7 @@ struct SysVarsStruct
bool hwBtnIs = false;
bool hwLedUsbIs = false;
bool hwLedPwrIs = false;
//bool hwUartSelIs = false;
// bool hwUartSelIs = false;
bool hwZigbeeIs = false;

bool connectedSocket[MAX_SOCKET_CLIENTS]; //[10]
Expand Down Expand Up @@ -95,13 +105,19 @@ struct SysVarsStruct
char deviceId[MAX_DEV_ID_LONG];

bool updateEspAvail;
bool updateZbAvail;
IPAddress savedWifiDNS;
IPAddress savedEthDNS;
};

// Network configuration structure
struct NetworkConfigStruct
{
// Wi-Fi
bool wifiEnable;
// int wifiPower;
wifi_power_t wifiPower;
int wifiMode;
char wifiSsid[50];
char wifiPass[80];
bool wifiDhcp;
Expand Down Expand Up @@ -175,7 +191,7 @@ void loadMqttConfig(MqttConfigStruct &config);

struct SystemConfigStruct
{
//bool keepWeb; // when usb mode active
// bool keepWeb; // when usb mode active

bool disableWeb; // when socket connected
bool webAuth;
Expand Down Expand Up @@ -205,7 +221,14 @@ struct SystemConfigStruct
char nmEnd[6];

// WORK_MODE_t prevWorkMode; // for button // WORK_MODE_t
WORK_MODE_t workMode; // for button // WORK_MODE_t
WORK_MODE_t workMode;

ZB_ROLE_t zbRole;
char zbFw[30];

char updCheckTime[6];
char updCheckDay[3];
bool updAutoInst;
};

// Function prototypes for SystemConfigStruct
Expand Down Expand Up @@ -297,33 +320,35 @@ uint8_t temprature_sens_read();

// Conditional logging macros
#if CURRENT_LOG_LEVEL >= LOG_LEVEL_WARN
#define LOGW(format, ...) \
if (systemCfg.workMode == WORK_MODE_NETWORK) { \
Serial.printf(ANSI_COLOR_PURPLE "%d " ANSI_COLOR_RESET ANSI_COLOR_RED "[%s] " ANSI_COLOR_RESET format "\n", millis(), __func__, ##__VA_ARGS__); \
}
#define LOGW(format, ...) \
if (systemCfg.workMode == WORK_MODE_NETWORK) \
{ \
Serial.printf(ANSI_COLOR_PURPLE "%d " ANSI_COLOR_RESET ANSI_COLOR_RED "[%s] " ANSI_COLOR_RESET format "\n", millis(), __func__, ##__VA_ARGS__); \
}
#else
#define LOGW(format, ...) // Nothing
#endif

#if CURRENT_LOG_LEVEL >= LOG_LEVEL_INFO
#define LOGI(format, ...) \
if (systemCfg.workMode == WORK_MODE_NETWORK) { \
Serial.printf(ANSI_COLOR_PURPLE "%d " ANSI_COLOR_RESET ANSI_COLOR_GREEN "[%s] " ANSI_COLOR_RESET format "\n", millis(), __func__, ##__VA_ARGS__); \
}
#define LOGI(format, ...) \
if (systemCfg.workMode == WORK_MODE_NETWORK) \
{ \
Serial.printf(ANSI_COLOR_PURPLE "%d " ANSI_COLOR_RESET ANSI_COLOR_GREEN "[%s] " ANSI_COLOR_RESET format "\n", millis(), __func__, ##__VA_ARGS__); \
}
#else
#define LOGI(format, ...) // Nothing
#endif

#if CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG
#define LOGD(format, ...) \
if (systemCfg.workMode == WORK_MODE_NETWORK) { \
Serial.printf(ANSI_COLOR_PURPLE "%d " ANSI_COLOR_RESET ANSI_COLOR_YELLOW "[%s] " ANSI_COLOR_RESET format "\n", millis(), __func__, ##__VA_ARGS__); \
}
#define LOGD(format, ...) \
if (systemCfg.workMode == WORK_MODE_NETWORK) \
{ \
Serial.printf(ANSI_COLOR_PURPLE "%d " ANSI_COLOR_RESET ANSI_COLOR_YELLOW "[%s] " ANSI_COLOR_RESET format "\n", millis(), __func__, ##__VA_ARGS__); \
}
#else
#define LOGD(format, ...) // Nothing
#endif


/* ----- Define functions | END -----*/

enum LEDMode
Expand Down
Loading

0 comments on commit 2550e56

Please sign in to comment.