add streaming stuff

This commit is contained in:
2018-10-03 13:32:23 +02:00
parent dff8545d65
commit 9c6ec9b231
12 changed files with 413 additions and 102 deletions

View File

@@ -28,6 +28,7 @@ class IlluCat : public MeshSprocket {
NeoPatternDto state;
AsyncWebServer* server;
AsyncWebSocket* ws;
AsyncWebSocket* wsStream;
NeoPixelConfig pixelConfig;
SprocketConfig sprocketConfig;
@@ -72,6 +73,7 @@ class IlluCat : public MeshSprocket {
pixels = new NeoPattern(pixelConfig.length, pixelConfig.pin, NEO_GRB + NEO_KHZ800);
server = new AsyncWebServer(80);
ws = new AsyncWebSocket("/pixel");
wsStream = new AsyncWebSocket("/stream");
// add plugins
addPlugin(new OtaTcpPlugin(otaConfig));
@@ -89,6 +91,8 @@ class IlluCat : public MeshSprocket {
server->on("/pixel/api", HTTP_POST, bind(&IlluCat::patternWebRequestHandler, this, _1));
ws->onEvent(bind(&IlluCat::onWsEvent, this, _1, _2, _3, _4, _5, _6));
server->addHandler(ws);
wsStream->onEvent(bind(&IlluCat::onStream, this, _1, _2, _3, _4, _5, _6));
server->addHandler(wsStream);
return MeshSprocket::activate(scheduler, network);
} using MeshSprocket::activate;
@@ -101,6 +105,15 @@ class IlluCat : public MeshSprocket {
return defaultValue;
}
void onStream(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len) {
if(type == WS_EVT_DATA){
PRINT_MSG(Serial, SPROCKET_TYPE, WsUtils::parseFrameAsString(type, arg, data, len, 0).c_str());
pixels->ActivePattern = NONE;
pixels->handleStream(data, len);
}
}
void patternWebRequestHandler(AsyncWebServerRequest *request) {
PRINT_MSG(Serial, SPROCKET_TYPE, "POST /pixel/api");
currentMessage.topic = getRequestParameterOrDefault(request, "topic", "");

View File

@@ -25,6 +25,7 @@ class PixelPlugin : public Plugin {
pixels = neoPattern;
pixels->begin();
pixels->setBrightness(pixelConfig.brightness);
}
void activate(Scheduler* userScheduler, Network* network){
subscribe("pixels/colorWheel", bind(&PixelPlugin::colorWheel, this, _1));
@@ -34,16 +35,13 @@ class PixelPlugin : public Plugin {
subscribe("pixels/totalSteps", bind(&PixelPlugin::setTotalSteps, this, _1));
subscribe("pixels/brightness", bind(&PixelPlugin::setBrightness, this, _1));
subscribe("pixels/state", bind(&PixelPlugin::setState, this, _1));
subscribe("pixels/stream", bind(&PixelPlugin::stream, this, _1));
animation.set(TASK_MILLISECOND * pixelConfig.updateInterval, TASK_FOREVER, bind(&PixelPlugin::animate, this));
userScheduler->addTask(animation);
animation.enable();
PRINT_MSG(Serial, SPROCKET_TYPE, "NeoPixels activated");
}
void stream(String msg){
// TODO handle LED byte array stream
}
void setState(String msg) {
PRINT_MSG(Serial, SPROCKET_TYPE, msg.c_str());
state.fromJsonString(msg);