mesh management stuff

This commit is contained in:
2018-09-01 16:56:45 +02:00
parent 3c882436bd
commit a06b3aee40
10 changed files with 109 additions and 12 deletions

View File

@@ -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
View File

@@ -0,0 +1,10 @@
{
"stationMode": 0,
"channel": 11,
"meshPort": 5555,
"meshSSID": "WibblyWobbly",
"meshPassword": "th3r31sn0sp00n",
"stationSSID": "MyAP",
"stationPassword": "myApPassword",
"hostname": "mesh-node"
}

View File

@@ -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...');
});

View File

@@ -9,7 +9,7 @@
; http://docs.platformio.org/page/projectconf.html
[platformio]
env_default = mesh
env_default = meshPixel
[common]
framework = arduino

View File

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

View File

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

View File

@@ -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"} }'

View File

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

View 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

View File

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