mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-14 17:35:22 +01:00
adapt to new sprocket api
This commit is contained in:
@@ -12,10 +12,6 @@
|
||||
|
||||
<body class="sui">
|
||||
<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">
|
||||
<span class="heading">Pixels</span>
|
||||
<div class="content">
|
||||
|
||||
@@ -29,6 +29,7 @@ lib_deps =
|
||||
ESP Async WebServer
|
||||
ESPAsyncTCP
|
||||
Adafruit NeoPixel
|
||||
PubSubClient
|
||||
|
||||
[env:build]
|
||||
src_filter = +<*> -<wifiMesh/> +<wifi/>
|
||||
@@ -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 = +<*> -<wifiMesh/> +<wifi/>
|
||||
@@ -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
|
||||
https://gitlab.com/wirelos/sprocket-lib.git#develop
|
||||
@@ -8,8 +8,7 @@
|
||||
#include "config.h"
|
||||
#include "NeoPattern.cpp"
|
||||
#include "NeoPatternDto.h"
|
||||
#include <plugins/WebSO.h>
|
||||
#include <plugins/OtaTcpPlugin.cpp>
|
||||
#include <plugins/WebServerConfig.h>
|
||||
#include <plugins/WebServerPlugin.cpp>
|
||||
#include <plugins/WebConfigPlugin.cpp>
|
||||
#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
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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 "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();
|
||||
}
|
||||
Reference in New Issue
Block a user