diff --git a/client/client/include/MeasurementData.hpp b/client/client/include/MeasurementData.hpp index 9434e6ae7588d3f8d66f64d2449bcc4ab3ab06ff..36bd5db75fbdb714dad723d67b92affd4d4fd189 100644 --- a/client/client/include/MeasurementData.hpp +++ b/client/client/include/MeasurementData.hpp @@ -34,7 +34,6 @@ class MeasurementData { double value; std::string measurementType; // TODO: consider using an enum std::optional<int> channel; - std::optional<int> i2cAddress; }; #endif // CLIENT_MEASUREMENTDATA_HPP diff --git a/client/client/lib/espnow/src/ClientDataPackage.hpp b/client/client/lib/espnow/src/ClientDataPackage.hpp index 2458ca6e40a670df1818599fce3e490bab679459..7cdd66fdc3b9175a4870933654a82c31bcf392d1 100644 --- a/client/client/lib/espnow/src/ClientDataPackage.hpp +++ b/client/client/lib/espnow/src/ClientDataPackage.hpp @@ -50,4 +50,5 @@ class ClientDataPackage { serializeJson(document, jsonString); return jsonString; } + }; diff --git a/client/client/lib/espnow/src/ESPNow.cpp b/client/client/lib/espnow/src/ESPNow.cpp index 8d7eb36da571a604af922485e31cad1b837147ea..890392ad22e6b2c7a596c12c5d7030085a76bcab 100644 --- a/client/client/lib/espnow/src/ESPNow.cpp +++ b/client/client/lib/espnow/src/ESPNow.cpp @@ -1,6 +1,6 @@ #include "ESPNow.hpp" -static const char* TAG = "ESPNOW"; +static const char *TAG = "ESPNOW"; uint8_t BROADCAST_MAC[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; esp_now_peer_info_t hostInfo; @@ -53,7 +53,10 @@ esp_err_t espnow_setup() get_host_mac(hostInfo.peer_addr); // check if there is a host saved in flash mem, broadcast otherwise hostInfo.channel = 0; - hostInfo.encrypt = 0; + + // TODO: PMK is used to encrypt LMK with the AES-128 algorithm. Call esp_now_set_pmk() to set PMK. If PMK is not set, a + // default PMK will be used. https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_now.html + hostInfo.encrypt = false; esp_now_add_peer(&hostInfo); esp_now_register_recv_cb(on_data_recv); diff --git a/client/client/lib/espnow/src/Message.cpp b/client/client/lib/espnow/src/Message.cpp index 8c69a1127de0a8ae84b153cfb778505591e12ef6..7de1fc9d38ed4ea322994c52bb6a608ff74d332a 100644 --- a/client/client/lib/espnow/src/Message.cpp +++ b/client/client/lib/espnow/src/Message.cpp @@ -9,8 +9,11 @@ esp_err_t Message::send() const ESP_LOGI(TAG, "Sending message"); esp_err_t success; auto messageData = getMessageAsMinifiedJsonString(); - success = esp_now_send(recipient, (uint8_t *)&messageData, sizeof(clientDataPackage)); + + // conversion from std::string to c_str adds null terminator, which is why we add 1 to message length + success = esp_now_send(recipient, (uint8_t *)messageData.c_str(), (messageData.length() + 1) * sizeof(char)); if (success != ESP_OK) { + ESP_LOGE(TAG, "Error sending the data"); // TODO REWRITE FOR JSON // if (!ram_cache_is_full()) { // // ram_cache_push(messageData); diff --git a/client/client/platformio.ini b/client/client/platformio.ini index 28cc58c3f73df2de36e934c0cb382f9978cf9125..435ae69baa774f3494c60228192f3fbfaec44f94 100644 --- a/client/client/platformio.ini +++ b/client/client/platformio.ini @@ -20,6 +20,9 @@ build_flags = -DCORE_DEBUG_LEVEL=5 -std=gnu++17 build_unflags = -std=gnu++11 +; serial port +monitor_port = /dev/ttyUSB1 +upload_port = /dev/ttyUSB1 lib_deps = sparkfun/SparkFun SCD30 Arduino Library@^1.0.18 Wire diff --git a/client/client/src/main.cpp b/client/client/src/main.cpp index 77265a5d537c6fb7650e76ca360715dff9182771..bf964c0c5c0280b41dc8e0a514f76408276314d0 100644 --- a/client/client/src/main.cpp +++ b/client/client/src/main.cpp @@ -14,6 +14,8 @@ void setup() { Serial.begin(115200); drs26.setup(); + espnow_setup(); + // log_e("Setup complete."); } @@ -23,7 +25,6 @@ void loop() out_data_drs26 data{}; try { - espnow_setup(); // data = drs26.readData(); auto messages = drs26.buildMessages(); diff --git a/host/esp32/src/main.cpp b/host/esp32/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..132224b96d1c3240b9c6ef17df736f0d1f16c01c --- /dev/null +++ b/host/esp32/src/main.cpp @@ -0,0 +1,42 @@ +#include <Arduino.h> +#include <WiFi.h> +#include <esp_now.h> + +void on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status) +{ + // go to sleep +} + +void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len) +{ + // print mac + Serial.println("Message recieved"); + for (int i = 0; i < 6; i++) { + Serial.print(mac[i], HEX); + Serial.print(":"); + } + Serial.println(); + + char data[len]; + memcpy(data, incomingData, len); + Serial.println(data); +} + +void setup() +{ + Serial.begin(115200); + WiFi.mode(WIFI_STA); + Serial.println("ESPNow init"); + if (esp_now_init() != ESP_OK) { + // initialization failed + Serial.println("ESPNow init failed"); + return; // not sure about this + } + Serial.println("ESPNow init success"); + + esp_now_register_recv_cb(on_data_recv); + // write your initialization code here +} + +void loop() { +} \ No newline at end of file