diff --git a/platformio.ini b/platformio.ini
index 69b887e..5ced6c2 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -29,6 +29,7 @@ lib_deps =
ESP Async WebServer
ESPAsyncTCP
Adafruit NeoPixel
+ PubSubClient
[env:build]
src_filter = +<*> -
+
@@ -40,7 +41,7 @@ framework = ${common.framework}
build_flags = -Wl,-Teagle.flash.4m1m.ld
-DSPROCKET_PRINT=1
lib_deps = ${common.lib_deps}
- https://gitlab.com/wirelos/sprocket-core.git#develop
+ https://gitlab.com/wirelos/sprocket-lib.git#develop
[env:build-mesh]
@@ -53,7 +54,7 @@ framework = ${common.framework}
build_flags = -Wl,-Teagle.flash.4m1m.ld
-DSPROCKET_PRINT=1
lib_deps = ${common.lib_deps}
- https://gitlab.com/wirelos/sprocket-core.git#develop
+ https://gitlab.com/wirelos/sprocket-lib.git#develop
[env:release]
src_filter = +<*> -
+
@@ -65,7 +66,7 @@ framework = ${common.framework}
build_flags = -Wl,-Teagle.flash.4m1m.ld
-DSPROCKET_PRINT=0
lib_deps = ${common.lib_deps}
- https://gitlab.com/wirelos/sprocket-core.git#develop
+ https://gitlab.com/wirelos/sprocket-lib.git#develop
[env:nodemcu]
@@ -78,4 +79,4 @@ framework = ${common.framework}
build_flags = -Wl,-Teagle.flash.4m1m.ld
-DSPROCKET_PRINT=1
lib_deps = ${common.lib_deps}
- https://gitlab.com/wirelos/sprocket-core.git#develop
\ No newline at end of file
+ https://gitlab.com/wirelos/sprocket-lib.git#develop
\ No newline at end of file
diff --git a/src/IlluCat.h b/src/IlluCat.h
index c7efc84..9f7393c 100644
--- a/src/IlluCat.h
+++ b/src/IlluCat.h
@@ -8,8 +8,7 @@
#include "config.h"
#include "NeoPattern.cpp"
#include "NeoPatternDto.h"
-#include
-#include
+#include
#include
#include
#include "WebApi.cpp"
@@ -23,26 +22,23 @@ class IlluCat : public Sprocket
public:
AsyncWebServer *server;
SprocketConfig sprocketConfig;
- OtaConfig otaConfig;
WebServerConfig webConfig;
- IlluCat(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg) : Sprocket(cfg)
+ IlluCat(SprocketConfig cfg, WebServerConfig webCfg) : Sprocket(cfg)
{
sprocketConfig = cfg;
- otaConfig = otaCfg;
webConfig = webCfg;
server = new AsyncWebServer(80);
server->serveStatic(PIXEL_CONFIG_FILE, SPIFFS, "pixelConfig.json");
+ addPlugin(new PixelPlugin());
+ addPlugin(new WebServerPlugin(webConfig, server));
+ addPlugin(new WebConfigPlugin(server));
+ addPlugin(new WebApi(server, "mesh/broadcast"));
}
void setup()
{
- addPlugin(new PixelPlugin());
- addPlugin(new WebServerPlugin(webConfig, server));
- addPlugin(new WebConfigPlugin(server));
- addPlugin(new WebApi(server, 1));
}
-
};
#endif
\ No newline at end of file
diff --git a/src/PixelPlugin.cpp b/src/PixelPlugin.cpp
index d6ad2f0..63528ba 100644
--- a/src/PixelPlugin.cpp
+++ b/src/PixelPlugin.cpp
@@ -40,7 +40,7 @@ void PixelPlugin::defaultAnimation() {
animate();
}
-void PixelPlugin::activate(Scheduler *userScheduler, Network *network)
+void PixelPlugin::activate(Scheduler *userScheduler)
{
animation.set(TASK_MILLISECOND * pixelConfig.updateInterval, TASK_FOREVER, bind(&PixelPlugin::animate, this));
userScheduler->addTask(animation);
diff --git a/src/PixelPlugin.h b/src/PixelPlugin.h
index e1a727d..9d711bb 100644
--- a/src/PixelPlugin.h
+++ b/src/PixelPlugin.h
@@ -31,7 +31,7 @@ class PixelPlugin : public Plugin {
void loadConfigFromFile();
void applyConfig(NeoPixelConfig cfg);
void applyConfigFromFile();
- void activate(Scheduler* userScheduler, Network* network);
+ void activate(Scheduler* userScheduler);
void defaultAnimation();
void setState(String msg);
void colorWheel(String msg);
diff --git a/src/WebApi.cpp b/src/WebApi.cpp
index e7bea6e..7035350 100644
--- a/src/WebApi.cpp
+++ b/src/WebApi.cpp
@@ -19,8 +19,6 @@ using namespace std::placeholders;
class WebApi : public Plugin
{
- private:
- Network *network;
public:
AsyncWebServer *server;
@@ -28,17 +26,18 @@ class WebApi : public Plugin
SprocketMessage currentMessage;
int broadcast;
+ String broadcastTopic;
- WebApi(AsyncWebServer *_server, int _broadcast = 0)
+ WebApi(AsyncWebServer *_server, String _broadcastTopic)
{
server = _server;
- broadcast = _broadcast;
+ broadcast = _broadcastTopic ? 1 : 0;
+ broadcastTopic = _broadcastTopic;
Update.runAsync(true);
}
- void activate(Scheduler *_scheduler, Network *_network)
+ void activate(Scheduler *_scheduler)
{
- network = _network;
ws = new AsyncWebSocket("/ws");
ws->onEvent(bind(&WebApi::onWsEvent, this, _1, _2, _3, _4, _5, _6));
server->addHandler(ws);
@@ -57,7 +56,7 @@ class WebApi : public Plugin
publish(currentMessage.topic, currentMessage.payload);
if (currentMessage.broadcast)
{
- network->broadcast(msg);
+ publish(broadcastTopic, msg);
}
request->send(200, "text/plain", msg);
}
@@ -67,7 +66,7 @@ class WebApi : public Plugin
if (type == WS_EVT_DATA)
{
String frame = WebUtils::parseFrameAsString(type, arg, data, len, 0);
- dispatch(0, frame);
+ dispatch(frame);
}
}
@@ -116,16 +115,15 @@ class WebApi : public Plugin
}
}
- void dispatch(uint32_t from, String &msg)
+ void dispatch(String &msg)
{
currentMessage.fromJsonString(msg);
if (currentMessage.valid)
{
- currentMessage.from = from;
publish(currentMessage.topic, currentMessage.payload);
if (broadcast)
{
- network->broadcast(msg);
+ publish(broadcastTopic, msg);
}
}
}
diff --git a/src/wifi/main.cpp b/src/wifi/main.cpp
index 05f873b..49579a3 100644
--- a/src/wifi/main.cpp
+++ b/src/wifi/main.cpp
@@ -2,27 +2,28 @@
#include "WiFiNet.h"
#include "IlluCat.h"
-WiFiNet net(
- SPROCKET_MODE,
- STATION_SSID,
- STATION_PASSWORD,
- AP_SSID,
- AP_PASSWORD,
- HOSTNAME,
- CONNECT_TIMEOUT
-);
-IlluCat sprocket(
- { STARTUP_DELAY, SERIAL_BAUD_RATE },
- { OTA_PORT, OTA_PASSWORD },
- { WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE }
-);
+WiFiNet *network;
+IlluCat *sprocket;
-void setup() {
- sprocket.setup();
- sprocket.join(net);
+void setup()
+{
+ sprocket = new IlluCat(
+ {STARTUP_DELAY, SERIAL_BAUD_RATE},
+ {WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE});
+ network = new WiFiNet(
+ SPROCKET_MODE,
+ STATION_SSID,
+ STATION_PASSWORD,
+ AP_SSID,
+ AP_PASSWORD,
+ HOSTNAME,
+ CONNECT_TIMEOUT);
+ network->connect();
+ sprocket->activate();
}
-void loop() {
- sprocket.loop();
+void loop()
+{
+ sprocket->loop();
yield();
}
\ No newline at end of file
diff --git a/src/wifiMesh/MeshCat.h b/src/wifiMesh/MeshCat.h
deleted file mode 100644
index 083acf4..0000000
--- a/src/wifiMesh/MeshCat.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#ifndef __MESHCAT__
-#define __MESHCAT__
-
-#include
-#include
-#include
-#include "utils_print.h"
-#include "IlluCat.h"
-#include "config.h"
-
-using namespace std;
-using namespace std::placeholders;
-
-class MeshCat : public IlluCat {
- public:
- Scheduler* meshScheduler;
-
- MeshCat(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg) : IlluCat(cfg, otaCfg, webCfg) {
- meshScheduler = new Scheduler();
- }
-
- Sprocket* join(Network& net){
- PRINT_MSG(Serial, SPROCKET_TYPE, "join mesh network");
- net.init(meshScheduler);
- net.onReceive(bind(&IlluCat::dispatch,this, _1, _2));
- net.connect();
- network = net;
- return activate(&scheduler, &net);
- }
-
- void loop() {
- meshScheduler->execute();
- yield();
- Sprocket::loop();
- yield();
- }
-};
-
-#endif
\ No newline at end of file
diff --git a/src/wifiMesh/main.cpp b/src/wifiMesh/main.cpp
index 6dfc6a4..f4764ad 100644
--- a/src/wifiMesh/main.cpp
+++ b/src/wifiMesh/main.cpp
@@ -1,25 +1,24 @@
#include "config.h"
-#include "MeshNet.h"
-#include "MeshCat.h"
+#include "plugins/MeshNetworkPlugin.cpp"
+#include "IlluCat.h"
-MeshNet net({
- SPROCKET_MODE, WIFI_CHANNEL,
- MESH_PORT, MESH_PREFIX, MESH_PASSWORD,
- STATION_SSID, STATION_PASSWORD, HOSTNAME,
- MESH_DEBUG_TYPES
-});
-MeshCat sprocket(
- { STARTUP_DELAY, SERIAL_BAUD_RATE },
- { OTA_PORT, OTA_PASSWORD },
- { WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE }
-);
+IlluCat *sprocket;
-void setup() {
- sprocket.setup();
- sprocket.join(net);
+void setup()
+{
+ sprocket = new IlluCat(
+ {STARTUP_DELAY, SERIAL_BAUD_RATE},
+ {WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE});
+ sprocket->addPlugin(new MeshNetworkPlugin(
+ {SPROCKET_MODE, WIFI_CHANNEL,
+ MESH_PORT, MESH_PREFIX, MESH_PASSWORD,
+ STATION_SSID, STATION_PASSWORD, HOSTNAME,
+ MESH_DEBUG_TYPES}));
+ sprocket->activate();
}
-void loop() {
- sprocket.loop();
+void loop()
+{
+ sprocket->loop();
yield();
}
\ No newline at end of file