From b073705fe761fe93711e9b5af18c67d033d597c0 Mon Sep 17 00:00:00 2001
From: Moritz Perschke <moritz.perschke@uibk.ac.at>
Date: Thu, 8 Sep 2022 14:10:14 +0200
Subject: [PATCH] fipy host broadcasts its mac + timestamp on start, main
 function of client updated according to last commit

---
 client/client/src/main.cpp | 6 +++---
 host/fipy/lib/espnow.py    | 4 ++++
 host/fipy/main.py          | 3 ++-
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/client/client/src/main.cpp b/client/client/src/main.cpp
index 3f34c4f..2412091 100644
--- a/client/client/src/main.cpp
+++ b/client/client/src/main.cpp
@@ -38,17 +38,17 @@ void loop()
 	new_data.add_data(++counter * 1.1, 0);
 	new_data.add_data(counter * 1.2, 1);
 	new_data.add_data(counter * 1.3, 2);
-	new_data.send();
+	espnow_send_message(new_data);
 
 	// if(!ram_cache_is_empty()){
 	//   ClientDataPackage old_data = ram_cache_pop();
 	//   Message* resend_message = new Message(old_data);
 	//   resend_message->send();
-	//   delete resend_message;
+	//   delete resend_message;u
 	// }
 	Serial.println(esptime::rtc.getMillis());
 	Serial.println("delaying...");
 	Serial.flush();
 	delay(5000); // 5 second receive window
-	deep_sleep(900); // go to sleep for 15 mins (900s)
+	// deep_sleep(900); // go to sleep for 15 mins (900s)
 }
\ No newline at end of file
diff --git a/host/fipy/lib/espnow.py b/host/fipy/lib/espnow.py
index 6afe2a8..21f4d57 100644
--- a/host/fipy/lib/espnow.py
+++ b/host/fipy/lib/espnow.py
@@ -41,6 +41,10 @@ def espnow_recv(result):
     
     espnow_respond(mac)
 
+def espnow_broadcast_config():
+    msg = struct.pack("<6sl", self_mac, time.time())
+    ESPNOW.send(None, msg)
+
 def bytes_to_data(msg):
     # turn bytes from message into 22-tuple of integers(identifiers), floats(values), integer(amount) and long(timestamp)
     data = struct.unpack("<10i10fil", bytes(msg))
diff --git a/host/fipy/main.py b/host/fipy/main.py
index 020d027..2d0fb65 100644
--- a/host/fipy/main.py
+++ b/host/fipy/main.py
@@ -2,7 +2,7 @@
 # from network import ESPNOW
 from time import sleep
 from lib.server_transfer import DataTransferWiFi
-from lib.espnow import Forte_ESPNOW
+from lib.espnow import Forte_ESPNOW, espnow_broadcast_config
 from lib.rtc_time import RTCTime
 
 # data = DataTransferWiFi()
@@ -14,6 +14,7 @@ from lib.rtc_time import RTCTime
 #
 rtc_time = RTCTime((2014, 5, 1, 4, 13, 0, 0, 0))
 espnow = Forte_ESPNOW()
+espnow_broadcast_config()
 while True:
     sleep(5)
     pass
-- 
GitLab