Skip to content
Snippets Groups Projects
Commit eadd1eac authored by Moritz Perschke's avatar Moritz Perschke
Browse files

folder 'lib' was previously ignored, contains espnow.cpp and its header

parent f0204211
No related branches found
No related tags found
5 merge requests!39Merge Develop into Main,!19development into master,!17Inital Host, initial Client,!3Merge Branch `develop` into `sensor_readout`,!1Espnow
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
#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;
}
#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();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment