mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-17 21:56:40 +01:00
Simplify
This commit is contained in:
@@ -4,40 +4,47 @@
|
||||
#include <painlessMesh.h>
|
||||
#include <WiFiClient.h>
|
||||
#include "Network.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
#define STATION_MODE 1
|
||||
#define WIFI_CHANNEL 11
|
||||
|
||||
#define MESH_PREFIX "whateverYouLike"
|
||||
#define MESH_PASSWORD "somethingSneaky"
|
||||
#define MESH_PORT 5555
|
||||
|
||||
#define STATION_SSID "tErAx1d"
|
||||
#define STATION_PWD "ramalamadingdong"
|
||||
#define HOSTNAME "MeshNode"
|
||||
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() {
|
||||
config = cfg;
|
||||
}
|
||||
|
||||
Network* init(){
|
||||
|
||||
Serial.println("init mesh");
|
||||
//mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
|
||||
mesh.setDebugMsgTypes( ERROR | STARTUP | CONNECTION);
|
||||
mesh.init( MESH_PREFIX, MESH_PASSWORD, scheduler, MESH_PORT, WIFI_AP_STA, WIFI_CHANNEL );
|
||||
mesh.setDebugMsgTypes( config.debugTypes );
|
||||
mesh.init( config.meshSSID, config.meshPassword, scheduler, config.meshPort, WIFI_AP_STA, config.channel );
|
||||
|
||||
//mesh.onReceive(bind(&MeshNet::receivedCallback,this, _1, _2));
|
||||
mesh.onNewConnection(bind(&MeshNet::newConnectionCallback, this, _1));
|
||||
mesh.onChangedConnections(bind(&MeshNet::changedConnectionCallback, this));
|
||||
mesh.onNodeTimeAdjusted(bind(&MeshNet::nodeTimeAdjustedCallback, this, _1));
|
||||
|
||||
if(STATION_MODE){
|
||||
if(config.stationMode){
|
||||
Serial.println("connect station");
|
||||
mesh.stationManual(STATION_SSID, STATION_PWD);
|
||||
mesh.setHostname(HOSTNAME);
|
||||
mesh.stationManual(config.stationSSID, config.stationPassword);
|
||||
mesh.setHostname(config.hostname);
|
||||
}
|
||||
|
||||
return this;
|
||||
@@ -49,6 +56,7 @@ class MeshNet : public Network {
|
||||
mesh.sendBroadcast(msg);
|
||||
}
|
||||
void update(){
|
||||
// only needed when no scheduler was passed to mesh.init
|
||||
mesh.update();
|
||||
}
|
||||
void receivedCallback( uint32_t from, String &msg ) {
|
||||
|
||||
Reference in New Issue
Block a user