From c28745c4398ad7ff2e92cf201b3a0367c0a2466b Mon Sep 17 00:00:00 2001 From: Moritz Perschke <moritz.perschke@uibk.ac.at> Date: Fri, 29 Jul 2022 16:13:25 +0200 Subject: [PATCH] added time sync #7 and timestamping of message --- client/client/lib/espnow/src/espnow.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/client/lib/espnow/src/espnow.cpp b/client/client/lib/espnow/src/espnow.cpp index d21e50b..e539742 100644 --- a/client/client/lib/espnow/src/espnow.cpp +++ b/client/client/lib/espnow/src/espnow.cpp @@ -1,5 +1,6 @@ #include <esp_now.h> #include <Preferences.h> +#include <ESP32Time.h> #include "WiFi.h" #include "espnow.hpp" @@ -7,6 +8,7 @@ uint8_t BROADCAST_MAC[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // leaving this bool host_defined = false; esp_now_peer_info_t hostInfo; Preferences preferences; +ESP32Time rtc(7200); void on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status){ // go to sleep @@ -23,6 +25,7 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len){ }// host change shouldn't be an issue preferences.end(); // sync time + rtc.setTime(new_config.time_millis); // see https://www.esp32.com/viewtopic.php?t=9965, maybe this needs an offset } @@ -69,6 +72,7 @@ void Message::add_data(float value, int identifier){ if(data->timestamp == 0){ //add timestamp + data->timestamp = rtc.getMillis(); } } -- GitLab