SpejsNode: add /config.json endpoint
parent
012bdd0735
commit
5879a80f48
|
@ -5,7 +5,7 @@
|
|||
SpejsNode node("unconfigured-generic-device");
|
||||
|
||||
void init() {
|
||||
node.init();
|
||||
node.init(true);
|
||||
node.loadJSON({
|
||||
&OutputEndpoint::fromJSON,
|
||||
&DHTEndpoint::fromJSON,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue