diff --git a/data/config.json b/data/config.json index e20959f..c7e58b1 100644 --- a/data/config.json +++ b/data/config.json @@ -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" } \ No newline at end of file diff --git a/data/example.config.json b/data/example.config.json new file mode 100644 index 0000000..e20959f --- /dev/null +++ b/data/example.config.json @@ -0,0 +1,10 @@ +{ + "stationMode": 0, + "channel": 11, + "meshPort": 5555, + "meshSSID": "WibblyWobbly", + "meshPassword": "th3r31sn0sp00n", + "stationSSID": "MyAP", + "stationPassword": "myApPassword", + "hostname": "mesh-node" +} \ No newline at end of file diff --git a/data/www/script.js b/data/www/script.js index e454a33..0127995 100644 --- a/data/www/script.js +++ b/data/www/script.js @@ -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...'); }); diff --git a/platformio.ini b/platformio.ini index 72ca256..ce98e66 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; http://docs.platformio.org/page/projectconf.html [platformio] -env_default = mesh +env_default = meshPixel [common] framework = arduino diff --git a/src/examples/mesh/MeshApp.h b/src/examples/mesh/MeshApp.h index 8288b67..77cb146 100644 --- a/src/examples/mesh/MeshApp.h +++ b/src/examples/mesh/MeshApp.h @@ -8,6 +8,7 @@ #include #include #include +#include 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) { diff --git a/src/examples/meshPixel/MeshPixel.h b/src/examples/meshPixel/MeshPixel.h index e20bec0..56fa8ae 100644 --- a/src/examples/meshPixel/MeshPixel.h +++ b/src/examples/meshPixel/MeshPixel.h @@ -15,6 +15,7 @@ #include #include #include +#include #include 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 diff --git a/src/examples/meshPixel/README.md b/src/examples/meshPixel/README.md index 53e7306..03bc339 100644 --- a/src/examples/meshPixel/README.md +++ b/src/examples/meshPixel/README.md @@ -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"} }' diff --git a/src/examples/meshPixel/config.h b/src/examples/meshPixel/config.h index 3758926..c51131c 100644 --- a/src/examples/meshPixel/config.h +++ b/src/examples/meshPixel/config.h @@ -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 \ No newline at end of file diff --git a/src/plugins/MeshManPlugin.cpp b/src/plugins/MeshManPlugin.cpp new file mode 100644 index 0000000..8b7b1f3 --- /dev/null +++ b/src/plugins/MeshManPlugin.cpp @@ -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 +#include +#include + +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(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 \ No newline at end of file diff --git a/src/plugins/OtaTcpPlugin.cpp b/src/plugins/OtaTcpPlugin.cpp index a0ab79e..affde58 100644 --- a/src/plugins/OtaTcpPlugin.cpp +++ b/src/plugins/OtaTcpPlugin.cpp @@ -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);