mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-16 10:04:30 +01:00
add library json
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "NeoPattern_api_json.h"
|
||||
#include "NeoPattern_api_modes.cpp"
|
||||
#include "utils_print.h"
|
||||
#include "utils_ws.h"
|
||||
#include <plugins/WebSO.h>
|
||||
#include <plugins/OtaTcpPlugin.cpp>
|
||||
#include <plugins/WebServerPlugin.cpp>
|
||||
@@ -27,7 +28,8 @@ class IlluCat : public MeshSprocket {
|
||||
NeoPatternDto state;
|
||||
Task animation;
|
||||
AsyncWebServer* server;
|
||||
|
||||
AsyncWebSocket* ws;
|
||||
|
||||
NeoPixelConfig pixelConfig;
|
||||
SprocketConfig sprocketConfig;
|
||||
OtaConfig otaConfig;
|
||||
@@ -68,18 +70,39 @@ class IlluCat : public MeshSprocket {
|
||||
}
|
||||
pixels = new NeoPattern(pixelConfig.length, pixelConfig.pin, NEO_GRB + NEO_KHZ800);
|
||||
server = new AsyncWebServer(80);
|
||||
ws = new AsyncWebSocket("/pixel");
|
||||
ws->onEvent([=](AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
|
||||
this->onWsEvent(server, client, type, arg, data, len);
|
||||
});
|
||||
addPlugin(new OtaTcpPlugin(otaConfig));
|
||||
addPlugin(new WebServerPlugin(webConfig, server));
|
||||
addPlugin(new WebConfigPlugin(server));
|
||||
addPlugin(new PixelPlugin(pixelConfig, pixels));
|
||||
|
||||
scanningAnimation();
|
||||
|
||||
server->addHandler(ws);
|
||||
server->on("/pixel/pattern", HTTP_GET, [this](AsyncWebServerRequest *request){
|
||||
Serial.println("POST /pixel/pattern");
|
||||
if(request->hasParam("state", true)) {
|
||||
String inStr = request->getParam("state", true)->value();
|
||||
onMessage(0, inStr);
|
||||
}
|
||||
request->send(200, "text/plain", "OK");
|
||||
});
|
||||
// FIXME OnDisable is triggered after last scan, aprx. 10 sec
|
||||
net->mesh.stationScan.task.setOnDisable(bind(&IlluCat::defaultAnimation,this));
|
||||
return MeshSprocket::activate(scheduler, network);
|
||||
} using MeshSprocket::activate;
|
||||
|
||||
void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len) {
|
||||
if(type == WS_EVT_DATA){
|
||||
String frame = WsUtils::parseFrameAsString(type, arg, data, len, 0);
|
||||
onMessage(0, frame);
|
||||
net->mesh.sendBroadcast(frame);
|
||||
client->text(String(millis()));
|
||||
}
|
||||
}
|
||||
|
||||
void onMessage( uint32_t from, String &msg ) {
|
||||
PRINT_MSG(Serial, SPROCKET_TYPE, "msg from %u = %s\n", from, msg.c_str());
|
||||
state.fromJsonString(msg);
|
||||
|
||||
Reference in New Issue
Block a user