mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-15 01:42:22 +01:00
optimize printing, add release profile
This commit is contained in:
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -13,6 +13,8 @@
|
||||
"deque": "cpp",
|
||||
"list": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp"
|
||||
"vector": "cpp",
|
||||
"tuple": "cpp",
|
||||
"utility": "cpp"
|
||||
}
|
||||
}
|
||||
41
api.md
41
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
|
||||
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
|
||||
```
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
[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
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ 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) {
|
||||
state.fromJsonString(msg);
|
||||
|
||||
Reference in New Issue
Block a user