Why WiFi-Manager directs to 192.168.244.1 instead of 192.168.4.1? (SOLVED)

No. Seems like my phone just made it look like it connected, but I think it only disconnected from NodeMCU`s and picked up the old WiFi from the list automatically. So… Now this ask a lot more in the WiFi-config. SSid, password, Static IP, Static Gateway, Subnet and Static DNS. And it still directs to 192.168.244.1. So when it works it should ask only SSID and Password… right?

This is really weird.

I’m sorry, I don’t really understand the question.

Usually, when people are using WifiManager with Blynk they add fields to the static portal to allow SSID, WiFi Password and Blynk Auth Code to be inputted.

They then use Blynk.begin(auth, ssid, pass); to use a DHCP allocated IP address for the device and connect to Blynk cloud.

If you need to be able to specify a static IP address for your device, as opposed to one allocated by your DHCP server (router) then you’ll need to change your code to manage your own Wi-Fi setup using something like
WiFi.config(device_ip, dns, gateway, subnet);
followed by
Blynk.config(auth, blynk_server, blynk_port);
Blynk.connect();
commands.

Maybe if you explained a little more about what exactly you’re trying to achieve, why you need to use a library like WiFiManager rather than hard-coding credentials, and sort of scenarios where your devices are likely to be used, we’d be able to give you more targeted advice.

Pete.

Well… This is a automatic hydroponic system, which checks the water level using ultrasound sensor and uses valves and pumps during watering process. Here´s part of the code, whole code is too long here… To this I´d like to include WiFi-Manager cause I´d like to make couple more of these… For my friends without profiting. But still it´s too hard to use hardcoded method here. Maybe I try with other computer… this is so strange anyway.


/**************************************************************

   Samsara Exit Hydroponics V1.0

  13.03.2019

   Hydroponics System for NodeMCU 1.0

 * ************************************************************

Blynk app Tab-1:

   V0: On-Off Button (Water Pump ON/OFF)
   V1: Value Display
   V2: On-off button (Lights Manual)
   V3: Terminal  // Label will be the clock + wifi signal
   V4: On-Off Button (Main watering ON/OFF)
   V5: On-Off Button (Water Leak Sensor ON/OFF)
   V7: Virtual LED (lights)
   V8: Segmented switch (1-Veg, 2-Bloom1, 3-Bloom2, 4-Plain Water, 5-Drain and End)
   V10: Timer - Time Input widget on V10
   V11: On-Off button (Lights Timer)

Blynk app Tab-2 (settings):

V6: Numeric Input Display (Water Capacity (Litres)
V9: Numeric Input Display (Drain Time (minutes)
V12: Numeric Input Display (Water Level Full (distance from the sensor cm)
V13: Numeric Input Display (Water Level Low (distance from the sensor cm)
V14: Numeric Input Display (Vegetative State - Fertilizer A (Grow) Ml/100L)
V15: Numeric Input Display (Vegetative State - Fertilizer B (Bloom) Ml/100L)
V16: Numeric Input Display (Vegetative State - Fertilizer C (Micro) Ml/100L)
V17: Numeric Input Display (Bloom 1 State - Fertilizer A (Grow) Ml/100L)
V18: Numeric Input Display (Bloom 1 State - Fertilizer B (Bloom) Ml/100L)
V19: Numeric Input Display (Bloom 1 State - Fertilizer C (Micro) Ml/100L)
V20: Numeric Input Display (Bloom 2 State - Fertilizer A (Grow) Ml/100L)
V21: Numeric Input Display (Bloom 2 State - Fertilizer B (Bloom) Ml/100L)
V22: Numeric Input Display (Bloom 2 State - Fertilizer C (Micro) Ml/100L)
V23: Numeric Input Display  (Water Pump OFF time (minutes)
V24: Numeric Input Display (Water Pump ON time (minutes)

 **************************************************************/

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <SPI.h>


SimpleTimer timer;

WidgetRTC rtc;
WidgetTerminal terminal(V3);

#define server "blynk.cloud-com"   // or "blynk.cloud-com" for Blynk's cloud server


char Date[16];
char Time[16];
char auth[] = "***********";
char ssid[] = "*********";
char pass[] = "**********";
long startsecondswd;            // weekday start time in seconds
long stopsecondswd;             // weekday stop  time in seconds
long nowseconds;                // time now in seconds
bool isFirstConnect = true;


// Set water sensor analog pins

float water_sensor_a = A0;
float sensorValue = 0;

float capacityAdjustValue = 0;
float WaterFullOutputValue = 0;
float WaterLowOutputValue = 0;
float WaterLevelMeterAdjustValue = 0;


unsigned long WaterPumpUserONPeriod = 0;  //Set Water Pump Open Time
unsigned long WaterPumpUserOFFPeriod = 0;  //Set Water Pump Closed Time
//int WaterPumpState = LOW;



unsigned long DrainValvePeriod = 0;  //Set Drain Valve Open Time

unsigned long PumpAVPeriod = 0;  //Fertilizer Pump 1 Fertilizer A (GROW) ON Vegetative State period
unsigned long PumpBVPeriod = 0;  //Fertilizer Pump 2 Fertilizer B (BLOOM) ON Vegetative State period
unsigned long PumpCVPeriod = 0;  //Fertilizer Pump 3 Fertilizer C (MICRO) ON Vegetative State period

unsigned long PumpABPeriod = 0;  //Fertilizer Pump 1 Fertilizer A (GROW) ON BLOOM 1 State period
unsigned long PumpBBPeriod = 0;  //Fertilizer Pump 2 Fertilizer B (BLOOM) ON BLOOM 1 State period
unsigned long PumpCBPeriod = 0;  //Fertilizer Pump 3 Fertilizer C (MICRO) ON BLOOM 1 State period

unsigned long PumpABFPeriod = 0;  //Fertilizer Pump 1 Fertilizer A (GROW) ON BLOOM 2 State period
unsigned long PumpBBFPeriod = 0;  //Fertilizer Pump 2 Fertilizer B (BLOOM) ON BLOOM 2 State period
unsigned long PumpCBFPeriod = 0;  //Fertilizer Pump 3 Fertilizer C (MICRO) ON BLOOM 2 State period

unsigned long DrainValveStartMillis;

unsigned long PumpABStartMillis;
unsigned long PumpBBStartMillis;
unsigned long PumpCBStartMillis;

unsigned long PumpABFStartMillis;
unsigned long PumpBBFStartMillis;
unsigned long PumpCBFStartMillis;

unsigned long PumpAVStartMillis;
unsigned long PumpBVStartMillis;
unsigned long PumpCVStartMillis;

unsigned long WaterPumpStartMillis;
unsigned long WaterPumpCurrentMillis = 0;

unsigned long DrainValveCurrentMillis = 0;

unsigned long PumpABCurrentMillis = 0;
unsigned long PumpBBCurrentMillis = 0;
unsigned long PumpCBCurrentMillis = 0;

unsigned long PumpAVCurrentMillis = 0;
unsigned long PumpBVCurrentMillis = 0;
unsigned long PumpCVCurrentMillis = 0;

unsigned long PumpABFCurrentMillis = 0;
unsigned long PumpBBFCurrentMillis = 0;
unsigned long PumpCBFCurrentMillis = 0;

#define DHTPIN3 = 0;  //D3
#define DHTPIN4 = 2;  //D4
#define DHTPIN5 = 14; //D5
#define DHTPIN6 = 12; //D6
#define DHTPIN7 = 13; //D7
#define DHTPIN8 = 15; //D8
#define DHTPIN0 = 16;  //D0


enum VEGWaterStates {IsVEGWaterNeeded, VEGStep1, VEGStep2, VEGStep3, VEGStep4, VEGWaterNotNeeded, VEGWaterNeeded};
VEGWaterStates VEGState = IsVEGWaterNeeded;

enum BLOOMWaterStates {IsBLOOMWaterNeeded, BLOOMStep1, BLOOMStep2, BLOOMStep3, BLOOMStep4, BLOOMWaterNotNeeded, BLOOMWaterNeeded};
BLOOMWaterStates BLOOMState = IsBLOOMWaterNeeded;

enum BLOOMFWaterStates {IsBLOOMFWaterNeeded, BLOOMFStep1, BLOOMFStep2, BLOOMFStep3, BLOOMFStep4, BLOOMFWaterNotNeeded, BLOOMFWaterNeeded};
BLOOMFWaterStates BLOOMFState = IsBLOOMFWaterNeeded;

enum PLAINWaterStates {IsPLAINWaterNeeded, PLAINStep1, PLAINStep2, PLAINWaterNotNeeded, PLAINWaterNeeded};
PLAINWaterStates PLAINState = IsPLAINWaterNeeded;

enum DRAINWaterStates {IsDRAINWaterNeeded, DRAINStep1, DRAINStep2, DRAINWaterNotNeeded, DRAINWaterNeeded};
DRAINWaterStates DRAINState = IsDRAINWaterNeeded;

enum WateringStates {WateringON, WateringOFF};
WateringStates WateringState = WateringOFF;


enum LowWaterNotifyStates {LowWaterNotifyDone, LowWaterNotifyUnDone};
LowWaterNotifyStates LowWaterNotifyState = LowWaterNotifyUnDone;


enum LeakStates {WaterLeakNO, WaterLeakYES};
LeakStates LeakState = WaterLeakNO;


enum WaterPumpStates {WaterPumpON, WaterPumpOFF};
WaterPumpStates WaterPumpState = WaterPumpON;

enum WaterPumpUserStates {WaterPumpUserON, WaterPumpUserOFF};
WaterPumpUserStates WaterPumpUserState = WaterPumpUserON;

enum MainWateringStates {MainWateringON, MainWateringOFF};
MainWateringStates MainWateringState = MainWateringON;

enum LeakSensorStates {LeakSensorON, LeakSensorOFF};
LeakSensorStates LeakSensorState = LeakSensorON;

byte MainValveState = LOW;
byte DrainValveState = LOW;
byte PumpAState = LOW;
byte PumpBState = LOW;
byte PumpCState = LOW;

int RELAY1 = D3; //Main Valve
int RELAY2 = D4; //Lights ON/OFF

const byte RELAY6 = D8; //Drain Valve

const byte RELAY3 = D5; //Fertilizer Pump 1 GROW
const byte RELAY4 = D6; //Fertilizer Pump 2 BLOOM
const byte RELAY5 = D7; //Fertilizer Pump 3 MICRO

const byte RELAY7 = D0; //Water Pump


String displaycurrenttimepluswifi;
int wifisignal;
int manual = 0;
int oldstatus;

int uptoyou;


//-------------------
//ultrasound sensor:

unsigned long echo = 0;
int ultraSoundSignal = 5; // Ultrasound trig signal pin D1
int ultraSoundSignalIN = 4; // Ultrasound echo signal pin D2

unsigned long ultrasoundValue = 0;



void setup()
{
  pinMode(RELAY1, OUTPUT);
  pinMode(RELAY2, OUTPUT);
  pinMode(RELAY3, OUTPUT);
  pinMode(RELAY4, OUTPUT);
  pinMode(RELAY5, OUTPUT);
  pinMode(RELAY6, OUTPUT);
  pinMode(RELAY7, OUTPUT);

  digitalWrite(RELAY1, LOW); // set Main Valve OFF

  digitalWrite(RELAY2, LOW); // set LIGHTS OFF
  digitalWrite(RELAY3, LOW); // set Fertilizer Pump 1 GROW OFF
  digitalWrite(RELAY4, LOW); // set Fertilizer Pump 2 BLOOM OFF
  digitalWrite(RELAY5, LOW); // set Fertilizer Pump 3 MICRO OFF
  digitalWrite(RELAY6, LOW); // set Drain Valve OFF
  digitalWrite(RELAY7, LOW); // set Water Pump OFF

  pinMode(ultraSoundSignal, OUTPUT);
  pinMode(ultraSoundSignalIN, INPUT);

  Serial.begin(115200);
  Serial.println("\Starting");
  Blynk.begin(auth, ssid, pass, IPAddress(139, 59, 206, 133), 80);
  int mytimeout = millis() / 1000;

  WaterPumpStartMillis = millis();  //initial start time of Water Pump

  while (Blynk.connect() == false) { // try to connect to server for 10 seconds
    if ((millis() / 1000) > mytimeout + 8) { // try local server if not connected within 9 seconds
      break;
    }
  }
  rtc.begin();
  timer.setInterval(10000L, activetoday);  // check every 10 SECONDS if schedule should run today
  timer.setInterval(30000L, reconnectBlynk);  // check every 30s if still connected to server
  timer.setInterval(5000L, clockvalue);  // check value for time
  timer.setInterval(5000L, sendWifi);    // Wi-Fi singal
  timer.setInterval(1000L, ultrasoundsensor_send); //ultrasoundsensorvalue
  timer.setInterval(2000L, MoistureSensor); // Moisture Sensor Value

}


unsigned long ping()
{
  pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output
  digitalWrite(ultraSoundSignal, LOW); // Send low pulse
  delayMicroseconds(2); // Wait for 2 microseconds
  digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
  delayMicroseconds(15); // Wait for 15 microseconds
  digitalWrite(ultraSoundSignal, LOW); // Holdoff
  pinMode(ultraSoundSignalIN, INPUT); // Switch signalpin to input
  digitalWrite(ultraSoundSignalIN, HIGH); // Turn on pullup resistor
  // please note that pulseIn has a 1sec timeout, which may
  // not be desirable. Depending on your sensor specs, you
  // can likely bound the time like this — marcmerlin
  // echo = pulseIn(ultraSoundSignal, HIGH, 38000)
  echo = pulseIn(ultraSoundSignalIN, HIGH); //Listen for echo
  Serial.println(echo);
  ultrasoundValue = (echo / 58.138); // * .39; //convert to CM then to inches


 

BLYNK_WRITE(V6)  //Water Capacity Value Input
{
  int capacityValueIn = param.asInt(); //Get value as integer
  capacityAdjustValue = capacityValueIn * 100.00 / 10000.00; //Calculate User Water Capacity Adjusting Value

}

BLYNK_WRITE(V9)  //Drain Time Value Calculations
{
  int DrainTimeValueIn = param.asInt(); //Get value as integer
  DrainValvePeriod = DrainTimeValueIn * 60000;  //Calculate User Drain Time Value

}

BLYNK_WRITE(V24)  //Water Pump ON Time Value Calculations
{
  int WaterPumpONTimeValueIn = param.asInt(); //Get value as integer
  WaterPumpUserONPeriod = WaterPumpONTimeValueIn * 60000;  //Calculate User Water Pump ON Time Value
}

BLYNK_WRITE(V23)  //Water Pump OFF Time Value Calculations
{
  int WaterPumpOFFTimeValueIn = param.asInt(); //Get value as integer
  WaterPumpUserOFFPeriod = WaterPumpOFFTimeValueIn * 60000;  //Calculate User Water Pump OFF Time Value
}

BLYNK_WRITE(V12)  //Water Level Full Distance Value Calculations
{
  int WaterFullValueIn = param.asInt(); //Get value as integer
  float WaterFullAdjustValue = WaterFullValueIn * 100.00 / 10000.00; //Calculate User Water Full Adjusting Value
  WaterFullOutputValue = (WaterFullAdjustValue  * 2860.00) * 2; //Calculate User Water Full Value (2860.00 = 50cm)
}

BLYNK_WRITE(V13)  //Water Level Low Distance & Water Level Meter Adjust Values Calculations
{
  int WaterLowValueIn = param.asInt(); //Get value as integer
  float WaterLowAdjustValue = WaterLowValueIn * 100.00 / 10000.00; //Calculate User Water Low Adjusting Value
  WaterLowOutputValue = (WaterLowAdjustValue  * 2860.00) * 2; //Calculate User Water Low Value (2860.00 = 50cm)
  WaterLevelMeterAdjustValue = (WaterLowOutputValue - WaterFullOutputValue) / 20; // Calculate Water Level Meter Adjust Value. 5% of the User Water Level Scale

}

BLYNK_WRITE(V14)  //Vegetative State Fertilizer A (Grow) Value Calculations
{
  int VegFertAValueIn = param.asInt(); //Get value as integer
  float VegFertAAdjustValue = VegFertAValueIn * 100.00 / 10000.00; //Calculate User Vegetative State Fertilizer A (Grow) Adjusting Value
  PumpAVPeriod = (VegFertAAdjustValue * 62000) * capacityAdjustValue; //Calculate User Vegetative State Fertilizer A (Grow) Output Value (62000 = 100Ml)
}

BLYNK_WRITE(V15)  //Vegetative State Fertilizer B (Bloom) Value Calculations
{
  int VegFertBValueIn = param.asInt(); //Get value as integer
  float VegFertBAdjustValue = VegFertBValueIn * 100.00 / 10000.00; //Calculate User Vegetative State Fertilizer B (Bloom) Adjusting Value
  PumpBVPeriod = (VegFertBAdjustValue * 62000) * capacityAdjustValue; //Calculate User Vegetative State Fertilizer B (Bloom) Output Value (62000 = 100Ml)
}

BLYNK_WRITE(V16)  //Vegetative State Fertilizer C (Micro) Value Calculations
{
  int VegFertCValueIn = param.asInt(); //Get value as integer
  float VegFertCAdjustValue = VegFertCValueIn * 100.00 / 10000.00; //Calculate User Vegetative State Fertilizer C (Micro) Adjusting Value
  PumpCVPeriod = (VegFertCAdjustValue * 62000) * capacityAdjustValue; //Calculate User Vegetative State Fertilizer C (Micro) Output Value (62000 = 100Ml)
}


//Bloom 1 State Fertilizer Calculations


BLYNK_WRITE(V17)  //Bloom 1 State Fertilizer A (Grow) Value Calculations
{
  int Bloom1FertAValueIn = param.asInt(); //Get value as integer
  float Bloom1FertAAdjustValue = Bloom1FertAValueIn * 100.00 / 10000.00; //Calculate User Bloom 1 State Fertilizer A (Grow) Adjusting Value
  PumpABPeriod = (Bloom1FertAAdjustValue * 62000) * capacityAdjustValue; //Calculate User Bloom 1 State Fertilizer A (Grow) Output Value (62000 = 100Ml)
}

BLYNK_WRITE(V18)  //Bloom 1 State Fertilizer B (Bloom) Value Calculations
{
  int Bloom1FertBValueIn = param.asInt(); //Get value as integer
  float Bloom1FertBAdjustValue = Bloom1FertBValueIn * 100.00 / 10000.00; //Calculate User Bloom 1 State Fertilizer B (Bloom) Adjusting Value
  PumpBBPeriod = (Bloom1FertBAdjustValue * 62000) * capacityAdjustValue; //Calculate User Bloom 1 State Fertilizer B (Bloom) Output Value (62000 = 100Ml)
}

BLYNK_WRITE(V19)  //Bloom 1 State Fertilizer C (Micro) Value Calculations
{
  int Bloom1FertCValueIn = param.asInt(); //Get value as integer
  float Bloom1FertCAdjustValue = Bloom1FertCValueIn * 100.00 / 10000.00; //Calculate User Bloom 1 State Fertilizer C (Micro) Adjusting Value
  PumpCBPeriod = (Bloom1FertCAdjustValue * 62000) * capacityAdjustValue; //Calculate User Bloom 1 State Fertilizer C (Micro) Output Value (62000 = 100Ml)
}

//Bloom 2 State Fertilizer Calculations


BLYNK_WRITE(V20)  //Bloom 2 State Fertilizer A (Grow) Value Calculations
{
  int Bloom2FertAValueIn = param.asInt(); //Get value as integer
  float Bloom2FertAAdjustValue = Bloom2FertAValueIn * 100.00 / 10000.00; //Calculate User Bloom 2 State Fertilizer A (Grow) Adjusting Value
  PumpABFPeriod = (Bloom2FertAAdjustValue * 62000) * capacityAdjustValue; //Calculate User Bloom 2 State Fertilizer A (Grow) Output Value (62000 = 100Ml)
}

BLYNK_WRITE(V21)  //Bloom 2 State Fertilizer B (Bloom) Value Calculations
{
  int Bloom2FertBValueIn = param.asInt(); //Get value as integer
  float Bloom2FertBAdjustValue = Bloom2FertBValueIn * 100.00 / 10000.00; //Calculate User Bloom 2 State Fertilizer B (Bloom) Adjusting Value
  PumpBBFPeriod = (Bloom2FertBAdjustValue * 62000) * capacityAdjustValue; //Calculate User Bloom 2 State Fertilizer B (Bloom) Output Value (62000 = 100Ml)
}

BLYNK_WRITE(V22)  //Bloom 2 State Fertilizer C (Micro) Value Calculations
{
  int Bloom2FertCValueIn = param.asInt(); //Get value as integer
  float Bloom2FertCAdjustValue = Bloom2FertCValueIn * 100.00 / 10000.00; //Calculate User Bloom 2 State Fertilizer C (Micro) Adjusting Value
  PumpCBFPeriod = (Bloom2FertCAdjustValue * 62000) * capacityAdjustValue; //Calculate User Bloom 2 State Fertilizer C (Micro) Output Value (62000 = 100Ml)
}

void sendUptime()
{
  // This function sends Arduino's up time every second to Virtual Pin (5).
  // In the app, Widget's reading frequency should be set to PUSH. This means
  // that you define how often to send data to Blynk App.

  Blynk.virtualWrite(V5, millis() / 1000);
  Blynk.virtualWrite(V6, millis() / 1000);
}



BLYNK_CONNECTED() {
  if (isFirstConnect) {
    Blynk.syncAll();
    Blynk.notify("TIMER STARTING!!!!");
    isFirstConnect = false;


  }
}


BLYNK_WRITE (V8) {

  switch (param.asInt())
  {

    case 1: // Vegetative Mix

      if (echo >= WaterLowOutputValue && echo < 9000)
      {

        VEGMachine();
      }
      else
      {
        if (WateringState == WateringON)
        {
          VEGMachine();
        }
      }

      break;

    case 2: // Bloom Mix

      if (echo >= WaterLowOutputValue && echo < 9000)
      {

        BLOOMMachine();
      }
      else
      {
        if (WateringState == WateringON)
        {
          BLOOMMachine();
        }
      }
      break;


    case 3: // Bloom Final Mix

      if (echo >= WaterLowOutputValue && echo < 9000)
      {

        BLOOMFMachine();
      }
      else
      {
        if (WateringState == WateringON)
        {
          BLOOMFMachine();
        }
      }
      break;

    case 4: // Plain Water Mix

      if (echo >= WaterLowOutputValue && echo < 9000)
      {

        PLAINMachine();
      }
      else
      {
        if (WateringState == WateringON)
        {
          PLAINMachine();
        }
      }
      break;

    case 5: // Drain All And Stop Growing

      DRAINMachine();
      break;

    default:
      // if nothing else matches, do the default
      // default is optional
      //watermixVEG();
      break;
  }

}


void ultrasoundsensor_send()

{
  int x = 0;
  x = ping();
  //Serial.println(x);
  //  delay(500); //delay 1/2 seconds.
}



void sendWifi() {
  wifisignal = map(WiFi.RSSI(), -105, -40, 0, 100);
}

void clockvalue() // Digital clock display of the time
{

  int gmthour = hour();
  if (gmthour == 24) {
    gmthour = 0;
  }
  String displayhour =   String(gmthour, DEC);
  int hourdigits = displayhour.length();
  if (hourdigits == 1) {
    displayhour = "0" + displayhour;
  }
  String displayminute = String(minute(), DEC);
  int minutedigits = displayminute.length();
  if (minutedigits == 1) {
    displayminute = "0" + displayminute;
  }

  displaycurrenttimepluswifi = "                                          Clock:  " + displayhour + ":" + displayminute + "               Signal:  " + wifisignal + " %";
  Blynk.setProperty(V3, "label", displaycurrenttimepluswifi);

}


void activetoday() {       // check if schedule should run today
  if (year() != 1970) {

    if (uptoyou == 1) {
      Blynk.syncVirtual(V10); // sync timeinput widget
    }
  }
}

void checklastbuttonpressed () {

  if (uptoyou == 1) {
    oldstatus = 5;
  }
  if (uptoyou == 0) {
    oldstatus = 6;
  }
}


void restorelastbuttonpressed () {

  if (oldstatus == 5) {
    uptoyou = 1;
    Blynk.virtualWrite(V11, 1);
  }
  if (oldstatus == 6) {

    uptoyou = 0;

    Blynk.virtualWrite(V11, 0);
  }
}


void resetTerminal()
{
  terminal.println();
  terminal.println();
  terminal.println();
  terminal.println("TIMER has been selected");
  terminal.println("Wait for update (10 seconds as maximum)");
  terminal.println();
  //terminal.println();
  //terminal.println();
  terminal.flush();
}

void resetManual()
{
  Blynk.virtualWrite(V1, 0);   //Turn OFF Manual Mode Widget
  Blynk.virtualWrite(V2, 0);   //Turn OFF Button Widget Device
  Blynk.virtualWrite(V7, 0); //Turn OFF virtual LED V7
  digitalWrite(RELAY2, LOW); // set LIGHTS OFF
}


BLYNK_WRITE(V2)  // ON-OFF Manual
{
  if (param.asInt() == 1) { //
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println("Manual MODE is ON");
    terminal.println("Press ON/OFF button if required");
    terminal.println("Lights Are ON");
    terminal.println();
    // terminal.println();
    terminal.flush();

    if (manual == 0) { 
      checklastbuttonpressed ();
      manual = 1;

      uptoyou = 0;

      Blynk.virtualWrite(V11, 0);
      Blynk.virtualWrite(V7, 1023); //Turn ON virtual LED V7
      digitalWrite(RELAY2, HIGH); // set LIGHTS ON
      Blynk.virtualWrite(V2, 1);   //Turn ON Button Widget

    } else {             //está en modo manual

      uptoyou = 0;

      Blynk.virtualWrite(V11, 0);
      Blynk.virtualWrite(V7, 1023); //Turn ON virtual LED V7
      digitalWrite(RELAY2, HIGH); // set LIGHTS ON
      Blynk.virtualWrite(V2, 1);   //Turn ON Button Widget
    }
  } else {

    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println("Manual MODE is ON");
    terminal.println("Press ON/OFF button if required");
    terminal.println("Light Are OFF");
    terminal.println();
    //terminal.println();
    terminal.flush();

    if (manual == 0) {   //modo automático
      checklastbuttonpressed ();
      manual = 1;

      uptoyou = 0;

      Blynk.virtualWrite(V11, 0);
      Blynk.virtualWrite(V7, 0); //Turn OFF virtual LED V7
      digitalWrite(RELAY2, LOW); // set LIGHTS OFF
      Blynk.virtualWrite(V2, 0);   //Turn OFF Button Widget
    } else {

      uptoyou = 0;

      Blynk.virtualWrite(V11, 0);
      Blynk.virtualWrite(V7, 0); //Turn OFF virtual LED V7
      digitalWrite(RELAY2, LOW); // set LIGHTS OFF
      Blynk.virtualWrite(V2, 0);   //Turn OFF Button Widget
    }
  }
}


BLYNK_WRITE(V0)  // ON-OFF Water Pump
{
  if (param.asInt() == 1) { 
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println("Water Pump Manual ON");
    terminal.println();
    // terminal.println();
    terminal.flush();
    Serial.println("Water Pump Manual ON");
    LeakState = WaterLeakNO;
    WaterPumpState = WaterPumpON;


  } else {

    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println("Water Pump Manual OFF");
    terminal.println();
    //terminal.println();
    terminal.flush();
    Serial.println("Water Pump Manual OFF");

    WaterPumpState = WaterPumpOFF;

  }
}



BLYNK_WRITE(V4)  // ON-OFF Main Watering
{
  if (param.asInt() == 1) { // boton encendido
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println("Main Watering ON");
    terminal.println();
    // terminal.println();
    terminal.flush();
    Serial.println("Main Watering ON");
    MainWateringState = MainWateringON;



  } else {

    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println("Main Watering OFF");
    terminal.println();
    //terminal.println();
    terminal.flush();


    digitalWrite(RELAY1, LOW);  //change the state of the Main Valve to Closed


    //    Serial.println("Main Valve Closed");
    MainValveState = LOW;


    digitalWrite(RELAY6, LOW);  //change the state of the Drain Valve to Closed
    DrainValveState = LOW;


    digitalWrite(RELAY3, LOW);  //change the state of the Fertilizer Pump 1 (GROW) to Closed
    PumpAState = LOW;

    digitalWrite(RELAY4, LOW);  //change the state of the Fertilizer Pump 2 (BLOOM) to Closed
    PumpBState = LOW;

    digitalWrite(RELAY5, LOW);  //change the state of the Fertilizer Pump 3 (MICRO) to Closed
    PumpCState = LOW;

    Serial.println("All Fertilizer Pumps + Drain & Main Valves Closed");


    WateringState = WateringOFF;
    BLOOMState = IsBLOOMWaterNeeded;
    BLOOMFState = IsBLOOMFWaterNeeded;
    VEGState = IsVEGWaterNeeded;
    PLAINState = IsPLAINWaterNeeded;
    DRAINState = IsDRAINWaterNeeded;
    Serial.println("Main Watering OFF");

    MainWateringState = MainWateringOFF;
  }
}


BLYNK_WRITE(V5)  // ON-OFF WaterLeak Sensor
{
  if (param.asInt() == 1) { // boton encendido
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println("Leak Sensor Is ON");
    terminal.println();
    // terminal.println();
    terminal.flush();

    LeakSensorState = LeakSensorON;

  } else {

    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println("Leak Sensor Is OFF");
    terminal.println();
    //terminal.println();
    terminal.flush();

    LeakSensorState = LeakSensorOFF;
  }
}

BLYNK_WRITE(V11)  // Up to you selected
{
  if (param.asInt() == 1) {
    timer.setTimeout(50, resetTerminal);
    timer.setTimeout(50, resetManual);
    timer.setTimeout(50, checklastbuttonpressed);

    uptoyou = 1;

  } else {

    uptoyou = 0;
  }
}

BLYNK_WRITE(V10)//Up to you
{
  if (uptoyou == 1) {
    sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
    sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());

    TimeInputParam t(param);

    terminal.print("TIMER Checked schedule at: ");
    terminal.println(Time);
    terminal.flush();
    int dayadjustment = -1;
    if (weekday() == 1) {
      dayadjustment =  6; // needed for Sunday, Time library is day 1 and Blynk is day 7
    }
    if (t.isWeekdaySelected(weekday() + dayadjustment)) { //Time library starts week on Sunday, Blynk on Monday
      terminal.println("TIMER ACTIVE today");
      terminal.flush();
      if (t.hasStartTime()) // Process start time
      {
        terminal.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute());
        terminal.flush();
      }
      if (t.hasStopTime()) // Process stop time
      {
        terminal.println(String("Stop : ") + t.getStopHour() + ":" + t.getStopMinute());
        terminal.flush();
      }
      // Display timezone details, for information purposes only
      terminal.println(String("Time zone: ") + t.getTZ()); // Timezone is already added to start/stop time
      terminal.println("At least ONE day MUST be selected");
      // terminal.println(String("Time zone offset: ") + t.getTZ_Offset()); // Get timezone offset (in seconds)
      terminal.flush();

      for (int i = 1; i <= 7; i++) {  // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
        if (t.isWeekdaySelected(i)) {
          terminal.println(String("Day ") + i + " is selected");
          terminal.flush();
        }
      }
      nowseconds = ((hour() * 3600) + (minute() * 60) + second());
      startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
      //Serial.println(startsecondswd);  // used for debugging
      if (nowseconds >= startsecondswd) {
        terminal.print("TIMER STARTED at");
        terminal.println(String(" ") + t.getStartHour() + ":" + t.getStartMinute());
        terminal.flush();
        if (nowseconds <= startsecondswd + 90) {  // 90s on 60s timer ensures 1 trigger command is sent

          Blynk.virtualWrite(V7, 1023); //Turn ON virtual LED V7
          digitalWrite(RELAY2, HIGH); // set LIGHTS ON
          Blynk.virtualWrite(V2, 0);   //Turn OFF Button Widget

          // code here to switch the relay ON
        }
      }
      else {
        terminal.println("Lights Are OFF");
        terminal.flush();

      }
      stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
      //Serial.println(stopsecondswd);  // used for debugging
      if (nowseconds >= stopsecondswd) {

        Blynk.virtualWrite(V7, 0); //Turn OFF virtual LED V7
        digitalWrite(RELAY2, LOW); // set LIGHTS OFF
        Blynk.virtualWrite(V2, 0);
        terminal.print("TIMER STOPPED at");
        terminal.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());

        terminal.flush();
        if (nowseconds <= stopsecondswd + 90) { // 90s on 60s timer ensures 1 trigger command is sent

          Blynk.virtualWrite(V7, 0); //Turn OFF virtual LED V7
          digitalWrite(RELAY2, LOW); // set LIGHTS OFF
          Blynk.virtualWrite(V2, 0);
          // code here to switch the relay OFF
        }
      }
      else {
        if (nowseconds >= startsecondswd) {

          Blynk.virtualWrite(V7, 0); //Turn OFF virtual LED V7
          digitalWrite(RELAY2, HIGH); // set LIGHTS ON
          Blynk.virtualWrite(V2, 0);
          terminal.println("Lights Are ON");
          terminal.flush();

        }
      }
    }
    else {
      terminal.println("TIMER INACTIVE today");
      terminal.flush();
      // nothing to do today, check again in 30 SECONDS time
    }
    terminal.println();
  }
}

void reconnectBlynk() {
  if (!Blynk.connected()) {
    if (Blynk.connect()) {
      BLYNK_LOG("Reconnected");
    } else {
      BLYNK_LOG("Not reconnected");
    }
  }
}

void WaterPump()  //function to ON/OFF Water Pump
{
  if ((WaterPumpUserState == WaterPumpUserON) && (WaterPumpCurrentMillis - WaterPumpStartMillis >= WaterPumpUserONPeriod))  //test whether the period has elapsed
  {
    WaterPumpUserState = WaterPumpUserOFF;
    digitalWrite(RELAY7, LOW);  //if so, change the state of the Water Pump to OFF
    WaterPumpStartMillis = WaterPumpCurrentMillis;  //IMPORTANT to save the start time of the current RELAY state.
    Serial.println("Water Pump OFF");
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println("Water Pump Turned OFF");
    terminal.println();
    // terminal.println();
    terminal.flush();
  }
   else if ((WaterPumpUserState == WaterPumpUserOFF) && (WaterPumpCurrentMillis - WaterPumpStartMillis >= WaterPumpUserOFFPeriod))  //test whether the period has elapsed
  {
    WaterPumpUserState = WaterPumpUserON;
    digitalWrite(RELAY7, HIGH);  //if so, change the state of the Water Pump to ON
    WaterPumpStartMillis = WaterPumpCurrentMillis;  //IMPORTANT to save the start time of the current RELAY state.
    Serial.println("Water Pump ON");
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println();
    terminal.println("Water Pump Turned ON");
    terminal.println();
    // terminal.println();
    terminal.flush();
  }
}


void MoistureSensor()
{

  sensorValue = analogRead(water_sensor_a);
  Serial.println(sensorValue);

  if (sensorValue >= 50 && sensorValue < 900)


    }
  }
  if (sensorValue >= 900 && sensorValue < 1300)
  {

    if (LeakSensorState == LeakSensorON) {

      //      if (LeakStateNotifyState == LeakStateNotifyUnDone) {

      if (LeakState == WaterLeakYES)
      {
        terminal.print("No Water Leak Found Anymore.");
        Blynk.notify("No Water Leak Found Anymore");
        Serial.print("No Water Leak Found Anymore.");


        Blynk.syncVirtual(V0);
        //          LeakStateNotifyState = LeakStateNotifyDone;
        LeakState = WaterLeakNO;

      }
    }
  }
}

void loop()
{

  if (Blynk.connected()) {
    Blynk.run();
  }
  timer.run();
  if (WaterPumpState == WaterPumpON)  {
    if (WateringState == WateringOFF) {

      WaterPumpCurrentMillis = millis();  //get the current time of Water Pump

      WaterPump();
    }
    if (WateringState == WateringON) {
      Blynk.syncVirtual(V8);
    }
  }
}

```cpp

Okay, so you’ve shared a load of code that has no WifiManager items in it, and the only item of interest is the shightly strange way in which you’re doing you’re Blynk.begin…

Blynk.begin(auth, ssid, pass, IPAddress(139, 59, 206, 133), 80);

if you did

Blynk.begin(auth, ssid, pass);

Then it would achieve exactly the same result.

As I said before, the Auth code, SSID and Wi-Fi password are the only three fields that you need to capture when using WifiManager with Blynk Cloud, provided you don’t need your devices to have a static IP address (which you’re not doing at the moment in this code).

If you want examples of how to capture these three items via the WifiManager static portal and save them to EEPROM then you’d be better searching this forum than github.

Pete.

Yeah I´ve tried to test that WiFi-manager by itself before including it to this long code. To find the best way to do it first. So there is no WiFi-manager stuff in this code yet, but you asked about this project so I told you about it.

I try to search the Blynk-forum and keep on struggling. That´s ok I´m used to it.

Thanks.

1 Like

If you get compile errors with that code then you need to downgrade your ArduinoJson library from 6.x.x to 5.13.5

Pete.

Thanks.

I managed to compile this to NodeMCU 1.0. So it directs me again to 192.168.244.1 and ask a lot of things in the config. Blynk token is already filled, so if I fill only SSID and password this is what I get out from serial monitor:


*WM: [1] AP IP address: 192.168.244.1
*WM: [3] setupConfigPortal 
*WM: [1] Starting Web Portal 
*WM: [3] dns server started with ip:  192.168.244.1
*WM: [2] HTTP server started 
*WM: [2] WiFi Scan ASYNC started 
*WM: [2] Config Portal Running, blocking, waiting for clients... 
*WM: [2] NUM CLIENTS: 0 
*WM: [2] WiFi Scan ASYNC completed in 2209 ms
*WM: [2] WiFi Scan ASYNC found: 4
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 16560 ms ago
*WM: [3] -> www.msftncsi.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 19709 ms ago
*WM: [3] -> ncc.avast.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] WiFi Scan ASYNC started 
*WM: [2] WiFi Scan ASYNC completed in 2207 ms
*WM: [2] WiFi Scan ASYNC found: 4
*WM: [3] -> ip-info.ff.avast.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 1097 ms ago
*WM: [2] NUM CLIENTS: 1 
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 4347 ms ago
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 7556 ms ago
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 10735 ms ago
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 13916 ms ago
*WM: [3] -> ncc.avast.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 17130 ms ago
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] WiFi Scan ASYNC started 
*WM: [2] WiFi Scan ASYNC completed in 2209 ms
*WM: [2] WiFi Scan ASYNC found: 4
*WM: [3] -> www.msftncsi.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [3] -> ncc.avast.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> ncc.avast.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> ncc.avast.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> ncc.avast.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP WiFi save  
*WM: [3] Method: POST
*WM: [2] Parameters 
*WM: [2] -------------------- 
*WM: [2] blynk: *************************
*WM: [2] -------------------- 
*WM: [3] static ip: (IP unset)
*WM: [3] static gateway: (IP unset)
*WM: [3] static netmask: (IP unset)
*WM: [3] static DNS: (IP unset)
*WM: [3] Sent wifi save page 
*WM: [2] process connect 
*WM: [2] Connecting as wifi client... 
*WM: [1] STA static IP: (IP unset)
*WM: [2] Custom static IP/GW/Subnet/DNS 
*WM: [2] Custom static DNS 
*WM: [1] STA IP set: (IP unset)
*WM: [3] WIFI station disconnect 
*WM: [1] Connecting to new AP: *************
*WM: [3] Using Password: ************
*WM: [3] WiFi station enable 
*WM: [3] enableSTA PERSISTENT ON 
*WM: [1] connectTimeout not set, ESP waitForConnectResult... 
*WM: [2] Connection result: WL_CONNECTED
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [1] Connect to new AP [SUCCESS] 
*WM: [1] Got IP Address: 
*WM: [1] 192.168.10.54 
Should save config
*WM: [2] disconnect configportal 
*WM: [2] restoring usermode STA
*WM: [2] wifi status: WL_CONNECTED
*WM: [2] wifi mode: STA
*WM: [1] config portal exiting 
connected...yeey :)
saving config
failed to open config file for writing
{"blynk_token":"****************"}BLYNK Connected
*WM: [3] freeing allocated params! 
*WM: [3] unloading 

Browser gets stuck at http://192.168.244.1/wifisave
and says:
"
Saving Credentials
Trying to connect ESP to network.
If it fails reconnect to AP to try again
"
And my laptop (which I used to set the config) is not connected to any network anymore.

What this means? Is NodeMCU connected or not? This is a bit confusing.

Update:

I tried this with 2 more NodeMCU´s and I get the same result. Second time I connect power to NodeMCU the serial monitor gives this:

*WM: [2] Connection result: WL_CONNECTED
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [1] AutoConnect: SUCCESS 
*WM: [1] STA IP Address: 192.168.10.54
connected...yeey :)
BLYNK Connected
*WM: [3] freeing allocated params! 
*WM: [3] unloading 

So seems like it connects to Blynk automatically. So how this works? How can I set new SSID and password for it when I want to use other network? How to reset it?

Sorry I´m totally novice with this WiFi-manager.

Thanks

Can you post your full WifiManager code?

Pete.

This is the code I used.

#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>
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager
#include <SimpleTimer.h>
#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson


#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
//#define BLYNK_DEBUG


//define your default values here, if there are different values in config.json, they are overwritten.
//char mqtt_server[40];
//char mqtt_port[6] = "8080";
char blynk_token[34] = "**********************";

//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 setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println();

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

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

  if (SPIFFS.begin()) {
    Serial.println("mounted file system");
    if (SPIFFS.exists("/config.json")) {
      //file exists, reading and loading
      Serial.println("reading config file");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile) {
        Serial.println("opened config file");
        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()) {
          Serial.println("\nparsed json");

          //strcpy(mqtt_server, json["mqtt_server"]);
          //strcpy(mqtt_port, json["mqtt_port"]);
          strcpy(blynk_token, json["blynk_token"]);

        } else {
          Serial.println("failed to load json config");
        }
      }
    }
  } 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 custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
  //WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 6);
  WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 33);

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

  //set static ip
  //wifiManager.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
  
  //add all your parameters here
  //wifiManager.addParameter(&custom_mqtt_server);
  //wifiManager.addParameter(&custom_mqtt_port);
  wifiManager.addParameter(&custom_blynk_token);

  //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("Wifi_Manager", "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(mqtt_server, custom_mqtt_server.getValue());
  //strcpy(mqtt_port, custom_mqtt_port.getValue());
  strcpy(blynk_token, custom_blynk_token.getValue());

  //save the custom parameters to FS
  if (shouldSaveConfig) {
    Serial.println("saving config");
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    //json["mqtt_server"] = mqtt_server;
    //json["mqtt_port"] = mqtt_port;
    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();
    //end save
  }

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

  Blynk.config(blynk_token);
  bool result = Blynk.connect();

if (result != true)
{
  Serial.println("BLYNK Connection Fail");
  Serial.println(blynk_token);
  wifiManager.resetSettings();
  ESP.reset();
  delay (5000);
}
else
{
  Serial.println("BLYNK Connected");
}

}

void loop() {
 
Blynk.run();

}

And with this code seems like I managed to reset those SSID and password.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
void setup()
{
  WiFi.disconnect();
//  WiFiManager.resetSettings();
//  ESP.eraseConfig();
//  ESP.reset();
//  ESP.restart();
}
void loop()
{
  yield();
}

So do I need to add some button to my Blynk-project like “Reset WiFi-settings”? But this I guess works only when I´m still connected to the old WiFi-network.

What does this : “ESP.reset();” mean in the code? is it basically the same as " WiFi.disconnect();"? So it resets the WiFi-settings, if it can´t find the old WiFi-network automatically anymore? And that way it takes me to config again.

Or what is the best way to do this? Or is this even connected properly now? Its bit weird have to say. How does this device act when i take it to some other place wheres new WiFi-network to connect if I havent reseted it first? Does it reset WiFi-settings automatically then to be able to go to the config again?

Correct.

You may want to review this page

Yes, when cannot connect to the configured router.

Okay, a few things here…

  1. I’ve compiled and uploaded this code to a device and it produces a captive portal at 102.168.4.1
*WM: Configuring access point... 
*WM: Wifi_Manager
*WM: password
*WM: AP IP address: 
*WM: 192.168.4.1
*WM: HTTP server started

I suspect that your WiFiManager.h file contains a line that says something like:

IPAddress     _ap_static_ip (192,168,244,1);

That part of my WiFiManager.h file looks like this

IPAddress     _ap_static_ip;
IPAddress     _ap_static_gw;
IPAddress     _ap_static_sn;
IPAddress     _sta_static_ip;
IPAddress     _sta_static_gw;
IPAddress     _sta_static_sn;

If that’s not the case, then you may have several version of WiFiManager installed (you hinted at this before). You should turn on verbose compiler messages in the IDE to see the path of the library that’s used, like this:

Using library WiFiManager at version 0.14 in folder: C:\Users\Pete Knight\Documents\Arduino\libraries\WiFiManager 

Find the folder that’s being used and check the contents of the WiFiManager.h file.

  1. I think that there are a few lines missing from the start of your serial monitor output, and I suspect that the first two missing lines say:
mounting FS...
failed to mount FS

I say this because of the line in your output that says:

failed to open config file for writing

If this is the case then I suspect that you’ve compiled your code with a “(no SPIFFS)” option selected in the Flash Size menu of the IDE. You need a small amount of SPIFFS (1M is usually the smallest option for a NodeMCU, but only a small amount is actually needed)).
This prevents the Blynk Auth Code data from being saved to SPIFFS and retrieved later.
WiFi credentials aren’t stored in SPIFFS, so they will be saved and the NodeMCU will attempt to re-connect to the same network. If it can’t then it will launch the WiFiManager captive portal automatically when the device is booted (I think this probably answers one of your questions about the need for a way to clear existing WiFi credentials - it’s not really needed, but more on that later).

  1. You may also find that you need to format the SPIFFS storage area before it can be used, but in my experience this only seems to be necessary if you’ve changed the type and size of data being stored in SPIFFS and you need to clear it out.

To format SPIFFS you un-comment this line:

  //SPIFFS.format();

then upload the code and boot the device once, then comment-out that line and re-upload the code.
The IDE now has a neat way of doing that, using the “Erase Flash:…All Flash Contents” option.

image

  1. As I’ve said already, If you take your NodeMCU to a place where its out of range of any known network (or if you flash it with the “Erase Flash:…Sketch + WiFi settings” or “Erase Flash:…All Flash Contents” options) then it will launch the WiFiManager captive portal.

Once the portal is launched it will scan for available networks and allow you to choose one then input the password. You’ll also be able to add the Blynk auth code that will be used at that location.
The only time that you’ll need to have access to the portal again is if either the Wifi credentials change (in which case the portal will launch automatically) or if you need to amend the Blynk auth token/ This could be because you’ve inputted it incorrectly, or because you want to refresh it for some reason.

You can either:

  • Re-flash the device with the "“Erase Flash:…Sketch + WiFi settings” option (very messy!)
  • Take the device out of range of the known network and connect it to something else (maybe a hotspot) then return to the correct Wi-Fi network and re-input the credentials (also messy, but do-able)
  • Have a physical button or button widget in the app that erases the WiFi credentials using WiFi.disconnect()

Hope this adds some clarity.

Pete.

One other thing to note.
If anyone tries to compile this code and gets and gets a compiler error message something like “‘dynamicjsonbuffer’ was not declared in this scope” then you need to downgrade your ArduinoJson library from 6.x.x to 5.13.5

Pete.

Thanks a lot. That made many things clear. I checked my “WiFiManager.h” and it looks the same as yours. Nothing about 192.168.244.1.

And yes, I had “No SPIFFS” there. So i tried with “1M SPIFFS” and also “Erase Flash (Skecth and WiFi-settings” on. Still directs me to that weird 192.168.244.1, but serial monitor gives this now:

*WM: [1] Custom AP IP/GW/Subnet: 
*WM: [0] [ERROR] softAPConfig failed! 
*WM: [1] AP IP address: 192.168.244.1
*WM: [3] setupConfigPortal 
*WM: [1] Starting Web Portal 
*WM: [3] dns server started with ip:  192.168.244.1
*WM: [2] HTTP server started 
*WM: [2] WiFi Scan ASYNC started 
*WM: [2] Config Portal Running, blocking, waiting for clients... 
*WM: [2] NUM CLIENTS: 0 
*WM: [2] WiFi Scan ASYNC completed in 2209 ms
*WM: [2] WiFi Scan ASYNC found: 8
*WM: [2] NUM CLIENTS: 1 
*WM: [3] -> www.msftncsi.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [3] -> ncc.avast.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] WiFi Scan ASYNC started 
*WM: [2] WiFi Scan ASYNC completed in 2207 ms
*WM: [2] WiFi Scan ASYNC found: 8
*WM: [3] -> ip-info.ff.avast.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 973 ms ago
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 3277 ms ago
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 4144 ms ago
*WM: [2] <- HTTP Wifi 
*WM: [2] Scan is cached 4808 ms ago
*WM: [1] 8 networks found
*WM: [2] AP:  -65 **********************
*WM: [2] AP:  -66 ************
*WM: [2] AP:  -67 **********
*WM: [2] AP:  -70 *********
*WM: [2] AP:  -74 ********
*WM: [2] AP:  -79 *************
*WM: [2] AP:  -83 **************
*WM: [2] AP:  -85 *************
*WM: [3] _staShowStaticFields 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [3] Sent config page 
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 7457 ms ago
*WM: [3] -> www.msftncsi.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 10915 ms ago
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP WiFi save  
*WM: [3] Method: POST
*WM: [2] Parameters 
*WM: [2] -------------------- 
*WM: [2] blynk: *****************************
*WM: [2] -------------------- 
*WM: [3] static ip: (IP unset)
*WM: [3] static gateway: (IP unset)
*WM: [3] static netmask: (IP unset)
*WM: [3] static DNS: (IP unset)
*WM: [3] Sent wifi save page 
*WM: [2] process connect 
*WM: [2] Connecting as wifi client... 
*WM: [1] STA static IP: (IP unset)
*WM: [2] Custom static IP/GW/Subnet/DNS 
*WM: [2] Custom static DNS 
*WM: [1] STA IP set: (IP unset)
*WM: [3] WIFI station disconnect 
*WM: [1] Connecting to new AP: *******************
*WM: [3] Using Password: ****************
*WM: [3] WiFi station enable 
*WM: [3] enableSTA PERSISTENT ON 
*WM: [1] connectTimeout not set, ESP waitForConnectResult... 
*WM: [2] Connection result: WL_CONNECTED
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [1] Connect to new AP [SUCCESS] 
*WM: [1] Got IP Address: 
*WM: [1] 192.168.10.64 
Should save config
*WM: [2] disconnect configportal 
*WM: [2] restoring usermode STA
*WM: [2] wifi status: WL_CONNECTED
*WM: [2] wifi mode: STA
*WM: [1] config portal exiting 
connected...yeey :)
saving config
{"blynk_token":"*******************************"}BLYNK Connected
*WM: [3] freeing allocated params! 
*WM: [3] unloading 

I have no idea yet why it directs me to that wrong config-site, but still…

my question is… is this NodeMCU properly connected anyway? So it works… but bit weird way?

I try to solve the mystery of 192.168.244.1 still.

Thanks a lot for your help… been a big help

You’re still missing some lines from the start of your serial output. You should keep the serial monitor open, clear the output then press the reset button on your NodeMCU.

What does vebose compiler messages say about the location of your WiFiManager library?

Pete.

Oh sorry bout this. Vebose compiler shows the right place for WiFiManager.h. And I checked it and it should be ok. So working or not? Heres all the serial monitor info:

mounting FS...
mounted file system
reading config file
opened config file
{"blynk_token":"****************************"}
parsed json
*WM: Adding parameter
*WM: blynk
*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Custom STA IP/GW/Subnet
*WM: (IP unset)
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 0
*WM: 
*WM: Configuring access point... 
*WM: Wifi_Manager
*WM: password
*WM: Custom AP IP/GW/Subnet
*WM: AP IP address: 
*WM: 192.168.244.1
*WM: HTTP server started
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Request redirected to captive portal
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Handle root
*WM: Scan done
*WM: **********
*WM: -63
*WM: ***********
*WM: -65
*WM: ********
*WM: -67
*WM: ************
*WM: -72
*WM: **********
*WM: -73
*WM: **********
*WM: -76
*WM: *****************
*WM: -80
*WM: **************
*WM: -84
*WM: ********
*WM: -89
*WM: Sent config page
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Request redirected to captive portal
*WM: Handle root
*WM: WiFi save
*WM: Parameter
*WM: blynk
*WM: **************************
*WM: static ip
*WM: (IP unset)
*WM: static gateway
*WM: (IP unset)
*WM: static netmask
*WM: (IP unset)
*WM: Sent wifi save page
*WM: Connecting to new AP
*WM: Connecting as wifi client...
*WM: Custom STA IP/GW/Subnet
*WM: (IP unset)
*WM: Connection result: 
*WM: 3
Should save config
connected...yeey :)
saving config
{"blynk_token":"*******************"}BLYNK Connected
*WM: freeing allocated params!

This what it says after restart:

mounting FS...
mounted file system
reading config file
opened config file
{"blynk_token":"********************"}
parsed json
*WM: Adding parameter
*WM: blynk
*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Custom STA IP/GW/Subnet
*WM: (IP unset)
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 3
*WM: IP Address:
*WM: 192.168.10.64
connected...yeey :)
BLYNK Connected
*WM: freeing allocated params!

From here

Hi, I am experimenting the issue. The only fix I found is to modify startConfigPortal, by adding
WiFi.mode(WIFI_OFF);
delay(2000);
just before
WiFi.mode(WIFI_AP_STA);
A lower delay might work.
When I do that, I get 100% of the time 192.168.4.1
Otherwise, I get very often 192.168.244.1
Looks like it’s related to ESP8266 core

Best,

Jean

2 Likes

Also being discussed here:

It seems that it’s something to do with changes to the Arduino core to accommodate IPv6.

@Lobotomi what version of the Arduino core are you using?

Pete.

1 Like

Thanks for this info. But where do I find that “startConfigPortal”?

And sorry how do I check the Arduino core version?

But still… Is this working now anyway it´s weird? That I´d like to know… And of course how to fix this

In your .cpp .h files. Mine are stored here… C:\Users\eboli\Documents\Arduino\libraries\WiFiManager