mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-16 18:05:05 +01:00
remove dns server and newConn cb
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
#include <painlessMesh.h>
|
||||
#include <base/MeshSprocket.h>
|
||||
#include <MeshNet.h>
|
||||
#include <DNSServer.h>
|
||||
|
||||
|
||||
#include "config.h"
|
||||
@@ -23,7 +22,6 @@
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
const byte DNS_PORT = 53;
|
||||
|
||||
class IlluCat : public MeshSprocket {
|
||||
public:
|
||||
@@ -32,13 +30,14 @@ class IlluCat : public MeshSprocket {
|
||||
NeoPatternDto state;
|
||||
AsyncWebServer* server;
|
||||
AsyncWebSocket* ws;
|
||||
DNSServer* dnsServer;
|
||||
|
||||
NeoPixelConfig pixelConfig;
|
||||
SprocketConfig sprocketConfig;
|
||||
OtaConfig otaConfig;
|
||||
WebServerConfig webConfig;
|
||||
|
||||
SprocketMessage currentMessage;
|
||||
|
||||
IlluCat(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg/* , NeoPixelConfig pixelCfg */) : MeshSprocket(cfg) {
|
||||
//pixelConfig = pixelCfg;
|
||||
|
||||
@@ -67,7 +66,7 @@ class IlluCat : public MeshSprocket {
|
||||
|
||||
net = static_cast<MeshNet*>(network);
|
||||
net->mesh.onNewConnection(bind(&IlluCat::onNewConnection,this, _1));
|
||||
net->mesh.onChangedConnections(bind(&IlluCat::onConnectionChanged,this));
|
||||
//net->mesh.onChangedConnections(bind(&IlluCat::onConnectionChanged,this));
|
||||
|
||||
if(SPIFFS.begin()){
|
||||
pixelConfig.fromFile("/pixelConfig.json");
|
||||
@@ -77,18 +76,12 @@ class IlluCat : public MeshSprocket {
|
||||
pixels = new NeoPattern(pixelConfig.length, pixelConfig.pin, NEO_GRB + NEO_KHZ800);
|
||||
server = new AsyncWebServer(80);
|
||||
ws = new AsyncWebSocket("/pixel");
|
||||
dnsServer = new DNSServer();
|
||||
|
||||
addPlugin(new OtaTcpPlugin(otaConfig));
|
||||
addPlugin(new WebServerPlugin(webConfig, server));
|
||||
addPlugin(new WebConfigPlugin(server));
|
||||
addPlugin(new PixelPlugin(pixelConfig, pixels));
|
||||
|
||||
|
||||
dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
|
||||
dnsServer->start(DNS_PORT, "*", WiFi.softAPIP());
|
||||
|
||||
//scanningAnimation();
|
||||
defaultAnimation();
|
||||
|
||||
// setup web stuff
|
||||
@@ -104,10 +97,10 @@ class IlluCat : public MeshSprocket {
|
||||
} using MeshSprocket::activate;
|
||||
|
||||
void patternWebRequestHandler(AsyncWebServerRequest *request) {
|
||||
Serial.println("POST /pixel/pattern");
|
||||
if(request->hasParam("state", true)) {
|
||||
String inStr = request->getParam("state", true)->value();
|
||||
onMessage(0, inStr);
|
||||
Serial.println("POST /pixel/state");
|
||||
if(request->hasParam("msg", true)) {
|
||||
String inStr = request->getParam("msg", true)->value();
|
||||
dispatch(0, inStr);
|
||||
}
|
||||
request->send(200, "text/plain", "OK");
|
||||
}
|
||||
@@ -115,41 +108,37 @@ class IlluCat : public MeshSprocket {
|
||||
virtual 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);
|
||||
NeoPatternMsg msg;
|
||||
msg.fromJsonString(frame);
|
||||
if(msg.valid){
|
||||
// TODO convert message to send to mesh
|
||||
//net->mesh.sendBroadcast(frame);
|
||||
publish(msg.topic, msg.payload);
|
||||
client->text(String(millis()));
|
||||
}
|
||||
dispatch(0, frame);
|
||||
// TODO broadcast enable/disable flag
|
||||
net->mesh.sendBroadcast(frame);
|
||||
client->text(String(millis()));
|
||||
}
|
||||
}
|
||||
|
||||
virtual void onMessage( uint32_t from, String &msg ) {
|
||||
PRINT_MSG(Serial, SPROCKET_TYPE, "msg from %u = %s\n", from, msg.c_str());
|
||||
state.fromJsonString(msg);
|
||||
PIXEL_FNCS[state.mode](pixels, state.valueStr);
|
||||
void dispatch( uint32_t from, String &msg ) {
|
||||
currentMessage.fromJsonString(msg);
|
||||
if(currentMessage.valid){
|
||||
currentMessage.from = from;
|
||||
publish(currentMessage.topic, currentMessage.payload);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void onNewConnection(uint32_t nodeId){
|
||||
PRINT_MSG(Serial, SPROCKET_TYPE, "connected to %u", nodeId);
|
||||
//defaultAnimation();
|
||||
String stateJson = state.toJsonString();
|
||||
net->mesh.sendSingle(nodeId, stateJson);
|
||||
// TODO publish current state to pixel/color on new node
|
||||
}
|
||||
virtual void onConnectionChanged(){
|
||||
PRINT_MSG(Serial, SPROCKET_TYPE, "connection changed");
|
||||
//if(!net->mesh.getNodeList().size()){
|
||||
// defaultAnimation();
|
||||
//}
|
||||
// publish current state to new node
|
||||
// FIXME we got a memory leak here
|
||||
//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();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user