Skip to content

Commit

Permalink
Resolving bootloop
Browse files Browse the repository at this point in the history
  • Loading branch information
Torxgewinde committed Jun 23, 2019
1 parent 1e5e96c commit 2ca0d67
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
10 changes: 6 additions & 4 deletions a10_globals.ino
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ void Log(String text) {
Serial.println(text);
}

#define CONFIG_FILE "/config.json"

// configuration, values are either from SPIFFS or default values
struct {
char hostname[64];
Expand All @@ -76,14 +78,14 @@ Input Value.: -
Return Value: -
******************************************************************************/
void readConfig() {
File configFile = SPIFFS.open("/config.json", "r");
File configFile = SPIFFS.open(CONFIG_FILE, "r");

StaticJsonDocument<512> root;

DeserializationError error = deserializeJson(root, configFile);

if(error)
Log("Failed to read config file /config.json from SPIFFS, using default values");
Log("Failed to read config file from SPIFFS, using default values");

strlcpy(configuration.hostname, root["hostname"] | "XIAOMI-DESK-LAMP", sizeof(configuration.hostname));
configuration.ratio = root["ratio"] | 1.0;
Expand All @@ -100,8 +102,8 @@ Input Value.: -
Return Value: -
******************************************************************************/
void writeConfig() {

File configFile = SPIFFS.open("/config.json", "w");
File configFile = SPIFFS.open(CONFIG_FILE, "w");

if (!configFile) {
Log("Could not open config file in SPIFFS");
return;
Expand Down
10 changes: 4 additions & 6 deletions a30_webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool handleFileRead(String path){
if(SPIFFS.exists(pathWithGz))
path += ".gz";
File file = SPIFFS.open(path, "r");
size_t sent = server.streamFile(file, contentType);
server.streamFile(file, contentType);
file.close();
return true;
}
Expand Down Expand Up @@ -105,8 +105,6 @@ void handleColorGET() {
root["ratio"] = g_ratio;
root["brightness"] = g_brightness;

uint8_t warmwhite, coldwhite;

root["ww"] = (int)(255 * g_ratio * g_brightness);
root["cw"] = (int)(255 * (1-g_ratio) * g_brightness);

Expand Down Expand Up @@ -215,7 +213,7 @@ void handleAllGET() {
}

/******************************************************************************
Description.: handles requests to "/config.json"
Description.: handles requests to CONFIG_FILE
if HTTP-GET parameters set new values, those are stored
it sends the contents of the file "config.json" to the HTTP-client
Input Value.: -
Expand All @@ -235,7 +233,7 @@ void handleConfigGET() {
writeConfig();
}

if(!handleFileRead("/config.json"))
if(!handleFileRead(CONFIG_FILE))
server.send(404, "text/plain", "FileNotFound");
}

Expand All @@ -256,7 +254,7 @@ void setup_webserver() {
server.on("/all", HTTP_GET, handleAllGET);
server.on("/color", HTTP_GET, handleColorGET);
server.on("/split", HTTP_GET, handleSplitGET);
server.on("/config.json", HTTP_GET, handleConfigGET);
server.on(CONFIG_FILE, HTTP_GET, handleConfigGET);

/* deleted the files present on SPIFFS file system */
server.on("/format", HTTP_GET, [](){
Expand Down
11 changes: 10 additions & 1 deletion a90_main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void setup(void){
Log("XIAOMI Desk Lamp starting up");
Log("Compiled at: " __DATE__ " - " __TIME__);

Log("initializing SPIFFS");
if( !SPIFFS.begin() ) {
Log("SPIFFS not mounted correctly, retrying...");
delay(1000);
Expand All @@ -51,6 +52,7 @@ void setup(void){
}

// read configuration file
Log("reading config from file or use default values");
readConfig();

// apply brightness and ratio from config
Expand All @@ -60,9 +62,16 @@ void setup(void){
// apply hostname
wifi_station_set_hostname(configuration.hostname);

Log("initializing LEDs");
setup_LEDs();

Log("initializing WiFi");
setup_wifi();

Log("initializing Webserver");
setup_webserver();

Log("initializing knob");
setup_knob();

state = CONSTANTCOLOR;
Expand All @@ -82,7 +91,7 @@ void loop(void) {
if(state == RESET_CONFIGURATION) {
Log("deleting configuration file /config.json");

SPIFFS.remove("/config.json");
SPIFFS.remove(CONFIG_FILE);

//keep running for ~5 more seconds, then restart
for(int i=0; i<5000; i++) {
Expand Down

0 comments on commit 2ca0d67

Please sign in to comment.