SpejsNode: add JSON network configuration loading

settings
informatic 2019-05-08 14:26:09 +02:00
parent 5879a80f48
commit 24924811b2
2 changed files with 16 additions and 1 deletions

View File

@ -58,7 +58,21 @@ void SpejsNode::loadJSON(std::vector<EndpointInitializer> initializers) {
if (root.containsKey("name"))
deviceType = (root["name"]).asString();
JsonObject& data = root["endpoints"].asObject();
JsonArray& networks = root.get<JsonArray&>("networks");
if (networks.success() && networks.size()) {
debugf("got networks");
JsonObject& network = networks.get<JsonObject&>(0);
if (network.success() && network.containsKey("ssid")) {
debugf("Loaded JSON network configuration");
wifiSSID = network["ssid"].as<String>();
wifiPassword = network["psk"].as<String>();
} else {
debugf("invalid network configuration");
}
}
JsonObject& data = root.get<JsonObject&>("endpoints");
for (auto it: data) {
bool found = false;

View File

@ -68,6 +68,7 @@ protected:
void mqttCallback(String, String);
void otaUpdateCallback(bool result);
void httpFile(HttpRequest &request, HttpResponse &response);
void httpConfig(HttpRequest &request, HttpResponse &response);
void httpIndex(HttpRequest &request, HttpResponse &response);
void systemReady(void);