diff --git a/client/client/lib/espnow/src/espnow.cpp b/client/client/lib/espnow/src/espnow.cpp index 01673d71390d380bdfd56c26473bd5557d383bfd..36d8b8b93e587e2e03687dbe293e0a4633465771 100644 --- a/client/client/lib/espnow/src/espnow.cpp +++ b/client/client/lib/espnow/src/espnow.cpp @@ -106,4 +106,18 @@ Message :: Message(){ data->amountData = 0; data->timestamp = rtc.getMillis(); // I am assuming we are not sending data from Unix Epoch +} + +Message :: Message(data_struct old_data){ + memcpy(data, &old_data, sizeof(data)); + + preferences.begin("config", true); + if(preferences.isKey("host")){ + preferences.getBytes("host", recipient, sizeof(uint8_t) * 6); + } + else{ + memcpy(recipient, BROADCAST_MAC, sizeof(BROADCAST_MAC)); + Serial.println("backup mac used"); + } + preferences.end(); } \ No newline at end of file diff --git a/client/client/src/main.cpp b/client/client/src/main.cpp index 2554b91d4fea310e730b3f0ae12f2d59b29b36a6..e130d950c9111ddcb72e257daf0aaa6ccc105ccd 100644 --- a/client/client/src/main.cpp +++ b/client/client/src/main.cpp @@ -1,5 +1,6 @@ #include <Arduino.h> #include "espnow.hpp" +#include "ram_caching.hpp" void setup() { @@ -22,5 +23,12 @@ void loop() { new_data->add_data(counter * 1.3, 2); new_data->send(); delete new_data; + + if(!ram_cache_is_empty()){ + data_struct old_data = ram_cache_pop(); + Message* resend_message = new Message(old_data); + resend_message->send(); + delete resend_message; + } delay(5000); } \ No newline at end of file