esp_garden git · master
Distributed ESP sensor and actuator system (garden)
C++ 70.7% Markdown 18% C 10.7%git clone https://git.christianimmanuel.de/embedded/esp_garden.gitwget https://git.christianimmanuel.de/embedded/esp_garden/archive/esp_garden.tar.gzUpdate error messages
client_sensor/main/ClientSensor.cpp | 61 +++++++++++++++++++------------------ client_sensor/main/main.cpp | 2 +- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/client_sensor/main/ClientSensor.cpp b/client_sensor/main/ClientSensor.cpp index 77df38f..64f86d0 100644 --- a/client_sensor/main/ClientSensor.cpp +++ b/client_sensor/main/ClientSensor.cpp @@ -133,7 +133,7 @@ bool load_SensorConfigs() { nvs_handle_t handle; esp_err_t err = nvs_open("sensors", NVS_READONLY, &handle); if (err != ESP_OK) { - ESP_LOGI(TAG, "Failed to open NVS namespace: %d", err); + ESP_LOGE(TAG, "Failed to open NVS namespace: %d", err); return false; } @@ -145,7 +145,7 @@ bool load_SensorConfigs() { nvs_close(handle); return true; } else { - ESP_LOGI(TAG, "No valid stored config found."); + ESP_LOGE(TAG, "No valid stored config found."); nvs_close(handle); return false; } @@ -159,14 +159,14 @@ void save_SensorConfigs() { nvs_handle_t handle; esp_err_t err = nvs_open("sensors", NVS_READWRITE, &handle); if (err != ESP_OK) { - ESP_LOGI(TAG, "Failed to open NVS namespace: %d", err); + ESP_LOGE(TAG, "Failed to open NVS namespace: %d", err); return; } size_t sc_size = SENSOR_CONFIG_COUNT * sizeof(SensorConfig_s); err = nvs_set_blob(handle, "configs", sensor_configs, sc_size); if (err != ESP_OK) { - ESP_LOGI(TAG, "Failed to write blob to NVS: %d", err); + ESP_LOGE(TAG, "Failed to write blob to NVS: %d", err); } else { nvs_commit(handle); ESP_LOGI(TAG, "Save complete."); @@ -183,7 +183,7 @@ void restore_SensorConfigs() { if (load_SensorConfigs()) { ESP_LOGI(TAG, "Sensor configs restored from flash."); } else { - ESP_LOGI(TAG, "No stored configs found, using defaults."); + ESP_LOGE(TAG, "No stored configs found, using defaults."); for (size_t i = 0; i < SENSOR_CONFIG_COUNT; i++) { memcpy(sensor_configs[i].pump_mac, PEER_PUMP, 6); } @@ -204,7 +204,7 @@ void on_DataSent(const wifi_tx_info_t* info, esp_now_send_status_t status) { if (status == ESP_NOW_SEND_SUCCESS) ESP_LOGI(TAG, " queued successfully"); else - ESP_LOGI(TAG, " failed to queue!"); + ESP_LOGE(TAG, " failed to queue!"); } void on_DataRecv(const esp_now_recv_info *info, const uint8_t *data, int len) { @@ -216,7 +216,7 @@ void on_DataRecv(const esp_now_recv_info *info, const uint8_t *data, int len) { const uint8_t *src = info->src_addr; if (memcmp(src, PEER_SERVER, 6) == 0) { - ESP_LOGI(TAG, "Ignoring message: unknown sender"); + ESP_LOGW(TAG, "Ignoring message: unknown sender"); return; } @@ -258,7 +258,7 @@ void on_DataRecvResponse(const esp_now_recv_info *info, const uint8_t *data, int } if (!from_server && !from_pump) { - ESP_LOGI(TAG, "Ignoring message: unknown sender"); + ESP_LOGW(TAG, "Ignoring message: unknown sender"); return; } @@ -275,6 +275,8 @@ void on_DataRecvResponse(const esp_now_recv_info *info, const uint8_t *data, int response_received = true; ESP_LOGI(TAG, "Setting send_response_process_complete to TRUE"); send_response_process_complete = true; + } else { + ESP_LOGW(TAG, "Unrecognized message"); } return; } @@ -329,7 +331,7 @@ void print_AllPeers() { esp_now_peer_num_t peerCount; esp_err_t res = esp_now_get_peer_num(&peerCount); if (res != ESP_OK) { - ESP_LOGI(TAG, "Failed to get peer count"); + ESP_LOGE(TAG, "Failed to get peer count"); return; } @@ -342,7 +344,7 @@ void print_AllPeers() { ESP_LOGI(TAG, "Peer %d: ", i); printMac(peerInfo.peer_addr); } else { - ESP_LOGI(TAG, "Failed to fetch peer %d", i); + ESP_LOGE(TAG, "Failed to fetch peer %d", i); } } } @@ -351,22 +353,21 @@ void add_Peer(const uint8_t* addr, int32_t channel) { static const char *TAG = "print_AllPeers"; ESP_LOGI(TAG, "add_Peer: "); + printMac(addr); if (!addr) { - ESP_LOGI(TAG, "ERROR: null MAC address!"); + ESP_LOGE(TAG, "ERROR: null MAC address!"); return; } for (int i = 0; i < 6; i++) { if (addr[i] != 0) continue; else { - ESP_LOGI(TAG, "ERROR: MAC address is zero!"); + ESP_LOGE(TAG, "ERROR: MAC address is zero!"); return; } } - printMac(addr); if (esp_now_is_peer_exist(addr)) { ESP_LOGI(TAG, "Peer already exists, skipping:"); - printMac(addr); return; } @@ -381,9 +382,9 @@ void add_Peer(const uint8_t* addr, int32_t channel) { ESP_LOGI(TAG, "Added peer: "); printMac(addr); } else { - ESP_LOGI(TAG, "Failed to add peer: "); + ESP_LOGE(TAG, "Failed to add peer: "); printMac(addr); - ESP_LOGI(TAG, " (ESP_ERR: %d)", res); + ESP_LOGE(TAG, " (ESP_ERR: %d)", res); } } @@ -402,7 +403,7 @@ void init_EspNow() { static const char *TAG = "init_EspNow"; if (esp_now_init() != ESP_OK) { - ESP_LOGI(TAG, "ESP NOW init failed"); + ESP_LOGE(TAG, "ESP NOW init failed"); while (true); } esp_now_register_send_cb(on_DataSent); @@ -416,7 +417,7 @@ bool send_Message(const uint8_t* peer, const char* message) { printMac(peer); ESP_LOGI(TAG, " %s", message); if (!esp_now_is_peer_exist(peer)) { - ESP_LOGI(TAG, "ERROR: peer doese not exist!"); + ESP_LOGE(TAG, "ERROR: peer doese not exist!"); return false; } esp_err_t result = esp_now_send(peer, (uint8_t*)message, strlen(message)); @@ -432,7 +433,7 @@ bool send_AndWaitResponse(const uint8_t* peer, const char* message, uint32_t tim esp_now_register_recv_cb(on_DataRecvResponse); if (!send_Message(peer, message)) { - ESP_LOGI(TAG, "Failed to queue message for sending!"); + ESP_LOGE(TAG, "Failed to queue message for sending!"); return false; } @@ -442,7 +443,7 @@ bool send_AndWaitResponse(const uint8_t* peer, const char* message, uint32_t tim } if (!response_received) { - ESP_LOGI(TAG, "No Response received from "); + ESP_LOGE(TAG, "No Response received from "); printMac(peer); return false; } @@ -506,7 +507,7 @@ bool is_TimeToReadSensor(size_t config_id) { ESP_LOGI(TAG, "check is_TimeToReadSensor: %s", p.sensor_name); if (!p.is_active) { - ESP_LOGI(TAG, "Sensor is inactive!"); + ESP_LOGE(TAG, "Sensor is inactive!"); return false; } @@ -645,7 +646,7 @@ bool request_SensorConfig(const char* sensor_name) { snprintf(msg, sizeof(msg), "get_config:%s", sensor_name); if (!send_Message(server_mac, msg)) { - ESP_LOGI(TAG, "Failed to send get_config request"); + ESP_LOGE(TAG, "Failed to send get_config request"); return false; } @@ -657,12 +658,12 @@ bool request_SensorConfig(const char* sensor_name) { } if (!sensor_config_received) { - ESP_LOGI(TAG, "No config reply received (timeout)"); + ESP_LOGE(TAG, "No config reply received (timeout)"); return false; } if (strncmp(sensor_config_message, "cfg:", 4) != 0) { - ESP_LOGI(TAG, "Invalid config response: %s", sensor_config_message); + ESP_LOGE(TAG, "Invalid config response: %s", sensor_config_message); return false; } @@ -684,7 +685,7 @@ bool request_SensorConfig(const char* sensor_name) { if (count_token < 9) { - ESP_LOGI(TAG, "Incomplete config data"); + ESP_LOGE(TAG, "Incomplete config data"); return false; } @@ -697,7 +698,7 @@ bool request_SensorConfig(const char* sensor_name) { } if (!cfg) { - ESP_LOGI(TAG, "Unknown sensor name in config: %s", tokens[0]); + ESP_LOGE(TAG, "Unknown sensor name in config: %s", tokens[0]); return false; } @@ -773,7 +774,7 @@ void process_PendingSensorConfigs() { g_pending_sensor_configs_count--; save_new_configs = true; } else { - ESP_LOGI(TAG, "Config request failed repeatedly, aborting loop."); + ESP_LOGE(TAG, "Config request failed repeatedly, aborting loop."); break; } } @@ -832,7 +833,7 @@ void send_DataToPumpAndServer(size_t config_id, uint32_t value, bool shall_pump) bool reached_pump = false; if (!send_AndWaitResponse(p.pump_mac, message)) { - ESP_LOGI(TAG, "Delivery failed or peer offline!"); + ESP_LOGE(TAG, "Delivery failed or peer offline!"); send_response_process_complete = true; } else reached_pump = true; @@ -847,7 +848,7 @@ void send_DataToPumpAndServer(size_t config_id, uint32_t value, bool shall_pump) reached_pump); send_response_process_complete = false; if (!send_AndWaitResponse(PEER_SERVER, message)) { - ESP_LOGI(TAG, "Failed to get response from server!"); + ESP_LOGE(TAG, "Failed to get response from server!"); send_response_process_complete = true; } while (!send_response_process_complete) @@ -865,6 +866,6 @@ void send_NextSensorReadToPeer(const uint8_t* mac, int64_t unix_time) { ESP_LOGI(TAG, "Sending to peer: "); printMac(mac); if (!send_Message(mac, message)) { - ESP_LOGI(TAG, "Delivery failed or peer offline!"); + ESP_LOGE(TAG, "Delivery failed or peer offline!"); } } diff --git a/client_sensor/main/main.cpp b/client_sensor/main/main.cpp index 8f9fd6e..937362a 100644 --- a/client_sensor/main/main.cpp +++ b/client_sensor/main/main.cpp @@ -71,7 +71,7 @@ extern "C" void app_main(void) { ESP_LOGI(TAG, "Requesting time sync..."); if (request_TimeSync()) ESP_LOGI(TAG, "done"); - else ESP_LOGI(TAG, "failed (timeout)"); + else ESP_LOGE(TAG, "failed (timeout)"); restore_SensorConfigs();