Created
January 16, 2016 14:16
-
-
Save sticilface/86ab4fdd2466af38342f 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 <Arduino.h> | |
#include <ESP8266WiFi.h> | |
#include <ArduinoJson.h> | |
#include <FS.h> | |
File configFile; | |
bool config_read() { | |
DynamicJsonBuffer jsonBuffer; | |
configFile = SPIFFS.open("/temp.json", "r"); | |
if (!configFile) return false; | |
size_t size = configFile.size(); | |
std::unique_ptr<char[]> buf(new char[size]); | |
configFile.readBytes(buf.get(), size); | |
JsonObject& json = jsonBuffer.parseObject(buf.get()); | |
const char* brightness = json["brightness"]; | |
Serial.print("Level: "); | |
Serial.println(brightness); | |
configFile.close(); | |
return true; | |
} | |
bool config_write() { | |
DynamicJsonBuffer jsonBuffer; | |
configFile = SPIFFS.open("/temp.json", "w"); | |
if (!configFile) return false; | |
JsonObject& json = jsonBuffer.createObject(); | |
json["brightness"] = "brightnessQ"; | |
json.printTo(configFile); | |
configFile.close(); // needed to flush | |
return true; | |
} | |
void setup() { | |
Serial.begin(115200); | |
//Serial.setDebugOutput(true); | |
// ArduinoOTA.begin(); | |
SPIFFS.begin(); | |
//delay(1000); | |
if (config_read()){ | |
Serial.println("Read worked"); | |
} else { | |
Serial.println("Read failed"); | |
} | |
if (config_write()){ | |
Serial.println("write worked"); | |
} else { | |
Serial.println("write failed"); | |
} | |
} | |
void loop() {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment