This commit is contained in:
2018-06-12 19:44:22 +00:00
parent a6d17ba6a3
commit 16b4f254e5
17 changed files with 98 additions and 254 deletions

View File

@@ -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 ) {