[GH-ISSUE #864] After "opened config file" {}failed to load json config #727

Open
opened 2026-02-28 01:26:47 +03:00 by kerem · 0 comments
Owner

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:

  • Master
  • [x ] Development

Esp8266/Esp32:

  • [ x] ESP8266
  • ESP32

Hardware: ESP-12e, esp01, esp25

  • [x ] ESP01
  • ESP12 E/F/S (nodemcu, wemos, feather)
  • Other

ESP Core Version: 2.4.0, staging

  • [? ] 2.3.0
  • 2.4.0
  • staging (master/dev)

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;

  // put your setup code here, to run once:
  Serial.begin(115200);

 

  //clean FS, for testing
  //SPIFFS.format();

  //read configuration from FS json
  Serial.println("mounting FS...");

  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]);

              configFile.readBytes(buf.get(), size);
              DynamicJsonBuffer jsonBuffer;
              JsonObject& json = jsonBuffer.parseObject(buf.get());
              json.printTo(Serial);
              if (json.success())                                        //NO GO
              {
                  Serial.println("\nparsed json");

                  strcpy(defaultHost, json["defaultHost"]);
                  strcpy(apiKey, json["apiKey"]);
              }
              else
              {
                  Serial.println("failed to load json config");            //GET THIS MESSAGE
              }
          }
      }
  }
  else    
  {
      Serial.println("failed to mount FS");
  }
  //end read

// 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);

  //WiFiManager
  //Local intialization. Once its business is done, there is no need to keep it around
  //WiFiManager wifiManager;

  //set config save notify callback
  wifiManager.setSaveConfigCallback(saveConfigCallback);

  //add all your parameters here
  wifiManager.addParameter(&customHostServer);
  wifiManager.addParameter(&customAPIKey);

  //reset settings - for testing
  //wifiManager.resetSettings();

  //set minimu quality of signal so it ignores AP's under that quality
  //defaults to 8%
  //wifiManager.setMinimumSignalQuality();

  //sets timeout until configuration portal gets turned off
  //useful to make it all retry or go to sleep
  //in seconds
  //wifiManager.setTimeout(120);

  //fetches ssid and pass and tries to connect
  //if it does not connect it starts an access point with the specified name
  //here  "AutoConnectAP"
  //and goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect("AutoConnectAP", "password"))
  {
      Serial.println("failed to connect and hit timeout");
      delay(3000);
      //reset and try again, or maybe put it to deep sleep
      ESP.reset();
      delay(5000);
  }

  //if you get here you have connected to the WiFi
  Serial.println("connected...yeey :)");

  //read updated parameters
  strcpy(defaultHost, customHostServer.getValue());
  strcpy(apiKey, customAPIKey.getValue());

  //save the custom parameters to FS
  if (shouldSaveConfig)
  {
      Serial.println("saving config");
      DynamicJsonBuffer jsonBuffer;
      JsonObject& json = jsonBuffer.createObject();
      json["defaultHost"] = defaultHost;
      json["apiKey"] = apiKey;

      File configFile = SPIFFS.open("/config.json", "w");
      if (!configFile)
      {
          Serial.println("failed to open config file for writing");
      }

      json.printTo(Serial);
      json.printTo(configFile);
      configFile.close();
      //end save
  }

  Serial.println("local ip");
  Serial.println(WiFi.localIP());

}

//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]);

              configFile.readBytes(buf.get(), size);
              DynamicJsonBuffer jsonBuffer;
              JsonObject& json = jsonBuffer.parseObject(buf.get());
              json.printTo(Serial);
              if (json.success())                                                             //NO GO
              {
                  Serial.println("\nparsed json");

                  strcpy(defaultHost, json["defaultHost"]);
                  strcpy(apiKey, json["apiKey"]);
                
              }
              else
              {
                  Serial.println("failed to load json config");                  PRINTS THIS
              }
          }
      }
  }
  else    
  {
      Serial.println("failed to mount FS");
  }

const int waterInPin = 2;  // Analog input pin that the potentiometer is attached to
const int BatteryInPin = 1;  // Analog input pin that the potentiometer is attached to
int waterSensorInValue;//reading our water lever sensor

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);

itt = waterSensorInValue;
itt2 = BatterySensorInValue;

 if (client.connect(defaultHost,80))
  { // "184.106.153.149" or api.thingspeak.com
      //Replace with a sensor reading or something useful
      String postStr = apiKey;
      postStr +="&field1=";
      postStr += String(itt);
      postStr +="&field2=";
      postStr += String(itt2);
      postStr += "\r\n\r\n\r\n";
     client.print("POST /update HTTP/1.1\n");
      client.print("Host: api.thingspeak.com\n");
      client.print("Connection: close\n");
      client.print("X-THINGSPEAKAPIKEY: "+String(apiKey)+"\n");
      client.print("Content-Type: application/x-www-form-urlencoded\n");
      client.print("Content-Length: ");
      client.print(postStr.length());
      client.print("\n\n\n");
      client.print(postStr);

Serial.println("% send to Thingspeak");
}
client.stop();
Serial.println("Waiting…");
// thingspeak needs minimum 15 sec delay between updates
delay(60000);
}

Debug Messages

messages here
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:** - [ ] Master - [x ] Development **Esp8266/Esp32:** - [ x] ESP8266 - [ ] ESP32 **Hardware: ESP-12e, esp01, esp25** - [x ] ESP01 - [ ] ESP12 E/F/S (nodemcu, wemos, feather) - [ ] Other **ESP Core Version: 2.4.0, staging** - [? ] 2.3.0 - [ ] 2.4.0 - [ ] staging (master/dev) ### 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; // put your setup code here, to run once: Serial.begin(115200); //clean FS, for testing //SPIFFS.format(); //read configuration from FS json Serial.println("mounting FS..."); 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]); configFile.readBytes(buf.get(), size); DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.parseObject(buf.get()); json.printTo(Serial); if (json.success()) //NO GO { Serial.println("\nparsed json"); strcpy(defaultHost, json["defaultHost"]); strcpy(apiKey, json["apiKey"]); } else { Serial.println("failed to load json config"); //GET THIS MESSAGE } } } } else { Serial.println("failed to mount FS"); } //end read // 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); //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around //WiFiManager wifiManager; //set config save notify callback wifiManager.setSaveConfigCallback(saveConfigCallback); //add all your parameters here wifiManager.addParameter(&customHostServer); wifiManager.addParameter(&customAPIKey); //reset settings - for testing //wifiManager.resetSettings(); //set minimu quality of signal so it ignores AP's under that quality //defaults to 8% //wifiManager.setMinimumSignalQuality(); //sets timeout until configuration portal gets turned off //useful to make it all retry or go to sleep //in seconds //wifiManager.setTimeout(120); //fetches ssid and pass and tries to connect //if it does not connect it starts an access point with the specified name //here "AutoConnectAP" //and goes into a blocking loop awaiting configuration if (!wifiManager.autoConnect("AutoConnectAP", "password")) { Serial.println("failed to connect and hit timeout"); delay(3000); //reset and try again, or maybe put it to deep sleep ESP.reset(); delay(5000); } //if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); //read updated parameters strcpy(defaultHost, customHostServer.getValue()); strcpy(apiKey, customAPIKey.getValue()); //save the custom parameters to FS if (shouldSaveConfig) { Serial.println("saving config"); DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.createObject(); json["defaultHost"] = defaultHost; json["apiKey"] = apiKey; File configFile = SPIFFS.open("/config.json", "w"); if (!configFile) { Serial.println("failed to open config file for writing"); } json.printTo(Serial); json.printTo(configFile); configFile.close(); //end save } Serial.println("local ip"); Serial.println(WiFi.localIP()); } //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]); configFile.readBytes(buf.get(), size); DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.parseObject(buf.get()); json.printTo(Serial); if (json.success()) //NO GO { Serial.println("\nparsed json"); strcpy(defaultHost, json["defaultHost"]); strcpy(apiKey, json["apiKey"]); } else { Serial.println("failed to load json config"); PRINTS THIS } } } } else { Serial.println("failed to mount FS"); } const int waterInPin = 2; // Analog input pin that the potentiometer is attached to const int BatteryInPin = 1; // Analog input pin that the potentiometer is attached to int waterSensorInValue;//reading our water lever sensor 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); itt = waterSensorInValue; itt2 = BatterySensorInValue; if (client.connect(defaultHost,80)) { // "184.106.153.149" or api.thingspeak.com //Replace with a sensor reading or something useful String postStr = apiKey; postStr +="&field1="; postStr += String(itt); postStr +="&field2="; postStr += String(itt2); postStr += "\r\n\r\n\r\n"; client.print("POST /update HTTP/1.1\n"); client.print("Host: api.thingspeak.com\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: "+String(apiKey)+"\n"); client.print("Content-Type: application/x-www-form-urlencoded\n"); client.print("Content-Length: "); client.print(postStr.length()); client.print("\n\n\n"); client.print(postStr); Serial.println("% send to Thingspeak"); } client.stop(); Serial.println("Waiting…"); // thingspeak needs minimum 15 sec delay between updates delay(60000); } ``` ``` ### Debug Messages ``` messages here ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#727
No description provided.