FAR nicer logging
Some checks failed
Test compiling project / test (push) Failing after 2m14s

This commit is contained in:
2025-03-20 22:33:22 +01:00
parent 9064d3cd01
commit 2fa4b0761b
8 changed files with 98 additions and 81 deletions

View File

@@ -4,6 +4,7 @@
#include "../global_data/defines.h"
#include <Preferences.h>
#include "../global_data/global_data.h"
#include <tools/log.h>
int64_t mac_address = ESP.getEfuseMac();
uint8_t failed_connection_attempts = 0;
@@ -34,21 +35,21 @@ const char * get_hostname(HostnameType host_type) {
void wifi_task(void* parameter)
{
logger.log(0, DEBUG, "Starting WiFi Task");
LOG(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) {
logger.log(0, DEBUG, "Failed to connecto to currently saved SSID, starting SoftAP");
LOG(DEBUG, "Failed to connecto to currently saved SSID, starting SoftAP");
} else {
logger.log(0, DEBUG, "No SSID saved, starting SoftAP");
LOG(DEBUG, "No SSID saved, starting SoftAP");
}
String ap_ssid = get_hostname(Wireless);
WiFi.softAP(ap_ssid, "");
logger.log(0, DEBUG, "[WIFI_TASK] Waiting for SSID now...");
LOG(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) {
@@ -64,11 +65,11 @@ void wifi_task(void* parameter)
wifi_data.network_name = WiFi.SSID();
wifi_data.ip_address = WiFi.localIP().toString();
// logger.log(0, DEBUG, "RSSI: %F, IP Address, %p, SSID: %s", float(WiFi.RSSI()), WiFi.localIP(), prefs.getString(ssid_key, "NOSSID"));
// LOG(DEBUG, "RSSI: %F, IP Address, %p, SSID: %s", float(WiFi.RSSI()), WiFi.localIP(), prefs.getString(ssid_key, "NOSSID"));
// Serial.println(WiFi.channel());
delay(5000);
} else {
logger.log(0, DEBUG, "Connecting to %s using password %s", prefs.getString(ssid_key, ""), prefs.getString(wifi_password_key, ""));
LOG(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, ""));
failed_connection_attempts++;
@@ -80,14 +81,14 @@ void wifi_task(void* parameter)
void ethernet_task(void* parameter)
{
logger.log(0, DEBUG, "Connecting Ethernet");
LOG(DEBUG, "Connecting Ethernet");
ETH.begin(0, 17, 23, 18);
ETH.setHostname(get_hostname(Ethernet));
while (true) {
ethernet_data.link = ETH.linkUp();
ethernet_data.rssi = ETH.linkSpeed();
ethernet_data.ip_address = ETH.localIP().toString();
// logger.log(0, DEBUG, "Ethernet RSSI: %F, IP Address, %s, LINK: %s", float(ethernet_data.rssi), ethernet_data.ip_address, String(ethernet_data.link));
// LOG(DEBUG, "Ethernet RSSI: %F, IP Address, %s, LINK: %s", float(ethernet_data.rssi), ethernet_data.ip_address, String(ethernet_data.link));
delay(60 * 1000);
}
}