Updates
Some checks failed
Test compiling project / test (push) Failing after 0s

This commit is contained in:
2025-11-02 12:50:10 +01:00
parent f0e237cd71
commit 27ebbe22ac
14 changed files with 221 additions and 276 deletions

View File

@@ -1,11 +1,20 @@
#include <Elog.h>
#include <ETH.h>
#include <WiFi.h>
#include "../global_data/defines.h"
#include <Preferences.h>
#include "../global_data/global_data.h"
#include <tools/log.h>
#define ETH_PHY_TYPE ETH_PHY_LAN8720
#define ETH_PHY_ADDR 0
#define ETH_PHY_MDC 23
#define ETH_PHY_MDIO 18
#define ETH_PHY_POWER 14
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
#include <ETH.h>
int64_t mac_address = ESP.getEfuseMac();
uint8_t failed_connection_attempts = 0;
@@ -13,6 +22,7 @@ extern NetworkData wifi_data;
extern NetworkData ethernet_data;
extern Preferences prefs;
// Defines the type of connection for which the hostname should be created
enum HostnameType {
Wireless,
Ethernet,
@@ -28,28 +38,28 @@ const char * get_hostname(HostnameType host_type) {
return (hostname + "-wl").c_str();
case Ethernet:
return (hostname + "-eth").c_str();
case Generic:
default:
return hostname.c_str();
}
}
void wifi_task(void* parameter)
{
LOG(DEBUG, "Starting WiFi Task");
LOG(ELOG_LEVEL_DEBUG, "Starting WiFi Task");
WiFi.setHostname(get_hostname(Wireless));
while (true) {
if (prefs.getString(ssid_key, "") == "" || failed_connection_attempts > 5) {
wifi_data.link = false;
if (failed_connection_attempts > 5) {
LOG(DEBUG, "Failed to connecto to currently saved SSID, starting SoftAP");
LOG(ELOG_LEVEL_DEBUG, "Failed to connect to currently saved SSID, starting SoftAP");
} else {
LOG(DEBUG, "No SSID saved, starting SoftAP");
LOG(ELOG_LEVEL_DEBUG, "No SSID saved, starting SoftAP");
}
String ap_ssid = get_hostname(Wireless);
WiFi.softAP(ap_ssid, "");
WiFi.softAP(ap_ssid.c_str(), "");
LOG(DEBUG, "[WIFI_TASK] Waiting for SSID now...");
LOG(ELOG_LEVEL_DEBUG, "[WIFI_TASK] Waiting for SSID now...");
String old_ssid = prefs.getString(ssid_key, "xxx");
while (prefs.getString(ssid_key, "") == "" || prefs.getString(ssid_key, "") == old_ssid) {
@@ -65,13 +75,14 @@ void wifi_task(void* parameter)
wifi_data.network_name = WiFi.SSID();
wifi_data.ip_address = WiFi.localIP().toString();
LOG(DEBUG, "RSSI: %F, IP Address, %p, SSID: %s", float(WiFi.RSSI()), WiFi.localIP(), prefs.getString(ssid_key, "NOSSID"));
Serial.println(WiFi.channel());
LOG(ELOG_LEVEL_DEBUG, "RSSI: %F, IP Address, %s, SSID: %s", float(WiFi.RSSI()), WiFi.localIP().toString(), prefs.getString(ssid_key, "NOSSID"));
Serial.println(WiFi.localIP());
delay(5000);
} else {
LOG(DEBUG, "Connecting to %s using password %s", prefs.getString(ssid_key, ""), prefs.getString(wifi_password_key, ""));
LOG(ELOG_LEVEL_DEBUG, "Connecting to %s using password %s", prefs.getString(ssid_key, ""), prefs.getString(wifi_password_key, ""));
WiFi.mode(WIFI_STA);
WiFi.begin(prefs.getString(ssid_key, ""), prefs.getString(wifi_password_key, ""));
WiFi.begin(prefs.getString(ssid_key, "").c_str(), prefs.getString(wifi_password_key, "").c_str());
failed_connection_attempts++;
delay(5000);
}
@@ -81,15 +92,14 @@ void wifi_task(void* parameter)
void ethernet_task(void* parameter)
{
LOG(DEBUG, "Connecting Ethernet");
ETH.begin(0, 17, 23, 18);
LOG(ELOG_LEVEL_DEBUG, "Connecting Ethernet");
ETH.begin();
ETH.setHostname(get_hostname(Ethernet));
while (true) {
ethernet_data.link = ETH.linkUp();
ethernet_data.rssi = ETH.linkSpeed();
ethernet_data.ip_address = ETH.localIP().toString();
Serial.println( ETH.localIP().toString());
LOG(DEBUG, "Ethernet RSSI: %F, IP Address, %s, LINK: %s", float(ethernet_data.rssi), ETH.localIP().toString().c_str(), String(ethernet_data.link));
LOG(ELOG_LEVEL_DEBUG, "Ethernet RSSI: %F, IP Address, %s, LINK: %s", float(ethernet_data.rssi), ETH.localIP().toString(), String(ethernet_data.link));
delay(60 * 1000);
}
}