Added logging

This commit is contained in:
CommanderRedYT
2021-12-29 06:19:16 +01:00
parent 351c40fce7
commit d5ebbcdd24

View File

@@ -35,19 +35,20 @@ bool receiveTsFromOtherBobbycars{true};
namespace { namespace {
extern "C" void onReceive(const uint8_t *mac_addr, const uint8_t *data, int len) extern "C" void onReceive(const uint8_t *mac_addr, const uint8_t *data, int len)
{ {
ESP_LOGI(TAG, "Received data");
const std::string message(data, data + len); const std::string message(data, data + len);
//Serial.printf("Received: %s\n", message.c_str()); ESP_LOGI(TAG, "Received data (%s)", message.c_str());
ESP_LOGI(TAG, "ID: %s - Token: %s", stringSettings.esp_now_door_id.c_str(), stringSettings.esp_now_door_token.c_str());
// Parse the message (msg format: "msg_type:msg_value:msg_token") via find and npos // Parse the message (msg format: "msg_type:msg_value:msg_token") via find and npos
const size_t pos = message.find(":"); const size_t pos = message.find(":");
if (pos == std::string::npos) { if (pos == std::string::npos) {
//Serial.println("Invalid message format"); ESP_LOGW(TAG, "Invalid message format");
return; return;
} }
const size_t pos2 = message.find(":", pos + 1); const size_t pos2 = message.find(":", pos + 1);
if (pos2 == std::string::npos) { if (pos2 == std::string::npos) {
//Serial.println("Invalid message format"); ESP_LOGW(TAG, "Invalid message format");
return; return;
} }
const std::string msg_type = message.substr(0, pos); const std::string msg_type = message.substr(0, pos);
@@ -58,12 +59,12 @@ extern "C" void onReceive(const uint8_t *mac_addr, const uint8_t *data, int len)
} }
if (msg_token.empty()) { if (msg_token.empty()) {
//Serial.println("No token was send"); ESP_LOGW(TAG, "No token was send");
return; return;
} }
if (msg_token != stringSettings.esp_now_door_token) { if (msg_token != stringSettings.esp_now_door_token) {
//Serial.println("Invalid token"); ESP_LOGW(TAG, "Invalid token (%s)", msg_token.c_str());
return; return;
} }