mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-15 17:58:20 +01:00
adapt to new sprocket api
This commit is contained in:
@@ -12,10 +12,6 @@
|
|||||||
|
|
||||||
<body class="sui">
|
<body class="sui">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<form id="fwUpload" enctype="multipart/form-data" method="post" action="#">
|
|
||||||
<input id="fileupload" name="myfile" type="file" />
|
|
||||||
<input type="submit" value="submit" id="submit" />
|
|
||||||
</form>
|
|
||||||
<form class="param-control container collapsible open" action="#" method="POST">
|
<form class="param-control container collapsible open" action="#" method="POST">
|
||||||
<span class="heading">Pixels</span>
|
<span class="heading">Pixels</span>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ lib_deps =
|
|||||||
ESP Async WebServer
|
ESP Async WebServer
|
||||||
ESPAsyncTCP
|
ESPAsyncTCP
|
||||||
Adafruit NeoPixel
|
Adafruit NeoPixel
|
||||||
|
PubSubClient
|
||||||
|
|
||||||
[env:build]
|
[env:build]
|
||||||
src_filter = +<*> -<wifiMesh/> +<wifi/>
|
src_filter = +<*> -<wifiMesh/> +<wifi/>
|
||||||
@@ -40,7 +41,7 @@ framework = ${common.framework}
|
|||||||
build_flags = -Wl,-Teagle.flash.4m1m.ld
|
build_flags = -Wl,-Teagle.flash.4m1m.ld
|
||||||
-DSPROCKET_PRINT=1
|
-DSPROCKET_PRINT=1
|
||||||
lib_deps = ${common.lib_deps}
|
lib_deps = ${common.lib_deps}
|
||||||
https://gitlab.com/wirelos/sprocket-core.git#develop
|
https://gitlab.com/wirelos/sprocket-lib.git#develop
|
||||||
|
|
||||||
|
|
||||||
[env:build-mesh]
|
[env:build-mesh]
|
||||||
@@ -53,7 +54,7 @@ framework = ${common.framework}
|
|||||||
build_flags = -Wl,-Teagle.flash.4m1m.ld
|
build_flags = -Wl,-Teagle.flash.4m1m.ld
|
||||||
-DSPROCKET_PRINT=1
|
-DSPROCKET_PRINT=1
|
||||||
lib_deps = ${common.lib_deps}
|
lib_deps = ${common.lib_deps}
|
||||||
https://gitlab.com/wirelos/sprocket-core.git#develop
|
https://gitlab.com/wirelos/sprocket-lib.git#develop
|
||||||
|
|
||||||
[env:release]
|
[env:release]
|
||||||
src_filter = +<*> -<wifiMesh/> +<wifi/>
|
src_filter = +<*> -<wifiMesh/> +<wifi/>
|
||||||
@@ -65,7 +66,7 @@ framework = ${common.framework}
|
|||||||
build_flags = -Wl,-Teagle.flash.4m1m.ld
|
build_flags = -Wl,-Teagle.flash.4m1m.ld
|
||||||
-DSPROCKET_PRINT=0
|
-DSPROCKET_PRINT=0
|
||||||
lib_deps = ${common.lib_deps}
|
lib_deps = ${common.lib_deps}
|
||||||
https://gitlab.com/wirelos/sprocket-core.git#develop
|
https://gitlab.com/wirelos/sprocket-lib.git#develop
|
||||||
|
|
||||||
|
|
||||||
[env:nodemcu]
|
[env:nodemcu]
|
||||||
@@ -78,4 +79,4 @@ framework = ${common.framework}
|
|||||||
build_flags = -Wl,-Teagle.flash.4m1m.ld
|
build_flags = -Wl,-Teagle.flash.4m1m.ld
|
||||||
-DSPROCKET_PRINT=1
|
-DSPROCKET_PRINT=1
|
||||||
lib_deps = ${common.lib_deps}
|
lib_deps = ${common.lib_deps}
|
||||||
https://gitlab.com/wirelos/sprocket-core.git#develop
|
https://gitlab.com/wirelos/sprocket-lib.git#develop
|
||||||
@@ -8,8 +8,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "NeoPattern.cpp"
|
#include "NeoPattern.cpp"
|
||||||
#include "NeoPatternDto.h"
|
#include "NeoPatternDto.h"
|
||||||
#include <plugins/WebSO.h>
|
#include <plugins/WebServerConfig.h>
|
||||||
#include <plugins/OtaTcpPlugin.cpp>
|
|
||||||
#include <plugins/WebServerPlugin.cpp>
|
#include <plugins/WebServerPlugin.cpp>
|
||||||
#include <plugins/WebConfigPlugin.cpp>
|
#include <plugins/WebConfigPlugin.cpp>
|
||||||
#include "WebApi.cpp"
|
#include "WebApi.cpp"
|
||||||
@@ -23,26 +22,23 @@ class IlluCat : public Sprocket
|
|||||||
public:
|
public:
|
||||||
AsyncWebServer *server;
|
AsyncWebServer *server;
|
||||||
SprocketConfig sprocketConfig;
|
SprocketConfig sprocketConfig;
|
||||||
OtaConfig otaConfig;
|
|
||||||
WebServerConfig webConfig;
|
WebServerConfig webConfig;
|
||||||
|
|
||||||
IlluCat(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg) : Sprocket(cfg)
|
IlluCat(SprocketConfig cfg, WebServerConfig webCfg) : Sprocket(cfg)
|
||||||
{
|
{
|
||||||
sprocketConfig = cfg;
|
sprocketConfig = cfg;
|
||||||
otaConfig = otaCfg;
|
|
||||||
webConfig = webCfg;
|
webConfig = webCfg;
|
||||||
server = new AsyncWebServer(80);
|
server = new AsyncWebServer(80);
|
||||||
server->serveStatic(PIXEL_CONFIG_FILE, SPIFFS, "pixelConfig.json");
|
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()
|
void setup()
|
||||||
{
|
{
|
||||||
addPlugin(new PixelPlugin());
|
|
||||||
addPlugin(new WebServerPlugin(webConfig, server));
|
|
||||||
addPlugin(new WebConfigPlugin(server));
|
|
||||||
addPlugin(new WebApi(server, 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -40,7 +40,7 @@ void PixelPlugin::defaultAnimation() {
|
|||||||
animate();
|
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));
|
animation.set(TASK_MILLISECOND * pixelConfig.updateInterval, TASK_FOREVER, bind(&PixelPlugin::animate, this));
|
||||||
userScheduler->addTask(animation);
|
userScheduler->addTask(animation);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class PixelPlugin : public Plugin {
|
|||||||
void loadConfigFromFile();
|
void loadConfigFromFile();
|
||||||
void applyConfig(NeoPixelConfig cfg);
|
void applyConfig(NeoPixelConfig cfg);
|
||||||
void applyConfigFromFile();
|
void applyConfigFromFile();
|
||||||
void activate(Scheduler* userScheduler, Network* network);
|
void activate(Scheduler* userScheduler);
|
||||||
void defaultAnimation();
|
void defaultAnimation();
|
||||||
void setState(String msg);
|
void setState(String msg);
|
||||||
void colorWheel(String msg);
|
void colorWheel(String msg);
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ using namespace std::placeholders;
|
|||||||
|
|
||||||
class WebApi : public Plugin
|
class WebApi : public Plugin
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
Network *network;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AsyncWebServer *server;
|
AsyncWebServer *server;
|
||||||
@@ -28,17 +26,18 @@ class WebApi : public Plugin
|
|||||||
SprocketMessage currentMessage;
|
SprocketMessage currentMessage;
|
||||||
|
|
||||||
int broadcast;
|
int broadcast;
|
||||||
|
String broadcastTopic;
|
||||||
|
|
||||||
WebApi(AsyncWebServer *_server, int _broadcast = 0)
|
WebApi(AsyncWebServer *_server, String _broadcastTopic)
|
||||||
{
|
{
|
||||||
server = _server;
|
server = _server;
|
||||||
broadcast = _broadcast;
|
broadcast = _broadcastTopic ? 1 : 0;
|
||||||
|
broadcastTopic = _broadcastTopic;
|
||||||
Update.runAsync(true);
|
Update.runAsync(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void activate(Scheduler *_scheduler, Network *_network)
|
void activate(Scheduler *_scheduler)
|
||||||
{
|
{
|
||||||
network = _network;
|
|
||||||
ws = new AsyncWebSocket("/ws");
|
ws = new AsyncWebSocket("/ws");
|
||||||
ws->onEvent(bind(&WebApi::onWsEvent, this, _1, _2, _3, _4, _5, _6));
|
ws->onEvent(bind(&WebApi::onWsEvent, this, _1, _2, _3, _4, _5, _6));
|
||||||
server->addHandler(ws);
|
server->addHandler(ws);
|
||||||
@@ -57,7 +56,7 @@ class WebApi : public Plugin
|
|||||||
publish(currentMessage.topic, currentMessage.payload);
|
publish(currentMessage.topic, currentMessage.payload);
|
||||||
if (currentMessage.broadcast)
|
if (currentMessage.broadcast)
|
||||||
{
|
{
|
||||||
network->broadcast(msg);
|
publish(broadcastTopic, msg);
|
||||||
}
|
}
|
||||||
request->send(200, "text/plain", msg);
|
request->send(200, "text/plain", msg);
|
||||||
}
|
}
|
||||||
@@ -67,7 +66,7 @@ class WebApi : public Plugin
|
|||||||
if (type == WS_EVT_DATA)
|
if (type == WS_EVT_DATA)
|
||||||
{
|
{
|
||||||
String frame = WebUtils::parseFrameAsString(type, arg, data, len, 0);
|
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);
|
currentMessage.fromJsonString(msg);
|
||||||
if (currentMessage.valid)
|
if (currentMessage.valid)
|
||||||
{
|
{
|
||||||
currentMessage.from = from;
|
|
||||||
publish(currentMessage.topic, currentMessage.payload);
|
publish(currentMessage.topic, currentMessage.payload);
|
||||||
if (broadcast)
|
if (broadcast)
|
||||||
{
|
{
|
||||||
network->broadcast(msg);
|
publish(broadcastTopic, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,27 +2,28 @@
|
|||||||
#include "WiFiNet.h"
|
#include "WiFiNet.h"
|
||||||
#include "IlluCat.h"
|
#include "IlluCat.h"
|
||||||
|
|
||||||
WiFiNet net(
|
WiFiNet *network;
|
||||||
SPROCKET_MODE,
|
IlluCat *sprocket;
|
||||||
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 }
|
|
||||||
);
|
|
||||||
|
|
||||||
void setup() {
|
void setup()
|
||||||
sprocket.setup();
|
{
|
||||||
sprocket.join(net);
|
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() {
|
void loop()
|
||||||
sprocket.loop();
|
{
|
||||||
|
sprocket->loop();
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
#ifndef __MESHCAT__
|
|
||||||
#define __MESHCAT__
|
|
||||||
|
|
||||||
#include <TaskSchedulerDeclarations.h>
|
|
||||||
#include <MeshNet.h>
|
|
||||||
#include <SprocketConfig.h>
|
|
||||||
#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
|
|
||||||
@@ -1,25 +1,24 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "MeshNet.h"
|
#include "plugins/MeshNetworkPlugin.cpp"
|
||||||
#include "MeshCat.h"
|
#include "IlluCat.h"
|
||||||
|
|
||||||
MeshNet net({
|
IlluCat *sprocket;
|
||||||
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 }
|
|
||||||
);
|
|
||||||
|
|
||||||
void setup() {
|
void setup()
|
||||||
sprocket.setup();
|
{
|
||||||
sprocket.join(net);
|
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() {
|
void loop()
|
||||||
sprocket.loop();
|
{
|
||||||
|
sprocket->loop();
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user