Skip to content

Commit

Permalink
feat(RMaker): Register common events for better debugging (espressif#…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
P-R-O-C-H-Y and pre-commit-ci-lite[bot] authored Aug 13, 2024
1 parent d3f5b9b commit 49d9b06
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libraries/RainMaker/src/RMaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <esp_rmaker_schedule.h>
#include <esp_rmaker_utils.h>
#include <esp_rmaker_scenes.h>
#include <esp_rmaker_common_events.h>
bool wifiLowLevelInit(bool persistent);
static esp_err_t err;

Expand All @@ -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 *)"";
Expand All @@ -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");
Expand Down

0 comments on commit 49d9b06

Please sign in to comment.