Skip to content
Snippets Groups Projects
Commit c28745c4 authored by Moritz Perschke's avatar Moritz Perschke
Browse files

added time sync #7 and timestamping of message

parent 4f6a78ea
No related branches found
No related tags found
5 merge requests!39Merge Develop into Main,!19development into master,!17Inital Host, initial Client,!3Merge Branch `develop` into `sensor_readout`,!1Espnow
#include <esp_now.h> #include <esp_now.h>
#include <Preferences.h> #include <Preferences.h>
#include <ESP32Time.h>
#include "WiFi.h" #include "WiFi.h"
#include "espnow.hpp" #include "espnow.hpp"
...@@ -7,6 +8,7 @@ uint8_t BROADCAST_MAC[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // leaving this ...@@ -7,6 +8,7 @@ uint8_t BROADCAST_MAC[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // leaving this
bool host_defined = false; bool host_defined = false;
esp_now_peer_info_t hostInfo; esp_now_peer_info_t hostInfo;
Preferences preferences; Preferences preferences;
ESP32Time rtc(7200);
void on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status){ void on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status){
// go to sleep // go to sleep
...@@ -23,6 +25,7 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len){ ...@@ -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 }// host change shouldn't be an issue
preferences.end(); preferences.end();
// sync time // 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){ ...@@ -69,6 +72,7 @@ void Message::add_data(float value, int identifier){
if(data->timestamp == 0){ if(data->timestamp == 0){
//add timestamp //add timestamp
data->timestamp = rtc.getMillis();
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment