SpejsNode: add /config.json endpoint

settings
informatic 2019-05-08 14:25:47 +02:00
parent 012bdd0735
commit 5879a80f48
2 changed files with 15 additions and 1 deletions

View File

@ -5,7 +5,7 @@
SpejsNode node("unconfigured-generic-device");
void init() {
node.init();
node.init(true);
node.loadJSON({
&OutputEndpoint::fromJSON,
&DHTEndpoint::fromJSON,

View File

@ -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)