mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-15 21:18:21 +01:00
layer basic com
This commit is contained in:
@@ -35,7 +35,9 @@ firmware-build:
|
|||||||
image: python:2.7-stretch
|
image: python:2.7-stretch
|
||||||
script:
|
script:
|
||||||
- pio run -t clean
|
- pio run -t clean
|
||||||
- pio run
|
- pio run --environment basic
|
||||||
|
- pio run --environment mesh
|
||||||
|
- pio run --environment meshMqttBridge
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- .pioenvs/*/firmware.*
|
- .pioenvs/*/firmware.*
|
||||||
|
|||||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -36,6 +36,7 @@
|
|||||||
"type_traits": "cpp",
|
"type_traits": "cpp",
|
||||||
"tuple": "cpp",
|
"tuple": "cpp",
|
||||||
"typeinfo": "cpp",
|
"typeinfo": "cpp",
|
||||||
"utility": "cpp"
|
"utility": "cpp",
|
||||||
|
"bitset": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,6 @@ Network* MeshNet::init(){
|
|||||||
mesh.setDebugMsgTypes( config.debugTypes );
|
mesh.setDebugMsgTypes( config.debugTypes );
|
||||||
mesh.init( config.meshSSID, config.meshPassword, scheduler, config.meshPort, WIFI_AP_STA, config.channel );
|
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.onNewConnection(bind(&MeshNet::newConnectionCallback, this, _1));
|
||||||
mesh.onChangedConnections(bind(&MeshNet::changedConnectionCallback, this));
|
mesh.onChangedConnections(bind(&MeshNet::changedConnectionCallback, this));
|
||||||
mesh.onNodeTimeAdjusted(bind(&MeshNet::nodeTimeAdjustedCallback, this, _1));
|
mesh.onNodeTimeAdjusted(bind(&MeshNet::nodeTimeAdjustedCallback, this, _1));
|
||||||
@@ -36,8 +35,8 @@ void MeshNet::update(){
|
|||||||
// only needed when no scheduler was passed to mesh.init
|
// only needed when no scheduler was passed to mesh.init
|
||||||
mesh.update();
|
mesh.update();
|
||||||
}
|
}
|
||||||
void MeshNet::receivedCallback( uint32_t from, String &msg ) {
|
void MeshNet::onReceive( std::function<void(uint32_t from, String &msg)> cb) {
|
||||||
Serial.printf("--> Received from %u msg=%s\n", from, msg.c_str());
|
mesh.onReceive(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshNet::newConnectionCallback(uint32_t nodeId) {
|
void MeshNet::newConnectionCallback(uint32_t nodeId) {
|
||||||
|
|||||||
@@ -28,13 +28,13 @@ class MeshNet : public Network {
|
|||||||
MeshNet(MeshConfig cfg);
|
MeshNet(MeshConfig cfg);
|
||||||
Network* init();
|
Network* init();
|
||||||
|
|
||||||
void broadcast(String msg);
|
|
||||||
void sendTo(uint32_t target, String msg);
|
|
||||||
void update(); // only needed when no scheduler was passed to mesh.init
|
void update(); // only needed when no scheduler was passed to mesh.init
|
||||||
void receivedCallback( uint32_t from, String &msg );
|
|
||||||
void newConnectionCallback(uint32_t nodeId);
|
void newConnectionCallback(uint32_t nodeId);
|
||||||
void changedConnectionCallback();
|
void changedConnectionCallback();
|
||||||
void nodeTimeAdjustedCallback(int32_t offset);
|
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)>);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <TaskSchedulerDeclarations.h>
|
#include <TaskSchedulerDeclarations.h>
|
||||||
|
|
||||||
|
typedef std::function<void(uint32_t from, String &msg)> msgReceived_cb;
|
||||||
|
|
||||||
class Network {
|
class Network {
|
||||||
public:
|
public:
|
||||||
uint32_t id = 0;
|
uint32_t id = 0;
|
||||||
@@ -13,9 +15,9 @@ class Network {
|
|||||||
virtual Network* init(Scheduler* s) { scheduler = s; return init(); };
|
virtual Network* init(Scheduler* s) { scheduler = s; return init(); };
|
||||||
virtual Network* connect() { return this; };
|
virtual Network* connect() { return this; };
|
||||||
virtual void update() {};
|
virtual void update() {};
|
||||||
virtual void broadcast(String msg){
|
virtual void broadcast(String msg){};
|
||||||
Serial.println("no-broadcast");
|
virtual void sendTo(uint32_t target, String msg) {};
|
||||||
};
|
virtual void onReceive(std::function<void(uint32_t from, String &msg)>);
|
||||||
Network* setScheduler(Scheduler* s) {
|
Network* setScheduler(Scheduler* s) {
|
||||||
scheduler = s;
|
scheduler = s;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class MeshApp : public Sprocket {
|
|||||||
MeshApp(SprocketConfig cfg) : Sprocket(cfg) {}
|
MeshApp(SprocketConfig cfg) : Sprocket(cfg) {}
|
||||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
||||||
net = static_cast<MeshNet*>(network);
|
net = static_cast<MeshNet*>(network);
|
||||||
net->mesh.onReceive(bind(&MeshApp::receivedCallback,this, _1, _2));
|
net->onReceive(bind(&MeshApp::onReceive,this, _1, _2));
|
||||||
// add a task that sends stuff to the mesh
|
// add a task that sends stuff to the mesh
|
||||||
someTask.set(TASK_SECOND * 5, TASK_FOREVER,
|
someTask.set(TASK_SECOND * 5, TASK_FOREVER,
|
||||||
bind(&MeshApp::heartbeat, this, net));
|
bind(&MeshApp::heartbeat, this, net));
|
||||||
@@ -28,8 +28,8 @@ class MeshApp : public Sprocket {
|
|||||||
network->broadcast(msg);
|
network->broadcast(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void receivedCallback( uint32_t from, String &msg ) {
|
void onReceive( uint32_t from, String &msg ) {
|
||||||
Serial.printf("startHere: Received from %u msg=%s\n", from, msg.c_str());
|
Serial.printf("MeshApp: received from %u msg=%s\n", from, msg.c_str());
|
||||||
// respond in receive callback can cause an endless loop when all nodes run the same firmware
|
// respond in receive callback can cause an endless loop when all nodes run the same firmware
|
||||||
//String foo = String("cheerz back to ") + String(from);
|
//String foo = String("cheerz back to ") + String(from);
|
||||||
//net->broadcast(foo);
|
//net->broadcast(foo);
|
||||||
|
|||||||
@@ -13,11 +13,11 @@
|
|||||||
#define STATION_MODE 0
|
#define STATION_MODE 0
|
||||||
#define WIFI_CHANNEL 11
|
#define WIFI_CHANNEL 11
|
||||||
#define MESH_PORT 5555
|
#define MESH_PORT 5555
|
||||||
#define MESH_PREFIX "WirelosContraption"
|
#define MESH_PREFIX "whateverYouLike"
|
||||||
#define MESH_PASSWORD "somethingSneaky"
|
#define MESH_PASSWORD "somethingSneaky"
|
||||||
#define STATION_SSID "Th1ngs4P"
|
#define STATION_SSID "Th1ngs4P"
|
||||||
#define STATION_PASSWORD "th3r31sn0sp00n"
|
#define STATION_PASSWORD "th3r31sn0sp00n"
|
||||||
#define HOSTNAME "mesh-node"
|
#define HOSTNAME "mesh-node"
|
||||||
#define MESH_DEBUG_TYPES ERROR | STARTUP | CONNECTION
|
#define MESH_DEBUG_TYPES ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user