From 5879a80f48f12d78b53d0d79c3bcf216a1da964d Mon Sep 17 00:00:00 2001 From: Piotr Dobrowolski Date: Wed, 8 May 2019 14:25:47 +0200 Subject: [PATCH] SpejsNode: add /config.json endpoint --- base-firmware/app/application.cpp | 2 +- spejsiot/SpejsNode.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/base-firmware/app/application.cpp b/base-firmware/app/application.cpp index 291766e..05365ca 100644 --- a/base-firmware/app/application.cpp +++ b/base-firmware/app/application.cpp @@ -5,7 +5,7 @@ SpejsNode node("unconfigured-generic-device"); void init() { - node.init(); + node.init(true); node.loadJSON({ &OutputEndpoint::fromJSON, &DHTEndpoint::fromJSON, diff --git a/spejsiot/SpejsNode.cpp b/spejsiot/SpejsNode.cpp index dd50e87..1a06bb6 100644 --- a/spejsiot/SpejsNode.cpp +++ b/spejsiot/SpejsNode.cpp @@ -164,8 +164,22 @@ void SpejsNode::onConnected() { // HTTP initialization http.listen(80); http.addPath("/", HttpPathDelegate(&SpejsNode::httpIndex, this)); + http.addPath("/config.json", HttpPathDelegate(&SpejsNode::httpConfig, this)); http.setDefaultHandler(HttpPathDelegate(&SpejsNode::httpFile, this)); + http.setBodyParser("application/json", bodyToStringParser); +} +void SpejsNode::httpConfig(HttpRequest &request, HttpResponse &response) +{ + if (request.method == HTTP_POST) { + debugf("settings data"); + String body = request.getBody(); + Serial.println(body); + fileSetContent("config.json", body); + response.sendString("{\"status\": 200}"); + } else { + response.sendFile("config.json"); + } } void SpejsNode::httpFile(HttpRequest &request, HttpResponse &response)