From 54b0801784b5892979ab25f957892f6c776713c7 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Thu, 20 Sep 2018 21:16:44 +0200 Subject: [PATCH 01/11] change POST endpoint to accept topic and payload --- src/IlluCat.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/IlluCat.h b/src/IlluCat.h index 2eebf92..ed53462 100644 --- a/src/IlluCat.h +++ b/src/IlluCat.h @@ -97,7 +97,7 @@ class IlluCat : public MeshSprocket { // TODO plugin // setup web stuff server->serveStatic("/pixelConfig.json", SPIFFS, "pixelConfig.json"); - server->on("/pixel/pattern", HTTP_POST, bind(&IlluCat::patternWebRequestHandler, this, _1)); + server->on("/pixel/state", HTTP_POST, bind(&IlluCat::patternWebRequestHandler, this, _1)); ws->onEvent(bind(&IlluCat::onWsEvent, this, _1, _2, _3, _4, _5, _6)); server->addHandler(ws); @@ -107,13 +107,22 @@ class IlluCat : public MeshSprocket { return MeshSprocket::activate(scheduler, network); } using MeshSprocket::activate; + // TODO move to utils + String getRequestParameterOrDefault(AsyncWebServerRequest *request, String param, String defaultValue, bool isPost = true){ + if(request->hasParam(param, isPost)) { + return request->getParam(param, isPost)->value(); + } + return defaultValue; + } + void patternWebRequestHandler(AsyncWebServerRequest *request) { Serial.println("POST /pixel/state"); - if(request->hasParam("state", true)) { - String inStr = request->getParam("state", true)->value(); - dispatch(0, inStr); - } - request->send(200, "text/plain", "OK"); + currentMessage.topic = getRequestParameterOrDefault(request, "topic", ""); + currentMessage.payload = getRequestParameterOrDefault(request, "payload", ""); + String msg = currentMessage.toJsonString(); + net->mesh.sendBroadcast(msg); + publish(currentMessage.topic, currentMessage.payload); + request->send(200, "text/plain", msg); } virtual void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len) { From a52b06155971e1a8768b72904fd26696f5577a06 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Fri, 21 Sep 2018 02:00:32 +0200 Subject: [PATCH 02/11] update ui --- data/www/index.html | 2 +- data/www/styles.css | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/data/www/index.html b/data/www/index.html index 2b38b6b..6455fc8 100644 --- a/data/www/index.html +++ b/data/www/index.html @@ -5,7 +5,7 @@ ESP Kit - + diff --git a/data/www/styles.css b/data/www/styles.css index 56f95d5..91868a7 100644 --- a/data/www/styles.css +++ b/data/www/styles.css @@ -21,6 +21,13 @@ .sui > .content { padding: 16px; } +@media screen and (min-width: 968px) { + .sui > .content { + margin-right: auto; + margin-left: auto; + width: 50%; + } +} .sui label { color: #b3b2b2; } @@ -150,6 +157,9 @@ input[type=range]:focus::-ms-fill-lower { input[type=range]:focus::-ms-fill-upper { background: #0eb4bb; } +.form-row input[type="range"] { + margin-top: 12px; +} /* The switch - the box around the slider */ .switch { position: relative; @@ -274,13 +284,13 @@ form .form-row input[type="checkbox"] { transform: scale(2); } .ColorPicker { - flex: none !important; background-color: transparent; border: 0; height: 42px; width: 42px; } .sui select { + flex: 5; padding: .5em; color: #eeeeee; background: none; From 8ec41cadc6f8f4c1a2912ff87d64b9ee618ee33f Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Fri, 21 Sep 2018 02:01:59 +0200 Subject: [PATCH 03/11] set page title --- data/www/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/www/index.html b/data/www/index.html index 6455fc8..b119527 100644 --- a/data/www/index.html +++ b/data/www/index.html @@ -2,7 +2,7 @@ - ESP Kit + Illu-Cat From 8b26e8044bca1eff5925b96bf28ebd6fe9836adb Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sun, 23 Sep 2018 15:05:41 +0200 Subject: [PATCH 04/11] update api docs --- README.md | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index b93a14a..da251d6 100644 --- a/README.md +++ b/README.md @@ -2,42 +2,47 @@ This is the brain of the the almighty [Illumination Cat](https://www.thingiverse.com/thing:2974862). ## API +Two API architectures are supported: WebSocket and REST. +Both can be used with the same set of fields. +Everything is propagated to the mesh network automatically. + +Fields: +| Field | Type | Description | +| ------- | ------- | -----------------------------------------------| +| topic | String | Name of the topic where the data is dispatched | +| payload | Integer/String | Data | + ### WebSocket Endpoint: /pixel - -Fields: -|Field|Type|Description| -| --- |---| ---| -| topic | String | Defines which functionality is executed, usually to set a value or activate a pattern | -| payload | String | data to be set | +Send a JSON String containing the mandatory fields. Example: ``` json { "topic": "pixels/color", - "payload": "13505813" + "payload": 13505813 } ``` #### Topics -| Topic | Data | -| ----- | ---- | -| pixels/color | | -| pixels/color2 | | -| pixels/pattern | | -| pixels/totalSteps | | -| pixels/brightness | | +All functionality can be used by sending messages to these topics. + +| topic | type | payload | +| ----- | ---- | ---- | +| pixels/colorWheel | Integer | Value from 0 to 255 to cycle through all colors | +| pixels/color | Integer | RGB color as integer. By calling this topic, all LEDs of the strip are set synchronously, stopping current running animation. | +| pixels/color2 | Integer |RGB color as integer. Sets the second color used in animations. Does not stop current running animation. | +| pixels/pattern | Integer | Value from 0 to 5 to set the current animation. Available animations: { NONE = 0, RAINBOW_CYCLE = 1, THEATER_CHASE = 2, COLOR_WIPE = 3, SCANNER = 4, FADE = 5 } | +| pixels/totalSteps | Integer | Number of steps of an animation. | +| pixels/brightness | Integer | Integer from 0 to 255 to set the overall brightness of the strip by bitshifting the current colors in memory. Use with caution as running the LEDs on full brightness requires a lot of power. | ### REST #### Endpoints -POST /pixel/state -POST /config - -### Mesh - +Content-Type: application/x-www-form-urlencoded +POST /pixel/api + ## Features - Enduser setup: initial setup where the cat opens an access point for configuration - WiFi: connect to existing AP as client or build a mesh network where all cats act as a collective - Web controls: colors and patterns can be changed through the web interface - OTA plugin: cats connected to an AP can be updated over-the-air via TCP flash method -- [0%] audio output -- [0%] OctoPrint plugin: connect to an OctoPrint instance and reflect print status via colors \ No newline at end of file +- [0%] audio output \ No newline at end of file From 7e632eb89bec680f0e2999a7a8a2645b32ff953a Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sun, 23 Sep 2018 15:05:54 +0200 Subject: [PATCH 05/11] update endpoints --- src/IlluCat.h | 37 +++++++++---------------------------- src/PixelPlugin.h | 8 +++++++- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/IlluCat.h b/src/IlluCat.h index ed53462..c4980be 100644 --- a/src/IlluCat.h +++ b/src/IlluCat.h @@ -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(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(); diff --git a/src/PixelPlugin.h b/src/PixelPlugin.h index dfd7f70..1e4ae5c 100644 --- a/src/PixelPlugin.h +++ b/src/PixelPlugin.h @@ -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()); From 196df0b4ee3bc6b95dbad505c4d390d3a4bd02e3 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sun, 23 Sep 2018 21:54:23 +0200 Subject: [PATCH 06/11] separate documentation --- README.md | 53 +++++++---------------------------------------------- api.md | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 46 deletions(-) create mode 100644 api.md diff --git a/README.md b/README.md index da251d6..c6e6823 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,9 @@ # Illumination-Cat -This is the brain of the the almighty [Illumination Cat](https://www.thingiverse.com/thing:2974862). +This is the brain of the the almighty Illumination-Cat. -## API -Two API architectures are supported: WebSocket and REST. -Both can be used with the same set of fields. -Everything is propagated to the mesh network automatically. - -Fields: -| Field | Type | Description | -| ------- | ------- | -----------------------------------------------| -| topic | String | Name of the topic where the data is dispatched | -| payload | Integer/String | Data | - -### WebSocket -Endpoint: /pixel -Send a JSON String containing the mandatory fields. - -Example: -``` json -{ - "topic": "pixels/color", - "payload": 13505813 -} -``` -#### Topics -All functionality can be used by sending messages to these topics. - -| topic | type | payload | -| ----- | ---- | ---- | -| pixels/colorWheel | Integer | Value from 0 to 255 to cycle through all colors | -| pixels/color | Integer | RGB color as integer. By calling this topic, all LEDs of the strip are set synchronously, stopping current running animation. | -| pixels/color2 | Integer |RGB color as integer. Sets the second color used in animations. Does not stop current running animation. | -| pixels/pattern | Integer | Value from 0 to 5 to set the current animation. Available animations: { NONE = 0, RAINBOW_CYCLE = 1, THEATER_CHASE = 2, COLOR_WIPE = 3, SCANNER = 4, FADE = 5 } | -| pixels/totalSteps | Integer | Number of steps of an animation. | -| pixels/brightness | Integer | Integer from 0 to 255 to set the overall brightness of the strip by bitshifting the current colors in memory. Use with caution as running the LEDs on full brightness requires a lot of power. | - -### REST -#### Endpoints -Content-Type: application/x-www-form-urlencoded -POST /pixel/api - -## Features -- Enduser setup: initial setup where the cat opens an access point for configuration -- WiFi: connect to existing AP as client or build a mesh network where all cats act as a collective -- Web controls: colors and patterns can be changed through the web interface -- OTA plugin: cats connected to an AP can be updated over-the-air via TCP flash method -- [0%] audio output \ No newline at end of file +## Resources & Documentation +[3D Model](https://www.thingiverse.com/thing:2974862) +[Installation](https://gitlab.com/0x1d/illucat/blob/master/installation.md) +[API](https://gitlab.com/0x1d/illucat/blob/master/api.md) +[OctoPrint Stuff](https://github.com/FrYakaTKoP/simple-octo-ws2812) + diff --git a/api.md b/api.md new file mode 100644 index 0000000..2508b9f --- /dev/null +++ b/api.md @@ -0,0 +1,40 @@ +# API +Two API architectures are supported: WebSocket and REST. +Both can be used with the same set of fields. +Everything is propagated to the mesh network automatically. + +Fields: +| Field | Type | Description | +| ------- | ------- | -----------------------------------------------| +| topic | String | Name of the topic where the data is dispatched | +| payload | Integer/String | Data | + +## Topics +All functionality can be used by sending messages to these topics. + +| topic | type | payload | +| ----- | ---- | ---- | +| pixels/colorWheel | Integer | Value from 0 to 255 to cycle through all colors | +| pixels/color | Integer | RGB color as integer. By calling this topic, all LEDs of the strip are set synchronously, stopping current running animation. | +| pixels/color2 | Integer |RGB color as integer. Sets the second color used in animations. Does not stop current running animation. | +| pixels/pattern | Integer | Value from 0 to 5 to set the current animation. Available animations: { NONE = 0, RAINBOW_CYCLE = 1, THEATER_CHASE = 2, COLOR_WIPE = 3, SCANNER = 4, FADE = 5 } | +| pixels/totalSteps | Integer | Number of steps of an animation. | +| pixels/brightness | Integer | Integer from 0 to 255 to set the overall brightness of the strip by bitshifting the current colors in memory. Use with caution as running the LEDs on full brightness requires a lot of power. | + +## WebSocket +Endpoint: /pixel +Send a JSON String containing the mandatory fields. + +Example: +``` json +{ + "topic": "pixels/color", + "payload": 13505813 +} +``` + +## REST +#### Endpoints +Content-Type: application/x-www-form-urlencoded +POST /pixel/api + \ No newline at end of file From 403c6ec86c7077addaf81b2be7edbd3fbafb9a07 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sun, 23 Sep 2018 21:55:53 +0200 Subject: [PATCH 07/11] separate documentation --- api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.md b/api.md index 2508b9f..8f7ccdc 100644 --- a/api.md +++ b/api.md @@ -5,7 +5,7 @@ Everything is propagated to the mesh network automatically. Fields: | Field | Type | Description | -| ------- | ------- | -----------------------------------------------| +| ------- | -------------- | -----------------------------------------------| | topic | String | Name of the topic where the data is dispatched | | payload | Integer/String | Data | From d01a8ab8c52b304ba2427f9caae1b0876e992106 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sun, 23 Sep 2018 21:57:02 +0200 Subject: [PATCH 08/11] separate documentation --- api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.md b/api.md index 8f7ccdc..507bf3f 100644 --- a/api.md +++ b/api.md @@ -5,7 +5,7 @@ Everything is propagated to the mesh network automatically. Fields: | Field | Type | Description | -| ------- | -------------- | -----------------------------------------------| +| ------- | -------------- | ---------------------------------------------- | | topic | String | Name of the topic where the data is dispatched | | payload | Integer/String | Data | From 2dcbf22b093f5ad83cf8a14e35919902a682634b Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sun, 23 Sep 2018 20:01:30 +0000 Subject: [PATCH 09/11] Update api.md --- api.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/api.md b/api.md index 507bf3f..01187bf 100644 --- a/api.md +++ b/api.md @@ -4,11 +4,9 @@ Both can be used with the same set of fields. Everything is propagated to the mesh network automatically. Fields: -| Field | Type | Description | -| ------- | -------------- | ---------------------------------------------- | -| topic | String | Name of the topic where the data is dispatched | -| payload | Integer/String | Data | - +- topic +- payload + ## Topics All functionality can be used by sending messages to these topics. From 4c49d2660ed4262a59257fb25601546f0e72d19c Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Mon, 24 Sep 2018 07:18:18 +0000 Subject: [PATCH 10/11] Update api.md --- api.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api.md b/api.md index 01187bf..0635ace 100644 --- a/api.md +++ b/api.md @@ -1,9 +1,8 @@ # API Two API architectures are supported: WebSocket and REST. Both can be used with the same set of fields. -Everything is propagated to the mesh network automatically. - -Fields: +Everything is propagated to the mesh network automatically. +As everything can be controlled with topics, only two fields are required: - topic - payload @@ -35,4 +34,6 @@ Example: #### Endpoints Content-Type: application/x-www-form-urlencoded POST /pixel/api +Request: Form post with topic and payload as fields +Response: 200 + JSON message that was used to notify the topics \ No newline at end of file From 88558532ee48f3ee44c55ce3b7a7d84e9cfa889f Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Mon, 24 Sep 2018 12:10:09 +0200 Subject: [PATCH 11/11] optimize printing, add release profile --- .vscode/settings.json | 4 ++- api.md | 43 +++++++++++++++++++++++++++--- lib/sprocket-utils/utils_print.cpp | 2 +- platformio.ini | 29 +++++++++++++------- src/IlluCat.h | 18 ++++++++----- src/PixelPlugin.h | 4 +-- 6 files changed, 76 insertions(+), 24 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index feb10db..c61cd55 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,6 +13,8 @@ "deque": "cpp", "list": "cpp", "unordered_map": "cpp", - "vector": "cpp" + "vector": "cpp", + "tuple": "cpp", + "utility": "cpp" } } \ No newline at end of file diff --git a/api.md b/api.md index 0635ace..cd74ef9 100644 --- a/api.md +++ b/api.md @@ -1,10 +1,18 @@ # API Two API architectures are supported: WebSocket and REST. Both can be used with the same set of fields. -Everything is propagated to the mesh network automatically. -As everything can be controlled with topics, only two fields are required: +As everything can be controlled with topics, only a few fields are required: +| Field | Type | Description | +| ----- | ---- | ---- | +| topic | String | Topic where the payload is dispatched | +| payload | String | Payload to be dispatched | +| broadcast | Integer | Where to send the payload; 0 = local, 1 = broadcast | + + + - topic - payload +- broadcast ## Topics All functionality can be used by sending messages to these topics. @@ -35,5 +43,32 @@ Example: Content-Type: application/x-www-form-urlencoded POST /pixel/api Request: Form post with topic and payload as fields -Response: 200 + JSON message that was used to notify the topics - \ No newline at end of file +Response: 200 + final payload as JSON + +Examples: +```shell +# set color by wheel +curl -v -X POST \ + --data "topic=pixels/colorWheel" \ + --data "payload=20" \ + http://illucat/pixel/api + +# set color only on current node +curl -v -X POST \ + --data "topic=pixels/colorWheel" \ + --data "payload=20" \ + --data "broadcast=1"\ + http://illucat/pixel/api + +# set brightness +curl -v -X POST \ + --data "topic=pixels/brightness" \ + --data "payload=10" \ + http://illucat/pixel/api + +# run rainbow pattern +curl -v -X POST \ + --data "topic=pixels/pattern" \ + --data "payload=1" \ + http://illucat/pixel/api +``` \ No newline at end of file diff --git a/lib/sprocket-utils/utils_print.cpp b/lib/sprocket-utils/utils_print.cpp index 20425ee..81fe4b2 100644 --- a/lib/sprocket-utils/utils_print.cpp +++ b/lib/sprocket-utils/utils_print.cpp @@ -20,6 +20,6 @@ void PRINT_MSG(Print &out, const char* prefix, const char* format, ...) { vsnprintf(ptr, sizeof(formatString)-1-strlen(formatString), formatString, args ); va_end (args); formatString[ sizeof(formatString)-1 ]='\0'; - out.print(ptr); + out.println(ptr); } } \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 04877fb..13300eb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -22,6 +22,13 @@ lib_deps = ESPAsyncTCP TaskScheduler SPIFFS + painlessMesh + ESP8266mDNS + ArduinoOTA + ArduinoJson + ESP Async WebServer + ESPAsyncTCP + Adafruit NeoPixel [env:build] platform = ${common.platform} @@ -30,13 +37,17 @@ upload_speed = ${common.upload_speed} monitor_baud = ${common.monitor_baud} framework = ${common.framework} build_flags = -Wl,-Teagle.flash.4m1m.ld -;lib_extra_dirs = ~/src/illucat/.piolibdeps/sprocket-core/lib + -DSPROCKET_PRINT=1 lib_deps = ${common.lib_deps} - painlessMesh - ESP8266mDNS - ArduinoOTA - ArduinoJson - ESP Async WebServer - ESPAsyncTCP - Adafruit NeoPixel - https://gitlab.com/wirelos/sprocket-core.git#develop \ No newline at end of file + https://gitlab.com/wirelos/sprocket-core.git#develop + +[env:release] +platform = ${common.platform} +board = ${common.board} +upload_speed = ${common.upload_speed} +monitor_baud = ${common.monitor_baud} +framework = ${common.framework} +build_flags = -Wl,-Teagle.flash.4m1m.ld + -DSPROCKET_PRINT=0 +lib_deps = ${common.lib_deps} + https://gitlab.com/wirelos/sprocket-core.git#master \ No newline at end of file diff --git a/src/IlluCat.h b/src/IlluCat.h index c4980be..b1b010a 100644 --- a/src/IlluCat.h +++ b/src/IlluCat.h @@ -90,9 +90,10 @@ class IlluCat : public MeshSprocket { // plugin? dnsServer->setErrorReplyCode(DNSReplyCode::NoError); dnsServer->start(DNS_PORT, "*", WiFi.softAPIP()); - Serial.println("SoftAP IP: " + WiFi.softAPIP().toString()); + String softApPrt = "SoftAP IP: " + WiFi.softAPIP().toString(); + PRINT_MSG(Serial, SPROCKET_TYPE, softApPrt.c_str()); - // TODO plugin + // TODO move to plugin // setup web stuff server->serveStatic("/pixelConfig.json", SPIFFS, "pixelConfig.json"); server->on("/pixel/api", HTTP_POST, bind(&IlluCat::patternWebRequestHandler, this, _1)); @@ -111,30 +112,33 @@ class IlluCat : public MeshSprocket { } void patternWebRequestHandler(AsyncWebServerRequest *request) { - Serial.println("POST /pixel/state"); + PRINT_MSG(Serial, SPROCKET_TYPE, "POST /pixel/api"); currentMessage.topic = getRequestParameterOrDefault(request, "topic", ""); currentMessage.payload = getRequestParameterOrDefault(request, "payload", ""); + currentMessage.broadcast = atoi(getRequestParameterOrDefault(request, "broadcast", "0").c_str()); String msg = currentMessage.toJsonString(); - net->mesh.sendBroadcast(msg); publish(currentMessage.topic, currentMessage.payload); + if(currentMessage.broadcast){ + net->mesh.sendBroadcast(msg); + } request->send(200, "text/plain", msg); } 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); - net->mesh.sendBroadcast(frame); dispatch(0, frame); - //client->text(String(millis())); } } virtual void dispatch( uint32_t from, String &msg ) { - //Serial.println(msg); currentMessage.fromJsonString(msg); if(currentMessage.valid){ currentMessage.from = from; publish(currentMessage.topic, currentMessage.payload); + if(currentMessage.broadcast){ + net->mesh.sendBroadcast(msg); + } } } diff --git a/src/PixelPlugin.h b/src/PixelPlugin.h index 1e4ae5c..7c7cc16 100644 --- a/src/PixelPlugin.h +++ b/src/PixelPlugin.h @@ -38,9 +38,9 @@ class PixelPlugin : public Plugin { animation.set(TASK_MILLISECOND * pixelConfig.updateInterval, TASK_FOREVER, bind(&PixelPlugin::animate, this)); userScheduler->addTask(animation); animation.enable(); - Serial.println("NeoPixels activated"); + PRINT_MSG(Serial, SPROCKET_TYPE, "NeoPixels activated"); } - void setState(String msg){ + void setState(String msg) { state.fromJsonString(msg); pixels->setBrightness(state.brightness); pixels->ColorSet(state.color);