Skip to content

Instantly share code, notes, and snippets.

@jpmens
Created April 14, 2016 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jpmens/d674114400c1dd7ba169403afb7d1ea1 to your computer and use it in GitHub Desktop.
Save jpmens/d674114400c1dd7ba169403afb7d1ea1 to your computer and use it in GitHub Desktop.
#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