From 49d9b060ca0b78c78a469df2d7ea9cb6807fa292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:30:15 +0200 Subject: [PATCH] feat(RMaker): Register common events for better debugging (#10133) * feat(rmaker): Register common events for better debugging * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- libraries/RainMaker/src/RMaker.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libraries/RainMaker/src/RMaker.cpp b/libraries/RainMaker/src/RMaker.cpp index 0cba0a4bede..0f8f276cbb9 100644 --- a/libraries/RainMaker/src/RMaker.cpp +++ b/libraries/RainMaker/src/RMaker.cpp @@ -4,6 +4,7 @@ #include #include #include +#include bool wifiLowLevelInit(bool persistent); static esp_err_t err; @@ -20,6 +21,16 @@ static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_ case RMAKER_EVENT_CLAIM_FAILED: log_i("RainMaker Claim Failed."); break; default: log_i("Unhandled RainMaker Event:"); } + } else if (event_base == RMAKER_COMMON_EVENT) { + switch (event_id) { + case RMAKER_EVENT_REBOOT: log_i("Rebooting in %d seconds.", *((uint8_t *)event_data)); break; + case RMAKER_EVENT_WIFI_RESET: log_i("Wi-Fi credentials reset."); break; + case RMAKER_EVENT_FACTORY_RESET: log_i("Node reset to factory defaults."); break; + case RMAKER_MQTT_EVENT_CONNECTED: log_i("MQTT Connected."); break; + case RMAKER_MQTT_EVENT_DISCONNECTED: log_i("MQTT Disconnected."); break; + case RMAKER_MQTT_EVENT_PUBLISHED: log_i("MQTT Published. Msg id: %d.", *((int *)event_data)); break; + default: log_w("Unhandled RainMaker Common Event: %" PRIi32, event_id); + } } else if (event_base == RMAKER_OTA_EVENT) { if (event_data == NULL) { event_data = (void *)""; @@ -46,6 +57,7 @@ Node RMakerClass::initNode(const char *name, const char *type) { esp_rmaker_node_t *rnode = NULL; esp_event_handler_register(RMAKER_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL); esp_event_handler_register(RMAKER_OTA_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL); + esp_event_handler_register(RMAKER_COMMON_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL); rnode = esp_rmaker_node_init(&rainmaker_cfg, name, type); if (!rnode) { log_e("Node init failed");