-
-
Save jpmens/d674114400c1dd7ba169403afb7d1ea1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ArduinoJson.h> | |
#include "FS.h" | |
bool saveConfig() | |
{ | |
StaticJsonBuffer < 1050 > jsonBuffer; | |
JsonObject & json = jsonBuffer.createObject(); | |
json["name"] = "Livingroom bookshelf"; | |
JsonObject & wifi = json.createNestedObject("wifi"); | |
wifi["ssid"] = "......."; | |
wifi["password"] = "......."; | |
JsonObject & mqtt = json.createNestedObject("mqtt"); | |
mqtt["host"] = "tiggr.ww.mens.de"; | |
mqtt["port"] = 1883; | |
mqtt["ssl"] = false; | |
mqtt["auth"] = true; | |
mqtt["username"] = "..."; | |
mqtt["password"] = "..."; | |
mqtt["base_topic"] = "sensors/homie/"; | |
JsonObject & ota = json.createNestedObject("ota"); | |
ota["enabled"] = true; | |
ota["ssl"] = false; | |
ota["host"] = "192.168.1.130"; | |
ota["port"] = 80; | |
ota["path"] = "/ota"; | |
json.printTo(Serial); | |
File configFile = SPIFFS.open("/homie/config.json", "w"); | |
if (!configFile) { | |
Serial.println("Failed to open config file for writing"); | |
return false; | |
} | |
json.printTo(configFile); | |
return true; | |
} | |
void setup() | |
{ | |
Serial.begin(115200); | |
Serial.println(""); | |
delay(1000); | |
Serial.println("Mounting FS..."); | |
//SPIFFS.format(); | |
if (!SPIFFS.begin()) { | |
Serial.println("Failed to mount file system"); | |
return; | |
} | |
saveConfig(); | |
} | |
void loop() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment