diff --git a/client/client/lib/caching/src/ram_caching.cpp b/client/client/lib/caching/src/ram_caching.cpp index 08d30ee2df7741cef82d1b1812b8683392f5344b..3b16f6e073fcffeef10cf68a0e8dd3db981f9fc6 100644 --- a/client/client/lib/caching/src/ram_caching.cpp +++ b/client/client/lib/caching/src/ram_caching.cpp @@ -2,7 +2,7 @@ namespace RtcMemory{ // 2D array of 20 Strings with maxLength of 251 - RTC_DATA_ATTR char storage[maxSize_][maxLength_]; + RTC_DATA_ATTR char storage[maxLength_][maxSize_]; RTC_DATA_ATTR int headElement = 0; RTC_DATA_ATTR int tailElement = 0; @@ -14,57 +14,38 @@ namespace RtcMemory{ // turn data into char array const char* jsonString = message.c_str(); - // move head to beginning of new element - // head = (head + (sizeof(char) * 251)) % sizeof(storage); + // move head to new element headElement = (headElement + 1) % maxSize_; - // copy data to earliest free block - memcpy( &storage + headElement*maxSize_, - jsonString, - sizeof(jsonString) - ); - ESP_LOGI(TAG, "Moved message to storage."); + // apparently I am not allowed to copy to rtc mem + for(int i=0; i<maxLength_; i++){ + storage[i][headElement] = jsonString[i]; + Serial.print(jsonString[i]); + if(jsonString[i] == '\0'){ + Serial.println("\n"); + Serial.flush(); + break; + } + } + ESP_LOGE(TAG, "Moved message to storage."); } String get_from_storage(){ // remove element pointed at by tail String buf = ""; - char current; - for(int i = 0; i<251; i++){ - // i dont like this - memcpy(¤t, &storage + (tailElement*maxSize_) + i, sizeof(char)); + char current = '\0'; + for(int i = 0; i<maxLength_; i++){ + current = storage[i][tailElement]; buf += current; - if(current = '\0'){ + Serial.print(current); + if(current == '\0'){ + Serial.println("\n"); + Serial.flush(); break; } } // move tail to next element tailElement = (tailElement + 1) % maxLength_; - Serial.println(buf); - ESP_LOGI(TAG, "Retrieved message from storage"); + ESP_LOGE(TAG, "Retrieved message from storage"); return buf; } } - -//RTC_DATA_ATTR int cachedAmount = -1; -//RTC_DATA_ATTR ClientDataPackage backup[NUM_SENSORS]; -// -//ClientDataPackage ram_cache_pop() -//{ -// return backup[cachedAmount--]; -//} -// -//void ram_cache_push(ClientDataPackage data) -//{ -// backup[++cachedAmount] = data; -// ESP_LOGI(TAG, "ClientDataPackage saved"); -//} -// -//bool ram_cache_is_empty() -//{ -// return cachedAmount == -1; -//} -// -//bool ram_cache_is_full() -//{ -// return cachedAmount == 9; -//} \ No newline at end of file diff --git a/client/client/lib/caching/src/ram_caching.hpp b/client/client/lib/caching/src/ram_caching.hpp index 7a0dd9716bf02bd124ce4533086664a0ec880d53..b16e248a7a514a21e523f06cb66c5408ad0a65ab 100644 --- a/client/client/lib/caching/src/ram_caching.hpp +++ b/client/client/lib/caching/src/ram_caching.hpp @@ -3,7 +3,7 @@ #include "esp_log.h" #include <ESP32Time.h> -#define maxSize_ 20 +#define maxSize_ 2 #define maxLength_ 251 namespace RtcMemory { diff --git a/client/client/lib/espnow/src/Message.cpp b/client/client/lib/espnow/src/Message.cpp index bd1e08a62901746d43300c4f45ff98514e687f8f..7f7f8e2326e86ba647971170dbf3a43a83227c90 100644 --- a/client/client/lib/espnow/src/Message.cpp +++ b/client/client/lib/espnow/src/Message.cpp @@ -15,12 +15,9 @@ esp_err_t Message::send() const if (success != ESP_OK) { ESP_LOGE(TAG, "Error sending the data"); Serial.println(success, HEX); - // TODO REWRITE FOR JSON - // if (!ram_cache_is_full()) { - // // ram_cache_push(messageData); - // } + // Removed caching from here, better do this in main } - ESP_LOGD(TAG, "Sent data: %s", messageData.c_str()); + ESP_LOGE(TAG, "Sent data: %s", messageData.c_str()); ESP_LOGD(TAG, "time sent: %l", clientDataPackage.getTimestamp()); ESP_LOGD(TAG, "send status: %d", success); diff --git a/client/client/src/main.cpp b/client/client/src/main.cpp index 6281ac79e00f954e0380cab41ea25c9c3c320448..4656cf0ef9a3aacb60654fa8e5fa683769a81803 100644 --- a/client/client/src/main.cpp +++ b/client/client/src/main.cpp @@ -32,10 +32,21 @@ void loop() auto messages = drs26.buildMessages(); for (const Message &message : messages) { - if(message.send() != ESP_OK){ - RtcMemory::store(message.getMessageAsMinifiedJsonString()); - } + // if(message.send() != ESP_OK){ + // RtcMemory::store(message.getMessageAsMinifiedJsonString()); + // } + // some sort of if(message received) is needed as well + RtcMemory::store(message.getMessageAsMinifiedJsonString()); + // Serial.println("original string:"); + // Serial.println(message.getMessageAsMinifiedJsonString().c_str()); + // Serial.println("length: " + (String) sizeof(message.getMessageAsMinifiedJsonString().c_str())); + // Serial.println("\n after retrieval:"); + String test = RtcMemory::get_from_storage(); + // Serial.println(test); + // Serial.println("length: " + (String) sizeof(test)); + Serial.println("------------------------"); } + Serial.println("================================"); } catch (const NoDataAvailableException &e) { std::cerr << e.what() << '\n'; @@ -48,6 +59,6 @@ void loop() Serial.print("This device: "); Serial.println(WiFi.macAddress()); Serial.println("\n"); - delay(5000); - DeepSleep::deep_sleep(5); + delay(10000); + // DeepSleep::deep_sleep(5); } diff --git a/host/esp32-espnow-recv/platformio.ini b/host/esp32-espnow-recv/platformio.ini index 73a15dd46f3a4a79306f6bb21fa95aa1eda91597..808a5bb1fc8bdb99fa2782ed3898a0cf5dcc7ae5 100644 --- a/host/esp32-espnow-recv/platformio.ini +++ b/host/esp32-espnow-recv/platformio.ini @@ -13,8 +13,8 @@ platform = espressif32 board = esp32-c3-devkitm-1 monitor_speed = 115200 framework = arduino -monitor_port = /dev/ttyUSB1 -upload_port = /dev/ttyUSB1 +; monitor_port = /dev/ttyUSB1 +; upload_port = /dev/ttyUSB1 build_flags = -I include -DCORE_DEBUG_LEVEL=5