mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-16 13:25:03 +01:00
51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
#ifndef __MESHNET_H__
|
|
#define __MESHNET_H__
|
|
|
|
#ifdef ESP32
|
|
#include <WiFi.h>
|
|
#elif defined(ESP8266)
|
|
#include <ESP8266WiFi.h>
|
|
#endif // ESP32
|
|
|
|
#include <painlessMesh.h>
|
|
#include <WiFiClient.h>
|
|
#include "Network.h"
|
|
|
|
using namespace std;
|
|
using namespace std::placeholders;
|
|
|
|
// FIXME non-mesh config should have it's own struct
|
|
struct MeshConfig {
|
|
int stationMode;
|
|
int channel;
|
|
int meshPort;
|
|
const char* meshSSID;
|
|
const char* meshPassword;
|
|
const char* stationSSID;
|
|
const char* stationPassword;
|
|
const char* hostname;
|
|
uint16_t debugTypes;
|
|
};
|
|
|
|
class MeshNet : public Network {
|
|
public:
|
|
painlessMesh mesh;
|
|
MeshConfig config;
|
|
|
|
MeshNet(MeshConfig cfg);
|
|
Network* init();
|
|
Network* connectStation(int);
|
|
|
|
void update();
|
|
void newConnectionCallback(uint32_t nodeId);
|
|
void changedConnectionCallback();
|
|
void nodeTimeAdjustedCallback(int32_t offset);
|
|
void broadcast(String msg);
|
|
void sendTo(uint32_t target, String msg);
|
|
void onReceive(std::function<void(uint32_t from, String &msg)>);
|
|
int isConnected(){
|
|
return WiFi.status() == WL_CONNECTED;
|
|
}
|
|
};
|
|
|
|
#endif |