added proper hostname
All checks were successful
Test compiling project / test (push) Successful in 1m43s
All checks were successful
Test compiling project / test (push) Successful in 1m43s
This commit is contained in:
@@ -18,8 +18,6 @@ lib_deps =
|
|||||||
robtillaart/INA226@^0.4.4
|
robtillaart/INA226@^0.4.4
|
||||||
bblanchon/ArduinoJson@^6.21.3
|
bblanchon/ArduinoJson@^6.21.3
|
||||||
ArduinoLog
|
ArduinoLog
|
||||||
|
|
||||||
upload_protocol = espota
|
upload_protocol = espota
|
||||||
upload_port = 192.168.5.181
|
upload_port = 192.168.5.181
|
||||||
|
lib_extra_dirs = libs
|
||||||
lib_extra_dirs = libs
|
|
||||||
|
|||||||
@@ -12,9 +12,30 @@ extern NetworkData wifi_data;
|
|||||||
extern NetworkData ethernet_data;
|
extern NetworkData ethernet_data;
|
||||||
extern Preferences prefs;
|
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)
|
void wifi_task(void* parameter)
|
||||||
{
|
{
|
||||||
Log.verbose("Starting WiFi Task");
|
Log.verbose("Starting WiFi Task");
|
||||||
|
WiFi.setHostname(get_hostname(Wireless));
|
||||||
while (true) {
|
while (true) {
|
||||||
if (prefs.getString(ssid_key, "") == "" || failed_connection_attempts > 5) {
|
if (prefs.getString(ssid_key, "") == "" || failed_connection_attempts > 5) {
|
||||||
wifi_data.link = false;
|
wifi_data.link = false;
|
||||||
@@ -24,7 +45,7 @@ void wifi_task(void* parameter)
|
|||||||
Log.verbose("No SSID saved, starting SoftAP");
|
Log.verbose("No SSID saved, starting SoftAP");
|
||||||
}
|
}
|
||||||
|
|
||||||
String ap_ssid = "Watermeter-" + String(mac_address);
|
String ap_ssid = get_hostname(Wireless);
|
||||||
WiFi.softAP(ap_ssid, "");
|
WiFi.softAP(ap_ssid, "");
|
||||||
|
|
||||||
Log.verbose("[WIFI_TASK] Waiting for SSID now...");
|
Log.verbose("[WIFI_TASK] Waiting for SSID now...");
|
||||||
@@ -60,11 +81,11 @@ void ethernet_task(void* parameter)
|
|||||||
{
|
{
|
||||||
Log.verbose("Connecting Ethernet");
|
Log.verbose("Connecting Ethernet");
|
||||||
ETH.begin(0, 17, 23, 18);
|
ETH.begin(0, 17, 23, 18);
|
||||||
ETH.setHostname("watermeter");
|
ETH.setHostname(get_hostname(Ethernet));
|
||||||
while (true) {
|
while (true) {
|
||||||
ethernet_data.link = ETH.linkUp();
|
ethernet_data.link = ETH.linkUp();
|
||||||
ethernet_data.rssi = ETH.linkSpeed();
|
ethernet_data.rssi = ETH.linkSpeed();
|
||||||
ethernet_data.ip_address = ETH.localIP().toString();
|
ethernet_data.ip_address = ETH.localIP().toString();
|
||||||
delay(60 * 1000);
|
delay(60 * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user