mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-15 17:58:20 +01:00
update endpoints
This commit is contained in:
@@ -55,55 +55,50 @@ class IlluCat : public MeshSprocket {
|
|||||||
pixelConfig.defaultColor = 100;
|
pixelConfig.defaultColor = 100;
|
||||||
|
|
||||||
}
|
}
|
||||||
// TDOO remove
|
|
||||||
virtual void scanningAnimation() {
|
virtual void scanningAnimation() {
|
||||||
pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelConfig.updateInterval);
|
pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelConfig.updateInterval);
|
||||||
//pixels->Fade(0, pixels->Color(255,255,255), 4, pixelConfig.updateInterval, FORWARD);
|
|
||||||
}
|
}
|
||||||
virtual void defaultAnimation() {
|
virtual void defaultAnimation() {
|
||||||
String defaultStr = String(defaultState.value);
|
String defaultStr = String(defaultState.value);
|
||||||
PIXEL_FNCS[defaultState.mode](pixels, defaultStr.c_str());
|
PIXEL_FNCS[defaultState.mode](pixels, defaultStr.c_str());
|
||||||
//pixels->RainbowCycle(150);
|
|
||||||
}
|
}
|
||||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
||||||
|
|
||||||
net = static_cast<MeshNet*>(network);
|
net = static_cast<MeshNet*>(network);
|
||||||
net->mesh.onNewConnection(bind(&IlluCat::onNewConnection,this, _1));
|
|
||||||
//net->mesh.onChangedConnections(bind(&IlluCat::onConnectionChanged,this));
|
|
||||||
|
|
||||||
|
// load config files from SPIFFS
|
||||||
if(SPIFFS.begin()){
|
if(SPIFFS.begin()){
|
||||||
pixelConfig.fromFile("/pixelConfig.json");
|
pixelConfig.fromFile("/pixelConfig.json");
|
||||||
defaultState.fromFile("/pixelState.json");
|
defaultState.fromFile("/pixelState.json");
|
||||||
state = defaultState;
|
state = defaultState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// initialize services
|
||||||
pixels = new NeoPattern(pixelConfig.length, pixelConfig.pin, NEO_GRB + NEO_KHZ800);
|
pixels = new NeoPattern(pixelConfig.length, pixelConfig.pin, NEO_GRB + NEO_KHZ800);
|
||||||
server = new AsyncWebServer(80);
|
server = new AsyncWebServer(80);
|
||||||
ws = new AsyncWebSocket("/pixel");
|
ws = new AsyncWebSocket("/pixel");
|
||||||
dnsServer = new DNSServer();
|
dnsServer = new DNSServer();
|
||||||
|
|
||||||
|
// add plugins
|
||||||
addPlugin(new OtaTcpPlugin(otaConfig));
|
addPlugin(new OtaTcpPlugin(otaConfig));
|
||||||
addPlugin(new WebServerPlugin(webConfig, server));
|
addPlugin(new WebServerPlugin(webConfig, server));
|
||||||
addPlugin(new WebConfigPlugin(server));
|
addPlugin(new WebConfigPlugin(server));
|
||||||
addPlugin(new PixelPlugin(pixelConfig, pixels));
|
addPlugin(new PixelPlugin(pixelConfig, pixels));
|
||||||
|
defaultAnimation();
|
||||||
|
|
||||||
|
// configure DNS
|
||||||
// TODO plugin?
|
// plugin?
|
||||||
dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
|
dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
|
||||||
dnsServer->start(DNS_PORT, "*", WiFi.softAPIP());
|
dnsServer->start(DNS_PORT, "*", WiFi.softAPIP());
|
||||||
Serial.println("SoftAP IP: " + WiFi.softAPIP().toString());
|
Serial.println("SoftAP IP: " + WiFi.softAPIP().toString());
|
||||||
|
|
||||||
defaultAnimation();
|
|
||||||
|
|
||||||
// TODO plugin
|
// TODO plugin
|
||||||
// setup web stuff
|
// setup web stuff
|
||||||
server->serveStatic("/pixelConfig.json", SPIFFS, "pixelConfig.json");
|
server->serveStatic("/pixelConfig.json", SPIFFS, "pixelConfig.json");
|
||||||
server->on("/pixel/state", HTTP_POST, bind(&IlluCat::patternWebRequestHandler, this, _1));
|
server->on("/pixel/api", HTTP_POST, bind(&IlluCat::patternWebRequestHandler, this, _1));
|
||||||
ws->onEvent(bind(&IlluCat::onWsEvent, this, _1, _2, _3, _4, _5, _6));
|
ws->onEvent(bind(&IlluCat::onWsEvent, this, _1, _2, _3, _4, _5, _6));
|
||||||
server->addHandler(ws);
|
server->addHandler(ws);
|
||||||
|
|
||||||
// FIXME OnDisable is triggered after last scan, aprx. 10 sec
|
|
||||||
// FIXME chck if this is also triggered when new connection arrives
|
|
||||||
//net->mesh.stationScan.task.setOnDisable(bind(&IlluCat::defaultAnimation,this));
|
|
||||||
return MeshSprocket::activate(scheduler, network);
|
return MeshSprocket::activate(scheduler, network);
|
||||||
} using MeshSprocket::activate;
|
} using MeshSprocket::activate;
|
||||||
|
|
||||||
@@ -130,7 +125,7 @@ class IlluCat : public MeshSprocket {
|
|||||||
String frame = WsUtils::parseFrameAsString(type, arg, data, len, 0);
|
String frame = WsUtils::parseFrameAsString(type, arg, data, len, 0);
|
||||||
net->mesh.sendBroadcast(frame);
|
net->mesh.sendBroadcast(frame);
|
||||||
dispatch(0, frame);
|
dispatch(0, frame);
|
||||||
client->text(String(millis()));
|
//client->text(String(millis()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,20 +138,6 @@ class IlluCat : public MeshSprocket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void onNewConnection(uint32_t nodeId){
|
|
||||||
PRINT_MSG(Serial, SPROCKET_TYPE, "connected to %u", nodeId);
|
|
||||||
// publish current state to new node
|
|
||||||
// TODO broadcast enable/disable flag
|
|
||||||
//String stateJson = currentMessage.toJsonString();
|
|
||||||
//net->mesh.sendSingle(nodeId, stateJson);
|
|
||||||
}
|
|
||||||
//virtual void onConnectionChanged(){
|
|
||||||
// PRINT_MSG(Serial, SPROCKET_TYPE, "connection changed");
|
|
||||||
// //if(!net->mesh.getNodeList().size()){
|
|
||||||
// // defaultAnimation();
|
|
||||||
// //}
|
|
||||||
//}
|
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
MeshSprocket::loop();
|
MeshSprocket::loop();
|
||||||
dnsServer->processNextRequest();
|
dnsServer->processNextRequest();
|
||||||
|
|||||||
@@ -40,9 +40,15 @@ class PixelPlugin : public Plugin {
|
|||||||
animation.enable();
|
animation.enable();
|
||||||
Serial.println("NeoPixels activated");
|
Serial.println("NeoPixels activated");
|
||||||
}
|
}
|
||||||
// TODO set the whole pixel state
|
|
||||||
void setState(String msg){
|
void setState(String msg){
|
||||||
state.fromJsonString(msg);
|
state.fromJsonString(msg);
|
||||||
|
pixels->setBrightness(state.brightness);
|
||||||
|
pixels->ColorSet(state.color);
|
||||||
|
pixels->Index = 0;
|
||||||
|
pixels->Color1 = state.color;
|
||||||
|
pixels->Color2 = state.color2;
|
||||||
|
pixels->TotalSteps = state.totalSteps;
|
||||||
|
pixels->ActivePattern = (pattern) state.pattern;
|
||||||
}
|
}
|
||||||
void colorWheel(String msg){
|
void colorWheel(String msg){
|
||||||
int color = atoi(msg.c_str());
|
int color = atoi(msg.c_str());
|
||||||
|
|||||||
Reference in New Issue
Block a user