From 0011339aa7a3ac62ee14bcb1b0640226c99c5fc7 Mon Sep 17 00:00:00 2001
From: Zoe Pfister <zoe.pfister@uibk.ac.at>
Date: Mon, 30 Jan 2023 11:22:31 +0100
Subject: [PATCH] Minor changes as suggested by markus

---
 host/host_central_mast/src/main.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/host/host_central_mast/src/main.cpp b/host/host_central_mast/src/main.cpp
index 042d4e6..db4e69d 100644
--- a/host/host_central_mast/src/main.cpp
+++ b/host/host_central_mast/src/main.cpp
@@ -60,11 +60,8 @@ void on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status) {
 }
 
 void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len) {
+
     esp_log_write(ESP_LOG_INFO, TAG_ESPNOW, "Message received\n");
-    // copy received data to a char array
-    char data[len];
-    memcpy(data, incomingData, len);
-    esp_log_write(ESP_LOG_DEBUG, TAG_ESPNOW, "Raw received Data: %s\n", data);
 
     if (!esp_now_is_peer_exist(mac)) {
         esp_now_peer_info_t client = {};
@@ -86,6 +83,10 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len) {
     esp_err_t success = esp_now_send(mac, (uint8_t *)&response, sizeof(response));
     esp_log_write(ESP_LOG_DEBUG, TAG_ESPNOW, (success == ESP_OK) ? "Response sent\n" : "Failed to respond\n");
 
+    char data[len];
+    memcpy(data, incomingData, len);
+    esp_log_write(ESP_LOG_DEBUG, TAG_ESPNOW, "Raw received Data: %s\n", data);
+
     DynamicJsonDocument doc = parseReceivedJsonData(data);
 
     String macAddress = getMacAddressAsString(mac);
-- 
GitLab