update endpoints

This commit is contained in:
2018-09-23 15:05:54 +02:00
parent 8b26e8044b
commit 7e632eb89b
2 changed files with 16 additions and 29 deletions

View File

@@ -55,55 +55,50 @@ class IlluCat : public MeshSprocket {
pixelConfig.defaultColor = 100;
}
// TDOO remove
virtual void scanningAnimation() {
pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelConfig.updateInterval);
//pixels->Fade(0, pixels->Color(255,255,255), 4, pixelConfig.updateInterval, FORWARD);
}
virtual void defaultAnimation() {
String defaultStr = String(defaultState.value);
PIXEL_FNCS[defaultState.mode](pixels, defaultStr.c_str());
//pixels->RainbowCycle(150);
}
Sprocket* activate(Scheduler* scheduler, Network* 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()){
pixelConfig.fromFile("/pixelConfig.json");
defaultState.fromFile("/pixelState.json");
state = defaultState;
}
// initialize services
pixels = new NeoPattern(pixelConfig.length, pixelConfig.pin, NEO_GRB + NEO_KHZ800);
server = new AsyncWebServer(80);
ws = new AsyncWebSocket("/pixel");
dnsServer = new DNSServer();
// add plugins
addPlugin(new OtaTcpPlugin(otaConfig));
addPlugin(new WebServerPlugin(webConfig, server));
addPlugin(new WebConfigPlugin(server));
addPlugin(new PixelPlugin(pixelConfig, pixels));
defaultAnimation();
// TODO plugin?
// configure DNS
// plugin?
dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
dnsServer->start(DNS_PORT, "*", WiFi.softAPIP());
Serial.println("SoftAP IP: " + WiFi.softAPIP().toString());
defaultAnimation();
// TODO plugin
// setup web stuff
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));
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);
} using MeshSprocket::activate;
@@ -130,7 +125,7 @@ class IlluCat : public MeshSprocket {
String frame = WsUtils::parseFrameAsString(type, arg, data, len, 0);
net->mesh.sendBroadcast(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(){
MeshSprocket::loop();
dnsServer->processNextRequest();

View File

@@ -40,9 +40,15 @@ class PixelPlugin : public Plugin {
animation.enable();
Serial.println("NeoPixels activated");
}
// TODO set the whole pixel state
void setState(String 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){
int color = atoi(msg.c_str());