Skip to content

Instantly share code, notes, and snippets.

@0x2b3bfa0
Last active January 16, 2016 14:13
Show Gist options
  • Save 0x2b3bfa0/c804f4d8a25c87b8ac45 to your computer and use it in GitHub Desktop.
Save 0x2b3bfa0/c804f4d8a25c87b8ac45 to your computer and use it in GitHub Desktop.
Failure
#include "main.h"
void config_read() {
// configFile = SPIFFS.open("/config.json", "w+");
size_t size = configFile.size();
std::unique_ptr<char[]> buf(new char[size]);
DynamicJsonBuffer jsonBuffer;
configFile.readBytes(buf.get(), size);
JsonObject& json = jsonBuffer.parseObject(buf.get());
const char* brightness = json["brightness"];
Serial.print("Level: ");
Serial.println(brightness);
}
void config_write() {
// configFile = SPIFFS.open("/config.json", "w");
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.createObject();
json["brightness"] = "brightnessQ";
json.printTo(configFile);
}
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
// ArduinoOTA.begin();
if (!SPIFFS.begin()) { Serial.println("Failed to mount file system"); }
//delay(1000);
configFile = SPIFFS.open("/config.json", "r+");
if (!configFile) {
configFile = SPIFFS.open("/config.json", "w+");
}
config_write();
config_read();
}
void loop() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment