diff --git a/client/client/lib/README b/client/client/lib/README new file mode 100644 index 0000000000000000000000000000000000000000..55da06ff31bbb98f1ac6f6accba999be40aca532 --- /dev/null +++ b/client/client/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]").**** + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include <Foo.h> +#include <Bar.h> + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/client/client/lib/espnow/src/espnow.cpp b/client/client/lib/espnow/src/espnow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b5cb166430e529d007f9338decb07ef47a6eef85 --- /dev/null +++ b/client/client/lib/espnow/src/espnow.cpp @@ -0,0 +1,41 @@ +#include <esp_now.h> +#include "WiFi.h" +#include "espnow.h" + +uint8_t BROADCAST_MAC[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; //probably shouldn't be defined here, works for now +esp_now_peer_info_t hostInfo; + +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){ + // sync time +} + +int send_data(dataMessage data){ + esp_err_t result = esp_now_send(BROADCAST_MAC, (uint8_t *) &data, sizeof(data)); + return result; +} + +int espnow_setup(){ + WiFi.mode(WIFI_STA); + if(esp_now_init() != ESP_OK){ + //initialization failed + return 1; + } + + memcpy(hostInfo.peer_addr, BROADCAST_MAC, sizeof(BROADCAST_MAC)); + hostInfo.channel = 0; + hostInfo.encrypt = true; //if we encrypt espnow we can have no more than 10 clients per host + esp_err_t peerAddStatus = esp_now_add_peer(&hostInfo); //there are a couple errors that can happen here + if(peerAddStatus != ESP_OK){ + //peer couldn't be added + return 2; + } + + esp_now_register_recv_cb(on_data_recv); + esp_now_register_send_cb(on_data_sent); + + return 0; +} diff --git a/client/client/lib/espnow/src/espnow.h b/client/client/lib/espnow/src/espnow.h new file mode 100644 index 0000000000000000000000000000000000000000..334fe1079577bf35e62b35d320e71a5d68886c69 --- /dev/null +++ b/client/client/lib/espnow/src/espnow.h @@ -0,0 +1,12 @@ +#define NUM_SENSORS 10 + +// I originally wanted to define the mac addresses here, but i got a "multiple definition" error? +typedef struct dataMessage{ + int identifiers[NUM_SENSORS]; + float values[NUM_SENSORS]; +}dataMessage; + +int send_data(dataMessage data); + +int espnow_setup(); +