mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 00:55:52 +03:00
[GH-ISSUE #864] After "opened config file" {}failed to load json config #727
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#727
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @gbenna on GitHub (Apr 3, 2019).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/864
SERIAL OUTPUT
load 0x4010f000, len 1384, room 16
20:48:35.342 -> tail ⸮5⸮⸮⸮⸮⸮d
20:48:35.342 -> v951aeffa
20:48:35.342 -> ~ld
mounting FS...
mounted file system
20:48:35.520 -> *WM: Adding parameter
20:48:35.520 -> *WM: defaultHost
20:48:35.520 -> *WM: Adding parameter
20:48:35.520 -> *WM: apiKey
20:48:35.520 -> *WM:
20:48:35.520 -> *WM: AutoConnect
20:48:35.520 -> *WM: Connecting as wifi client...
20:48:35.520 -> *WM: Using last saved values, should be faster
20:48:35.520 -> *WM: Connection result:
20:48:35.520 -> *WM: 0
20:48:35.520 -> *WM:
20:48:35.520 -> *WM: Configuring access point...
20:48:35.520 -> *WM: AutoConnectAP
20:48:35.556 -> *WM: password
*WM: AP IP address:
20:48:36.051 -> *WM: 192.168.4.1
20:48:36.051 -> *WM: HTTP server started
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
20:48:44.006 -> *WM: Handle root
*WM: Scan done
20:48:49.184 -> *WM: DUP AP: Gary's Wi-Fi Network
20:48:49.184 -> *WM: DUP AP: Kimberlee
20:48:49.184 -> *WM: Gary's Wi-Fi Network
20:48:49.184 -> *WM: -47
20:48:49.184 -> *WM: 350
20:48:49.184 -> *WM: -74
20:48:49.184 -> *WM: Kimberlee
20:48:49.184 -> *WM: -84
20:48:49.184 -> *WM: Hayt
20:48:49.184 -> *WM: -84
20:48:49.184 -> *WM: Sent config page
*WM: Request redirected to captive portal
*WM: Handle root
*WM: WiFi save
20:49:01.362 -> *WM: Parameter
20:49:01.362 -> *WM: defaultHost
20:49:01.396 -> *WM: api.thingspeak.com
20:49:01.396 -> *WM: Parameter
20:49:01.396 -> *WM: apiKey
20:49:01.396 -> *WM: 8RXVFOW83KRZHSNL
20:49:01.396 -> *WM: Sent wifi save page
*WM: Connecting to new AP
20:49:03.386 -> *WM: Connecting as wifi client...
*WM: Connection result:
20:49:07.474 -> *WM: 3
Should save config
20:49:07.583 -> connected...yeey :)
20:49:07.583 -> saving config
20:49:07.583 -> {"defaultHost":"api.thingspeak.com","apiKey":"8RXVFOW83KRZHSNL"}local ip
20:49:07.620 -> 10.0.1.23
20:49:07.620 -> *WM: freeing allocated params!
//THIS PART REPEATS EVERY MINUTE EVEN AFTER THE POWER IS TURNED OFF AND THEN BACK ON TO THE ESP8266
20:49:07.620 -> mounted file system
20:49:07.620 -> reading config file
20:49:07.620 -> opened config file
20:49:07.620 -> {}failed to load json config
20:49:07.620 -> WaterOutValue =
20:49:07.620 -> 224
20:49:07.620 -> WaterInValue =
20:49:07.620 -> 1023
20:49:07.620 -> BatteryOutValue =
20:49:07.620 -> 0
20:49:07.620 -> BatteryInValue =
20:49:07.620 -> 0
% send to Thingspeak
Waiting…
Basic Infos
writing sketch for ESP8266 which allows user to input their own WiFi address and Password and ThingSpeak write apikey. Everything works well except when the power is disrupted to the module and restored the ESP reconnects to the WIFi, mounts the SPIFFS file system, reads config file, opens config file but fails to load the json config. So the saved write apikey file is not read and handed off to the code so it can upload to ThingSpeak. Wondering what I am doing wrong that It doesn't load the file?
Hardware
WiFimanager Branch/Release:
Esp8266/Esp32:
Hardware: ESP-12e, esp01, esp25
ESP Core Version: 2.4.0, staging
Description
Adding thingSpeak write api as custom parameter to SPIFFS
Problem description
Seems to add parameter but when trying to read file get "failed to load json config"
Settings in IDE
Board: "Generic ESP8266 Module"
UPLoad Speed:"115200"
CPU Frequency:"80MHz"
Crystal Frequency:"26 MHz"
Flash Size: 512K (32K SPIFFS)"
Flash Mode: "DOUT(compatible)"
Flash Frequency: "40 MHz"
Reset Method:"ck"
Debug port:"Disabled"
Debug Level:"None"
IwIP Variant:"v2 Lower Memory"
Tables:"Flash"
Exceptions:"Disabled"
Builtin Led:"2"
Erase Flash:"Only Sketch"
Port: "/dev/cu.usbmodem14201 (Arduino/Genuino Uno)"
Get Board Info
Programmer:"AVRISP mkII
Turn Bootloader
Module: ESP8266-01 Arduino Uno 3
Additional libraries:
#include <FS.h> //this needs to be first, or it all crashes and burns...
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
#include <ArduinoJson.h>
Sketch
char apiKey[20] = "";
WiFiClient client;
char defaultHost[100] = "api.thingspeak.com"; //Thing Speak IP address (sometime the web address causes issues with ESP's :/
long itt = 500;
long itt2 = 300;
int interruptPinDebounce = 0;
long debouncing_time = 1000; //Debouncing Time in Milliseconds
volatile unsigned long wifiResetLastMillis = 0;
//flag for saving data
bool shouldSaveConfig = false;
//callback notifying us of the need to save config
void saveConfigCallback ()
{
Serial.println("Should save config");
shouldSaveConfig = true;
}
void handleWifiReset()
{
if(millis() < wifiResetLastMillis)
{
wifiResetLastMillis = millis(); //To handle error caused by the 49 day rollover in millis
}
if( (millis() - wifiResetLastMillis) >= debouncing_time)
{
Serial.println("Clearing WiFi data resetting");
WiFiManager wifiManager;
wifiManager.resetSettings();
SPIFFS.format(); //If you change the number of wifi prams, you will need to call this or everything breaks :(
ESP.reset();
delay(1000);
}
wifiResetLastMillis = millis();
}
void setup()
{
WiFiManager wifiManager;
// The extra parameters to be configured (can be either global or just in the setup)
// After connecting, parameter.getValue() will get you the configured value
// id/name placeholder/prompt default length
WiFiManagerParameter customHostServer("defaultHost", "Host Server", defaultHost, 100);
WiFiManagerParameter customAPIKey("apiKey", "Host API Key", apiKey, 20);
}
//Loop code taken from ThingSpeak's example of HTTP Post
void loop()
{
if (SPIFFS.begin())
{
Serial.println("mounted file system"); //DOES THIS
if (SPIFFS.exists("/config.json"))
{
//file exists, reading and loading
Serial.println("reading config file"); //DOES THIS
File configFile = SPIFFS.open("/config.json", "r");
if (configFile)
{
Serial.println("opened config file"); //DOES THIS
size_t size = configFile.size();
// Allocate a buffer to store contents of the file.
std::unique_ptr<char[]> buf(new char[size]);
int waterSensorOutValue;//conversion of water sensor value
int BatterySensorInValue;//reading our water lever sensor
int BatterySensorOutValue;//conversion of water sensor value
// put your main code here, to run repeatedly:
waterSensorInValue = analogRead(waterInPin);
BatterySensorInValue = analogRead(BatteryInPin);
waterSensorOutValue = map(waterSensorInValue,0,1024,0,225);
BatterySensorOutValue = map(BatterySensorInValue,0,1024,0,225);
Serial.println("WaterOutValue = ");
Serial.println(waterSensorOutValue );
Serial.println("WaterInValue = ");
Serial.println(waterSensorInValue );
Serial.println("BatteryOutValue = ");
Serial.println(BatterySensorOutValue );
Serial.println("BatteryInValue = ");
Serial.println(BatterySensorInValue);
Serial.println("% send to Thingspeak");
}
client.stop();
Serial.println("Waiting…");
// thingspeak needs minimum 15 sec delay between updates
delay(60000);
}
Debug Messages