SpejsNode: add /config.json endpoint
parent
012bdd0735
commit
5879a80f48
|
@ -5,7 +5,7 @@
|
||||||
SpejsNode node("unconfigured-generic-device");
|
SpejsNode node("unconfigured-generic-device");
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
node.init();
|
node.init(true);
|
||||||
node.loadJSON({
|
node.loadJSON({
|
||||||
&OutputEndpoint::fromJSON,
|
&OutputEndpoint::fromJSON,
|
||||||
&DHTEndpoint::fromJSON,
|
&DHTEndpoint::fromJSON,
|
||||||
|
|
|
@ -164,8 +164,22 @@ void SpejsNode::onConnected() {
|
||||||
// HTTP initialization
|
// HTTP initialization
|
||||||
http.listen(80);
|
http.listen(80);
|
||||||
http.addPath("/", HttpPathDelegate(&SpejsNode::httpIndex, this));
|
http.addPath("/", HttpPathDelegate(&SpejsNode::httpIndex, this));
|
||||||
|
http.addPath("/config.json", HttpPathDelegate(&SpejsNode::httpConfig, this));
|
||||||
http.setDefaultHandler(HttpPathDelegate(&SpejsNode::httpFile, 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)
|
void SpejsNode::httpFile(HttpRequest &request, HttpResponse &response)
|
||||||
|
|
Loading…
Reference in New Issue