mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-14 12:46:50 +01:00
mesh management stuff
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"stationMode": 0,
|
||||
"stationMode": 1,
|
||||
"channel": 11,
|
||||
"meshPort": 5555,
|
||||
"meshSSID": "WibblyWobbly",
|
||||
"meshPassword": "th3r31sn0sp00n",
|
||||
"stationSSID": "MyAP",
|
||||
"stationPassword": "myApPassword",
|
||||
"hostname": "mesh-node"
|
||||
"meshSSID": "whateverYouLike",
|
||||
"meshPassword": "somethingSneaky",
|
||||
"stationSSID": "tErAx1d",
|
||||
"stationPassword": "ramalamadingdong",
|
||||
"hostname": "dbuggy"
|
||||
}
|
||||
10
data/example.config.json
Normal file
10
data/example.config.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"stationMode": 0,
|
||||
"channel": 11,
|
||||
"meshPort": 5555,
|
||||
"meshSSID": "WibblyWobbly",
|
||||
"meshPassword": "th3r31sn0sp00n",
|
||||
"stationSSID": "MyAP",
|
||||
"stationPassword": "myApPassword",
|
||||
"hostname": "mesh-node"
|
||||
}
|
||||
@@ -1,10 +1,24 @@
|
||||
// mesh topology:
|
||||
const exampleMesh = [{
|
||||
"nodeId": 757307929, "subs": [
|
||||
{ "nodeId": 2138241514, "subs": [] },
|
||||
{ "nodeId": 757307466, "subs": [] }
|
||||
]
|
||||
}, {
|
||||
"nodeId": 757308244, "subs": [
|
||||
{ "nodeId": 3154639577, "subs": [] }
|
||||
]
|
||||
}, {
|
||||
"nodeId": 3954439712, "subs": []
|
||||
}];
|
||||
|
||||
$(() => {
|
||||
// load config
|
||||
$.get("/config.json", (data) => {
|
||||
$('.js-config').val(JSON.stringify(data, null, 4));
|
||||
});
|
||||
// add handlers
|
||||
$('.js-restart').click(()=>{
|
||||
$('.js-restart').click(() => {
|
||||
$.post('/restart');
|
||||
alert('restarting...');
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
; http://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[platformio]
|
||||
env_default = mesh
|
||||
env_default = meshPixel
|
||||
|
||||
[common]
|
||||
framework = arduino
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <plugins/OtaTcpPlugin.cpp>
|
||||
#include <plugins/WebServerPlugin.cpp>
|
||||
#include <plugins/WebConfigPlugin.cpp>
|
||||
#include <plugins/MeshManPlugin.cpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
@@ -22,6 +23,7 @@ class MeshApp : public MeshSprocket {
|
||||
addPlugin(new OtaTcpPlugin(otaCfg));
|
||||
addPlugin(new WebServerPlugin(webCfg, &WEBSERVER));
|
||||
addPlugin(new WebConfigPlugin(&WEBSERVER));
|
||||
addPlugin(new MeshManPlugin(&WEBSERVER));
|
||||
}
|
||||
|
||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <plugins/OtaTcpPlugin.cpp>
|
||||
#include <plugins/WebServerPlugin.cpp>
|
||||
#include <plugins/WebConfigPlugin.cpp>
|
||||
#include <plugins/MeshManPlugin.cpp>
|
||||
#include <plugins/PixelPlugin.cpp>
|
||||
|
||||
using namespace std;
|
||||
@@ -35,12 +36,13 @@ class MeshPixel : public MeshSprocket {
|
||||
addPlugin(new OtaTcpPlugin(otaCfg));
|
||||
addPlugin(new WebServerPlugin(webCfg, server));
|
||||
addPlugin(new WebConfigPlugin(server));
|
||||
addPlugin(new MeshManPlugin(server));
|
||||
addPlugin(new PixelPlugin(pixelConfig, pixels));
|
||||
//pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelCfg.updateInterval);
|
||||
startupAnimation();
|
||||
}
|
||||
void startupAnimation() {
|
||||
pixels->Fade(0, pixels->Color(255,255,255), 4, pixelConfig.updateInterval, FORWARD);
|
||||
pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelConfig.updateInterval);
|
||||
//pixels->Fade(0, pixels->Color(255,255,255), 4, pixelConfig.updateInterval, FORWARD);
|
||||
}
|
||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
||||
// call parent method that enables dispatching and plugins
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# Mesh Sprocket Example
|
||||
|
||||
## OTA
|
||||
## MQTT stuff
|
||||
mosquitto_sub -h citadel.lan -p 1883 -v -t '#'
|
||||
|
||||
mosquitto_pub -h citadel.lan -p 1883 -t '/down/domain_id/gateway' -m '{"device":"broadcast", "msg": {"mode": 3, "value": 4} }'
|
||||
|
||||
Enable OTA:
|
||||
mosquitto_pub -h citadel.lan -p 1883 -t '/down/wirelos/gateway' -m '{"target":"broadcast", "domain": "wirelos", "msg": {"target":"broadcast", "type": 3, msg: "OTA"} }'
|
||||
|
||||
@@ -38,6 +38,6 @@
|
||||
#define LED_STRIP_UPDATE_INTERVAL 200
|
||||
#define LED_STRIP_DEFAULT_COLOR 100
|
||||
#define COLOR_CONNECTED LED_STRIP_DEFAULT_COLOR
|
||||
#define COLOR_NOT_CONNECTED 254
|
||||
#define COLOR_NOT_CONNECTED 255
|
||||
|
||||
#endif
|
||||
66
src/plugins/MeshManPlugin.cpp
Normal file
66
src/plugins/MeshManPlugin.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef __MESH_MAN_PLUGIN__
|
||||
#define __MESH_MAN_PLUGIN__
|
||||
|
||||
#include "TaskSchedulerDeclarations.h"
|
||||
#include "ArduinoOTA.h"
|
||||
#include "MeshNet.h"
|
||||
#include "Plugin.h"
|
||||
#include <plugins/WebSO.h>
|
||||
#include <base/MeshSprocketConfig.h>
|
||||
#include <functional>
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
|
||||
class MeshManPlugin : public Plugin {
|
||||
private:
|
||||
MeshNet* net;
|
||||
AsyncWebServer* server;
|
||||
public:
|
||||
MeshManPlugin(AsyncWebServer* webServer){
|
||||
server = webServer;
|
||||
}
|
||||
void activate(Scheduler* userScheduler, Network* network){
|
||||
net = static_cast<MeshNet*>(network);
|
||||
server->on("/mesh", HTTP_GET, std::bind(&MeshManPlugin::getMeshConnections, this, std::placeholders::_1));
|
||||
server->on("/mesh", HTTP_POST, std::bind(&MeshManPlugin::sendMsg, this, std::placeholders::_1));
|
||||
server->on("/mesh/nodeId", HTTP_GET, std::bind(&MeshManPlugin::getNodeId, this, std::placeholders::_1));
|
||||
server->on("/mesh/broadcast", HTTP_POST, std::bind(&MeshManPlugin::broadcast, this, std::placeholders::_1));
|
||||
}
|
||||
void getMeshConnections(AsyncWebServerRequest *request) {
|
||||
request->send(200, "text/plain", net->mesh.subConnectionJson());
|
||||
}
|
||||
void broadcast(AsyncWebServerRequest *request) {
|
||||
String msg = "";
|
||||
if(request->hasParam("msg", true)) {
|
||||
msg = request->getParam("msg", true)->value();
|
||||
}
|
||||
msg = msg + "\0";
|
||||
net->mesh.sendBroadcast(msg);
|
||||
request->send(200, "text/plain", msg);
|
||||
}
|
||||
void sendMsg(AsyncWebServerRequest *request) {
|
||||
String msg = "";
|
||||
uint32_t to = 0;
|
||||
if(request->hasParam("msg", true)) {
|
||||
msg = request->getParam("msg", true)->value();
|
||||
}
|
||||
if(request->hasParam("nodeId", true)) {
|
||||
to = atoi(request->getParam("nodeId", true)->value().c_str());
|
||||
}
|
||||
msg = msg + "\0";
|
||||
net->mesh.sendSingle(to, msg);
|
||||
request->send(200, "text/plain", msg);
|
||||
}
|
||||
void getNodeId(AsyncWebServerRequest *request) {
|
||||
StaticJsonBuffer<200> jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.createObject();
|
||||
root["nodeId"] = net->mesh.getNodeId();
|
||||
String jsonString;
|
||||
root.printTo(jsonString);
|
||||
request->send(200, "text/plain", jsonString);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -37,6 +37,7 @@ class OtaTcpPlugin : public Plugin {
|
||||
if(msg.type == MeshMessage::OTA){
|
||||
Serial.println("OTA msg received");
|
||||
WiFi.disconnect();
|
||||
net->mesh.stop();
|
||||
connectUpdateNetwork();
|
||||
enable();
|
||||
//net->mesh.sendBroadcast("my ip:" + WiFi.localIP().toString(), true);
|
||||
|
||||
Reference in New Issue
Block a user