mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-15 05:02:21 +01:00
introduce dispatch method to simplify things
This commit is contained in:
@@ -2,4 +2,10 @@
|
||||
Library to build a mesh network of single purpose nodes.
|
||||
|
||||
## WTF is a sprocket?
|
||||
A sprocket is a device that has a single purpose, for example a PIR sensor node that notifies other nodes if there is motion or an LED node that lights up when a message is received.
|
||||
A sprocket is a device that has a single purpose, for example a PIR sensor node that notifies other nodes if there is motion or an LED node that lights up when a message is received.
|
||||
|
||||
# Useful commands
|
||||
```sh
|
||||
# erase flash
|
||||
esptool --port /dev/ttyUSB0 erase_flash
|
||||
```
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
k{
|
||||
"name": "sprocket-core",
|
||||
"keywords": "esp8266, sprocket, stack",
|
||||
"description": "Core stack for Sprockets",
|
||||
|
||||
@@ -22,6 +22,7 @@ Sprocket* Sprocket::activate() {
|
||||
Sprocket* Sprocket::join(Network& net){
|
||||
Serial.println("join network");
|
||||
net.init(&scheduler);
|
||||
net.onReceive(bind(&Sprocket::dispatch,this, _1, _2));
|
||||
net.connect();
|
||||
return activate(&scheduler, &net);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#include <FS.h>
|
||||
#include "Network.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
struct SprocketConfig {
|
||||
int startupDelay;
|
||||
int serialBaudRate;
|
||||
@@ -25,6 +28,7 @@ class Sprocket {
|
||||
virtual Sprocket* activate();
|
||||
virtual Sprocket* activate(Scheduler*) { return this; }
|
||||
virtual Sprocket* activate(Scheduler*, Network*) { return this; }
|
||||
virtual void dispatch(uint32_t from, String &msg) {};
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -15,7 +15,7 @@ class MeshApp : public Sprocket {
|
||||
MeshApp(SprocketConfig cfg) : Sprocket(cfg) {}
|
||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
||||
net = static_cast<MeshNet*>(network);
|
||||
net->onReceive(bind(&MeshApp::onReceive,this, _1, _2));
|
||||
//net->onReceive(bind(&MeshApp::onReceive,this, _1, _2));
|
||||
// add a task that sends stuff to the mesh
|
||||
someTask.set(TASK_SECOND * 5, TASK_FOREVER,
|
||||
bind(&MeshApp::heartbeat, this, net));
|
||||
@@ -28,7 +28,7 @@ class MeshApp : public Sprocket {
|
||||
network->broadcast(msg);
|
||||
}
|
||||
|
||||
void onReceive( uint32_t from, String &msg ) {
|
||||
void dispatch( uint32_t from, String &msg ) {
|
||||
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
|
||||
//String foo = String("cheerz back to ") + String(from);
|
||||
|
||||
Reference in New Issue
Block a user