[GH-ISSUE #886] How to reset wifi setting #750

Closed
opened 2026-02-28 01:26:53 +03:00 by kerem · 1 comment
Owner

Originally created by @hznupeter on GitHub (May 14, 2019).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/886

Basic Infos

I want to use this library to connect to blynk, i use the example AutoConnectWithFSParameters
if I input the correct wifi ssid and passwrod ,but the blynk token is wrong . The esp8266 will connect the wifi ,but it can't connect to the Blynk server.
So, what i can do when i meet this?
i have two ways,but i dont how to do.

  1. Press a button more than 5(10) seconds ,then the wifi setting will be erased, the esp8266 need to be connect again.
  2. Use can change the blynk_token after the wifi is connected.

Hardware

WiFimanager Branch/Release:

  • Master
  • Development

Esp8266/Esp32:

  • ESP8266
  • ESP32

Hardware: ESP-12e, esp01, esp25

  • 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

Problem description

Settings in IDE

Module: NodeMcu, Wemos D1

Additional libraries: Blynk

Sketch

#define BLYNK_PRINT Serial
#include <FS.h>                   //this needs to be first, or it all crashes and burns...
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#include <BlynkSimpleEsp8266.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager
#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson
char blynk_token[34] = "YOUR_BLYNK_TOKEN";
bool shouldSaveConfig = false;
void saveConfigCallback () {
  Serial.println("Should save config");
  shouldSaveConfig = true;
}
void setup() {
  Serial.begin(115200);
  Serial.println();
  Serial.println("mounting FS...");
  if (SPIFFS.begin()) {
    Serial.println("mounted file system");
    if (SPIFFS.exists("/config.json")) {
      Serial.println("reading config file");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile) {
        Serial.println("opened config file");
        size_t size = configFile.size();
        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()) {
          Serial.println("\nparsed json");
          strcpy(blynk_token, json["blynk_token"]);
        } else {
          Serial.println("failed to load json config");
        }
        configFile.close();
      }
    }
  } else {
    Serial.println("failed to mount FS");
  }
  WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 32);
  WiFiManager wifiManager;
  wifiManager.setSaveConfigCallback(saveConfigCallback);
  wifiManager.addParameter(&custom_blynk_token);
  if (!wifiManager.autoConnect()) {
    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);
  }
  Serial.println("connected...yeey :)");
  strcpy(blynk_token, custom_blynk_token.getValue());
  if (shouldSaveConfig) {
    Serial.println("saving config");
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    json["blynk_token"] = blynk_token;
    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();
  }
  Serial.println("local ip");
  Serial.println(WiFi.localIP());
 Blynk.config(blynk_token, IPAddress(116, 62, 49, 166), 8080);
}

void loop() {
  Blynk.run();
}

Debug Messages

mounting FS...
failed to mount FS
*WM: Adding parameter
*WM: blynk
*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 3
*WM: IP Address:
*WM: 192.168.31.79
connected...yeey :)
local ip
192.168.31.79
[3425] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on ESP8266

*WM: freeing allocated params!
[3440] Connecting to 116.62.49.166
[3485] Invalid auth token
Originally created by @hznupeter on GitHub (May 14, 2019). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/886 ### Basic Infos I want to use this library to connect to blynk, i use the example [AutoConnectWithFSParameters](https://github.com/tzapu/WiFiManager/blob/master/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino) if I input the correct wifi ssid and passwrod ,but the blynk token is wrong . The esp8266 will connect the wifi ,but it can't connect to the Blynk server. So, what i can do when i meet this? i have two ways,but i dont how to do. 1. Press a button more than 5(10) seconds ,then the wifi setting will be erased, the esp8266 need to be connect again. 2. Use can change the blynk_token after the wifi is connected. #### Hardware **WiFimanager Branch/Release:** - [x] Master - [ ] Development **Esp8266/Esp32:** - [x] ESP8266 - [ ] ESP32 **Hardware: ESP-12e, esp01, esp25** - [ ] ESP01 - [x] ESP12 E/F/S (nodemcu, wemos, feather) - [ ] Other **ESP Core Version: 2.4.0, staging** - [ ] 2.3.0 - [ ] 2.4.0 - [x] staging (master/dev) ### Description Problem description ### Settings in IDE Module: NodeMcu, Wemos D1 Additional libraries: Blynk ### Sketch ```cpp #define BLYNK_PRINT Serial #include <FS.h> //this needs to be first, or it all crashes and burns... #include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino #include <BlynkSimpleEsp8266.h> #include <DNSServer.h> #include <ESP8266WebServer.h> #include <WiFiManager.h> //https://github.com/tzapu/WiFiManager #include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson char blynk_token[34] = "YOUR_BLYNK_TOKEN"; bool shouldSaveConfig = false; void saveConfigCallback () { Serial.println("Should save config"); shouldSaveConfig = true; } void setup() { Serial.begin(115200); Serial.println(); Serial.println("mounting FS..."); if (SPIFFS.begin()) { Serial.println("mounted file system"); if (SPIFFS.exists("/config.json")) { Serial.println("reading config file"); File configFile = SPIFFS.open("/config.json", "r"); if (configFile) { Serial.println("opened config file"); size_t size = configFile.size(); 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()) { Serial.println("\nparsed json"); strcpy(blynk_token, json["blynk_token"]); } else { Serial.println("failed to load json config"); } configFile.close(); } } } else { Serial.println("failed to mount FS"); } WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 32); WiFiManager wifiManager; wifiManager.setSaveConfigCallback(saveConfigCallback); wifiManager.addParameter(&custom_blynk_token); if (!wifiManager.autoConnect()) { 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); } Serial.println("connected...yeey :)"); strcpy(blynk_token, custom_blynk_token.getValue()); if (shouldSaveConfig) { Serial.println("saving config"); DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.createObject(); json["blynk_token"] = blynk_token; 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(); } Serial.println("local ip"); Serial.println(WiFi.localIP()); Blynk.config(blynk_token, IPAddress(116, 62, 49, 166), 8080); } void loop() { Blynk.run(); } ``` ### Debug Messages ``` mounting FS... failed to mount FS *WM: Adding parameter *WM: blynk *WM: *WM: AutoConnect *WM: Connecting as wifi client... *WM: Using last saved values, should be faster *WM: Connection result: *WM: 3 *WM: IP Address: *WM: 192.168.31.79 connected...yeey :) local ip 192.168.31.79 [3425] ___ __ __ / _ )/ /_ _____ / /__ / _ / / // / _ \/ '_/ /____/_/\_, /_//_/_/\_\ /___/ v0.6.1 on ESP8266 *WM: freeing allocated params! [3440] Connecting to 116.62.49.166 [3485] Invalid auth token ```
kerem closed this issue 2026-02-28 01:26:53 +03:00
Author
Owner

@tablatronix commented on GitHub (May 14, 2019):

on demand configportal example

<!-- gh-comment-id:492288671 --> @tablatronix commented on GitHub (May 14, 2019): on demand configportal example
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#750
No description provided.