added proper hostname
All checks were successful
Test compiling project / test (push) Successful in 1m43s

This commit is contained in:
2024-11-14 23:15:43 +01:00
parent 57a6e041a5
commit ec332c5f76
2 changed files with 25 additions and 6 deletions

View File

@@ -18,8 +18,6 @@ lib_deps =
robtillaart/INA226@^0.4.4
bblanchon/ArduinoJson@^6.21.3
ArduinoLog
upload_protocol = espota
upload_port = 192.168.5.181
lib_extra_dirs = libs
lib_extra_dirs = libs

View File

@@ -12,9 +12,30 @@ extern NetworkData wifi_data;
extern NetworkData ethernet_data;
extern Preferences prefs;
enum HostnameType {
Wireless,
Ethernet,
Generic
};
const char * get_hostname(HostnameType host_type) {
String default_hostname = "Waterlevel-" + String(mac_address, HEX);
String hostname = prefs.getString("hostname", default_hostname);
switch (host_type)
{
case Wireless:
return (hostname + "-wl").c_str();
case Ethernet:
return (hostname + "-eth").c_str();
case Generic:
return hostname.c_str();
}
}
void wifi_task(void* parameter)
{
Log.verbose("Starting WiFi Task");
WiFi.setHostname(get_hostname(Wireless));
while (true) {
if (prefs.getString(ssid_key, "") == "" || failed_connection_attempts > 5) {
wifi_data.link = false;
@@ -24,7 +45,7 @@ void wifi_task(void* parameter)
Log.verbose("No SSID saved, starting SoftAP");
}
String ap_ssid = "Watermeter-" + String(mac_address);
String ap_ssid = get_hostname(Wireless);
WiFi.softAP(ap_ssid, "");
Log.verbose("[WIFI_TASK] Waiting for SSID now...");
@@ -60,11 +81,11 @@ void ethernet_task(void* parameter)
{
Log.verbose("Connecting Ethernet");
ETH.begin(0, 17, 23, 18);
ETH.setHostname("watermeter");
ETH.setHostname(get_hostname(Ethernet));
while (true) {
ethernet_data.link = ETH.linkUp();
ethernet_data.rssi = ETH.linkSpeed();
ethernet_data.ip_address = ETH.localIP().toString();
delay(60 * 1000);
}
}
}