optimize printing, add release profile

This commit is contained in:
2018-09-24 12:10:09 +02:00
parent 4c49d2660e
commit 88558532ee
6 changed files with 76 additions and 24 deletions

View File

@@ -13,6 +13,8 @@
"deque": "cpp", "deque": "cpp",
"list": "cpp", "list": "cpp",
"unordered_map": "cpp", "unordered_map": "cpp",
"vector": "cpp" "vector": "cpp",
"tuple": "cpp",
"utility": "cpp"
} }
} }

43
api.md
View File

@@ -1,10 +1,18 @@
# API # API
Two API architectures are supported: WebSocket and REST. Two API architectures are supported: WebSocket and REST.
Both can be used with the same set of fields. 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 a few fields are required:
As everything can be controlled with topics, only two 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 - topic
- payload - payload
- broadcast
## Topics ## Topics
All functionality can be used by sending messages to these topics. All functionality can be used by sending messages to these topics.
@@ -35,5 +43,32 @@ Example:
Content-Type: application/x-www-form-urlencoded Content-Type: application/x-www-form-urlencoded
POST /pixel/api POST /pixel/api
Request: Form post with topic and payload as fields 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
```

View File

@@ -20,6 +20,6 @@ void PRINT_MSG(Print &out, const char* prefix, const char* format, ...) {
vsnprintf(ptr, sizeof(formatString)-1-strlen(formatString), formatString, args ); vsnprintf(ptr, sizeof(formatString)-1-strlen(formatString), formatString, args );
va_end (args); va_end (args);
formatString[ sizeof(formatString)-1 ]='\0'; formatString[ sizeof(formatString)-1 ]='\0';
out.print(ptr); out.println(ptr);
} }
} }

View File

@@ -22,6 +22,13 @@ lib_deps =
ESPAsyncTCP ESPAsyncTCP
TaskScheduler TaskScheduler
SPIFFS SPIFFS
painlessMesh
ESP8266mDNS
ArduinoOTA
ArduinoJson
ESP Async WebServer
ESPAsyncTCP
Adafruit NeoPixel
[env:build] [env:build]
platform = ${common.platform} platform = ${common.platform}
@@ -30,13 +37,17 @@ upload_speed = ${common.upload_speed}
monitor_baud = ${common.monitor_baud} monitor_baud = ${common.monitor_baud}
framework = ${common.framework} framework = ${common.framework}
build_flags = -Wl,-Teagle.flash.4m1m.ld build_flags = -Wl,-Teagle.flash.4m1m.ld
;lib_extra_dirs = ~/src/illucat/.piolibdeps/sprocket-core/lib -DSPROCKET_PRINT=1
lib_deps = ${common.lib_deps} lib_deps = ${common.lib_deps}
painlessMesh https://gitlab.com/wirelos/sprocket-core.git#develop
ESP8266mDNS
ArduinoOTA [env:release]
ArduinoJson platform = ${common.platform}
ESP Async WebServer board = ${common.board}
ESPAsyncTCP upload_speed = ${common.upload_speed}
Adafruit NeoPixel monitor_baud = ${common.monitor_baud}
https://gitlab.com/wirelos/sprocket-core.git#develop 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

View File

@@ -90,9 +90,10 @@ class IlluCat : public MeshSprocket {
// 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()); String softApPrt = "SoftAP IP: " + WiFi.softAPIP().toString();
PRINT_MSG(Serial, SPROCKET_TYPE, softApPrt.c_str());
// TODO plugin // TODO move to plugin
// setup web stuff // setup web stuff
server->serveStatic("/pixelConfig.json", SPIFFS, "pixelConfig.json"); server->serveStatic("/pixelConfig.json", SPIFFS, "pixelConfig.json");
server->on("/pixel/api", HTTP_POST, bind(&IlluCat::patternWebRequestHandler, this, _1)); server->on("/pixel/api", HTTP_POST, bind(&IlluCat::patternWebRequestHandler, this, _1));
@@ -111,30 +112,33 @@ class IlluCat : public MeshSprocket {
} }
void patternWebRequestHandler(AsyncWebServerRequest *request) { void patternWebRequestHandler(AsyncWebServerRequest *request) {
Serial.println("POST /pixel/state"); PRINT_MSG(Serial, SPROCKET_TYPE, "POST /pixel/api");
currentMessage.topic = getRequestParameterOrDefault(request, "topic", ""); currentMessage.topic = getRequestParameterOrDefault(request, "topic", "");
currentMessage.payload = getRequestParameterOrDefault(request, "payload", ""); currentMessage.payload = getRequestParameterOrDefault(request, "payload", "");
currentMessage.broadcast = atoi(getRequestParameterOrDefault(request, "broadcast", "0").c_str());
String msg = currentMessage.toJsonString(); String msg = currentMessage.toJsonString();
net->mesh.sendBroadcast(msg);
publish(currentMessage.topic, currentMessage.payload); publish(currentMessage.topic, currentMessage.payload);
if(currentMessage.broadcast){
net->mesh.sendBroadcast(msg);
}
request->send(200, "text/plain", msg); request->send(200, "text/plain", msg);
} }
virtual void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len) { virtual void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len) {
if(type == WS_EVT_DATA){ if(type == WS_EVT_DATA){
String frame = WsUtils::parseFrameAsString(type, arg, data, len, 0); String frame = WsUtils::parseFrameAsString(type, arg, data, len, 0);
net->mesh.sendBroadcast(frame);
dispatch(0, frame); dispatch(0, frame);
//client->text(String(millis()));
} }
} }
virtual void dispatch( uint32_t from, String &msg ) { virtual void dispatch( uint32_t from, String &msg ) {
//Serial.println(msg);
currentMessage.fromJsonString(msg); currentMessage.fromJsonString(msg);
if(currentMessage.valid){ if(currentMessage.valid){
currentMessage.from = from; currentMessage.from = from;
publish(currentMessage.topic, currentMessage.payload); publish(currentMessage.topic, currentMessage.payload);
if(currentMessage.broadcast){
net->mesh.sendBroadcast(msg);
}
} }
} }

View File

@@ -38,9 +38,9 @@ class PixelPlugin : public Plugin {
animation.set(TASK_MILLISECOND * pixelConfig.updateInterval, TASK_FOREVER, bind(&PixelPlugin::animate, this)); animation.set(TASK_MILLISECOND * pixelConfig.updateInterval, TASK_FOREVER, bind(&PixelPlugin::animate, this));
userScheduler->addTask(animation); userScheduler->addTask(animation);
animation.enable(); animation.enable();
Serial.println("NeoPixels activated"); PRINT_MSG(Serial, SPROCKET_TYPE, "NeoPixels activated");
} }
void setState(String msg){ void setState(String msg) {
state.fromJsonString(msg); state.fromJsonString(msg);
pixels->setBrightness(state.brightness); pixels->setBrightness(state.brightness);
pixels->ColorSet(state.color); pixels->ColorSet(state.color);