Moved a lot of global vars to queues
All checks were successful
Test project compilation / test (push) Successful in 3m52s
All checks were successful
Test project compilation / test (push) Successful in 3m52s
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <Preferences.h>
|
||||
#include "../global_data/global_data.h"
|
||||
#include <tools/log.h>
|
||||
#include "freertos/queue.h"
|
||||
|
||||
#define ETH_PHY_TYPE ETH_PHY_LAN8720
|
||||
#define ETH_PHY_ADDR 0
|
||||
@@ -18,8 +19,9 @@
|
||||
int64_t mac_address = ESP.getEfuseMac();
|
||||
uint8_t failed_connection_attempts = 0;
|
||||
|
||||
extern NetworkData wifi_data;
|
||||
extern NetworkData ethernet_data;
|
||||
NetworkData wifi_data;
|
||||
NetworkData ethernet_data;
|
||||
|
||||
extern Preferences prefs;
|
||||
|
||||
// Defines the type of connection for which the hostname should be created
|
||||
@@ -45,6 +47,14 @@ const char * get_hostname(HostnameType host_type) {
|
||||
|
||||
void wifi_task(void* parameter)
|
||||
{
|
||||
// Extract the queue handle from the task parameters
|
||||
QueueHandle_t dataQueue = (QueueHandle_t)parameter;
|
||||
if (dataQueue == NULL) {
|
||||
LOG(ELOG_LEVEL_ERROR, "Data queue is NULL");
|
||||
vTaskDelete(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
LOG(ELOG_LEVEL_DEBUG, "Starting WiFi Task");
|
||||
WiFi.setHostname(get_hostname(Wireless));
|
||||
while (true) {
|
||||
@@ -72,8 +82,21 @@ void wifi_task(void* parameter)
|
||||
failed_connection_attempts = 0;
|
||||
wifi_data.rssi = WiFi.RSSI();
|
||||
wifi_data.link = true;
|
||||
wifi_data.network_name = WiFi.SSID();
|
||||
wifi_data.ip_address = WiFi.localIP().toString();
|
||||
strncpy(wifi_data.network_name, WiFi.SSID().c_str(), sizeof(wifi_data.network_name) - 1);
|
||||
wifi_data.network_name[sizeof(wifi_data.network_name) - 1] = '\0';
|
||||
strncpy(wifi_data.ip_address, WiFi.localIP().toString().c_str(), sizeof(wifi_data.ip_address) - 1);
|
||||
wifi_data.ip_address[sizeof(wifi_data.ip_address) - 1] = '\0';
|
||||
|
||||
// Create a DataMessage for WiFi data
|
||||
DataMessage dataMessage;
|
||||
dataMessage.type = DATA_TYPE_WIFI;
|
||||
dataMessage.data.networkData = wifi_data;
|
||||
|
||||
// Send the WiFi data to the queue
|
||||
if (xQueueSend(dataQueue, &dataMessage, 0) != pdTRUE) {
|
||||
LOG(ELOG_LEVEL_ERROR, "Failed to send WiFi data to queue");
|
||||
}
|
||||
|
||||
LOG(ELOG_LEVEL_DEBUG, "WIFI connected; RSSI: %F, IP Address, %s, SSID: %s", float(WiFi.RSSI()), WiFi.localIP().toString(), prefs.getString(ssid_key, "NOSSID"));
|
||||
delay(1000 * 60);
|
||||
} else {
|
||||
@@ -92,13 +115,33 @@ void wifi_task(void* parameter)
|
||||
|
||||
void ethernet_task(void* parameter)
|
||||
{
|
||||
// Extract the queue handle from the task parameters
|
||||
QueueHandle_t dataQueue = (QueueHandle_t)parameter;
|
||||
if (dataQueue == NULL) {
|
||||
LOG(ELOG_LEVEL_ERROR, "Data queue is NULL");
|
||||
vTaskDelete(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
LOG(ELOG_LEVEL_DEBUG, "Starting Ethernet Task");
|
||||
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();
|
||||
strncpy(ethernet_data.ip_address, ETH.localIP().toString().c_str(), sizeof(ethernet_data.ip_address) - 1);
|
||||
ethernet_data.ip_address[sizeof(ethernet_data.ip_address) - 1] = '\0';
|
||||
|
||||
// Create a DataMessage for Ethernet data
|
||||
DataMessage dataMessage;
|
||||
dataMessage.type = DATA_TYPE_ETHERNET;
|
||||
dataMessage.data.networkData = ethernet_data;
|
||||
|
||||
// Send the Ethernet data to the queue
|
||||
if (xQueueSend(dataQueue, &dataMessage, 0) != pdTRUE) {
|
||||
LOG(ELOG_LEVEL_ERROR, "Failed to send Ethernet data to queue");
|
||||
}
|
||||
|
||||
LOG(ELOG_LEVEL_DEBUG, "Ethernet RSSI: %F, IP Address, %s, LINK: %s", float(ethernet_data.rssi), ETH.localIP().toString(), String(ethernet_data.link));
|
||||
|
||||
if (ETH.linkUp() && !ETH.isDefault() && ETH.localIP().toString() != "0.0.0.0") {
|
||||
|
||||
Reference in New Issue
Block a user