Normalize spacing in ESP32 firmware

This commit is contained in:
2025-12-09 10:04:06 +01:00
parent 4e78a5f2ed
commit eaad4469bc
3 changed files with 12 additions and 14 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ static void watchdogTask(void *pvParameters) {
ESP_ERROR_CHECK(esp_task_wdt_add(NULL)); ESP_ERROR_CHECK(esp_task_wdt_add(NULL));
for(;;) { for(;;) {
if (criticalErrorFlag) { if(criticalErrorFlag) {
ESP_LOGE(TAG, "Critical error flag raised. Rebooting."); ESP_LOGE(TAG, "Critical error flag raised. Rebooting.");
esp_restart(); esp_restart();
} }
+5 -7
View File
@@ -22,9 +22,9 @@ static void mqtt_subscribe(void) {
} }
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) { static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) {
esp_mqtt_event_handle_t event = (esp_mqtt_event_handle_t)event_data; esp_mqtt_event_handle_t event =(esp_mqtt_event_handle_t)event_data;
switch (event->event_id) { switch(event->event_id) {
case MQTT_EVENT_CONNECTED: case MQTT_EVENT_CONNECTED:
xEventGroupSetBits(connectivity_event_group, MQTT_CONNECTED_BIT); xEventGroupSetBits(connectivity_event_group, MQTT_CONNECTED_BIT);
mqtt_subscribe(); mqtt_subscribe();
@@ -41,7 +41,7 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
ESP_LOGD(TAG, "Data received"); ESP_LOGD(TAG, "Data received");
int len = event->data_len; int len = event->data_len;
if (len > sizeof(global_rx_buffer) - 1) len = sizeof(global_rx_buffer) - 1; if(len > sizeof(global_rx_buffer) - 1) len = sizeof(global_rx_buffer) - 1;
memcpy(global_rx_buffer, event->data, len); memcpy(global_rx_buffer, event->data, len);
global_rx_buffer[len] = '\0'; global_rx_buffer[len] = '\0';
@@ -96,14 +96,12 @@ void mqttTask(void *pvParameters) {
EventBits_t bits = xEventGroupGetBits(connectivity_event_group); EventBits_t bits = xEventGroupGetBits(connectivity_event_group);
if ((bits & (WIFI_CONNECTED_BIT | MQTT_CONNECTED_BIT)) == (WIFI_CONNECTED_BIT | MQTT_CONNECTED_BIT)) { if((bits &(WIFI_CONNECTED_BIT | MQTT_CONNECTED_BIT)) ==(WIFI_CONNECTED_BIT | MQTT_CONNECTED_BIT)) {
ESP_LOGV(TAG, "Connection established"); ESP_LOGV(TAG, "Connection established");
uint32_t task_notification = ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(MQTT_TASK_TIMEOUT_MS)); uint32_t task_notification = ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(MQTT_TASK_TIMEOUT_MS));
if (task_notification) {} //{twi_do(global_rx_buffer)} if(task_notification) {} //{twi_do(global_rx_buffer)}
} else { } else {
ESP_LOGW(TAG, "Waiting for connection..."); ESP_LOGW(TAG, "Waiting for connection...");
vTaskDelay(pdMS_TO_TICKS(MQTT_TASK_TIMEOUT_MS/2)); vTaskDelay(pdMS_TO_TICKS(MQTT_TASK_TIMEOUT_MS/2));
+6 -6
View File
@@ -13,15 +13,15 @@
static const char* TAG = "WIFI"; static const char* TAG = "WIFI";
static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
if (event_base == WIFI_EVENT) { if(event_base == WIFI_EVENT) {
switch (event_id) { switch(event_id) {
case WIFI_EVENT_STA_START: case WIFI_EVENT_STA_START:
ESP_LOGV(TAG, "Process started, connecting..."); ESP_LOGV(TAG, "Process started, connecting...");
esp_wifi_connect(); esp_wifi_connect();
break; break;
case WIFI_EVENT_STA_DISCONNECTED: { case WIFI_EVENT_STA_DISCONNECTED: {
wifi_event_sta_disconnected_t* disconn = (wifi_event_sta_disconnected_t*) event_data; wifi_event_sta_disconnected_t* disconn =(wifi_event_sta_disconnected_t*) event_data;
ESP_LOGW(TAG, "Disconnected, reason: %d", disconn->reason); ESP_LOGW(TAG, "Disconnected, reason: %d", disconn->reason);
xEventGroupClearBits(connectivity_event_group, WIFI_CONNECTED_BIT | MQTT_CONNECTED_BIT); xEventGroupClearBits(connectivity_event_group, WIFI_CONNECTED_BIT | MQTT_CONNECTED_BIT);
@@ -33,8 +33,8 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t e
break; break;
} }
} }
else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { else if(event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; ip_event_got_ip_t* event =(ip_event_got_ip_t*) event_data;
ESP_LOGD(TAG, "Got IP: " IPSTR, IP2STR(&event->ip_info.ip)); ESP_LOGD(TAG, "Got IP: " IPSTR, IP2STR(&event->ip_info.ip));
xEventGroupSetBits(connectivity_event_group, WIFI_CONNECTED_BIT); xEventGroupSetBits(connectivity_event_group, WIFI_CONNECTED_BIT);
@@ -44,7 +44,7 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t e
static void wifi_init_sta(void) { static void wifi_init_sta(void) {
esp_err_t nvs_err = nvs_flash_init(); esp_err_t nvs_err = nvs_flash_init();
if (nvs_err == ESP_ERR_NVS_NO_FREE_PAGES || nvs_err == ESP_ERR_NVS_NEW_VERSION_FOUND) { if(nvs_err == ESP_ERR_NVS_NO_FREE_PAGES || nvs_err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase()); ESP_ERROR_CHECK(nvs_flash_erase());
ESP_ERROR_CHECK(nvs_flash_init()); ESP_ERROR_CHECK(nvs_flash_init());
} }