Change auth, ssid and pass from BLYNK terminal for NANO+ESP-01 project

@Costas thank you as always! :slight_smile:
(my personal reflection on forum. Can be confusing as you said because it show you only last posts and donā€™t load all)

@Lichtsignaal could be a good idea, for example taking care of some ā€œimportantā€ sketch like that (and costasā€™) that can be putted in evidence or something similar to avoid lost them in the forum with other request

and perhaps such a procedure PUT and GET EEPROM for ESP8266 standalone

  EEPROM.begin(512);
  EEPROM.put(adrauth, t_auth);
  EEPROM.put(adrssid, t_ssid);
  EEPROM.put(adrpass, t_pass);
  EEPROM.end();
.............
  EEPROM.begin(512);
  EEPROM.get(adrauth, t_auth);
  EEPROM.get(adrssid, t_ssid);
  EEPROM.get(adrpass, t_pass);
  EEPROM.get(adrflagawifi, setp);
  EEPROM.commit();
  EEPROM.end();

Itā€™s checked - works

Hi, Costas can you able to share your code of working in ESP standalone ? I could not figures out. I read several time and truth is I am tangled :tired_face:

me trying to connect D1 mini to friendsā€™ network too when I am there

@speed57 for ESP in Standalone mode have you tried the last sketch I posted at Change auth, ssid and pass from BLYNK terminal for NANO+ESP-01 project

One very easy fix for connecting to the network of friends and family is for you all to have the same SSID and PWD on your router. We use this method and also have the same SSID and PWD on our Android phone for tethering so a single sketch (without any EEPROM content) can access the internet anywhere.

@Costas thank you for q answer. I added Terminal widget and changed all serial.println to terminal.println but no luck.

@speed57 I donā€™t think changing from Serial Monitor to Terminal widget should be a problem.

Did you actually try my last sketch as it is, without any changes?

Perhaps post your sketch and any errors you have.

Yes I did.

/* EEPROMhandler.ino  ESP EEPROM Read and write for Blynk by Costas 12th Sept 2016
 * Remember char myChar = 'A' and char myChar = 65 are equivalent   */
  #include <EEPROM.h>             // ESP8266 EEPROM library
  #define BLYNK_PRINT Serial      // Comment this out to disable prints and save space
  #include <ArduinoOTA.h>         // for local OTA updates
  #include <ESP8266WiFi.h>
  #include <BlynkSimpleEsp8266.h>
  #include <SimpleTimer.h>        // Essential for almost all sketches
  SimpleTimer timer;

  WidgetTerminal terminal(V0);
  
  //********************* SECTION FOR YOU TO COMPLETE WITH YOUR DETAILS ***************************
  // You should get Auth Token in the Blynk App.
  char auth[] = "xxxxxxed9bb9637"; // Go to the Project Settings (nut icon).
  //char cloudserver[16] = "blynk-cloud.com";
  //char localserver[16] = "192.168.10.229";         // Enter your IP details for the local server
  char ssid[] = "xx";                  // Your WiFi credentials.
  char pass[] = "8xxx";                      // Set password to "" for open networks.
  char OTAhost[] = "EEPROMhandler";                // Optional, but very useful
  //***********************************************************************************************
          
  String theData = "BLYNK  Token size 32  characters";     // e.g Your String to be stored in EEPROM
  char DataRetrieved[33];  // char array of data retrieved from EEPROM
  int DataLocation;  // e.g. address 0 for bootflag, 1 to 33 for token, 34 to 66 for SSID and 67 to 99 for PWD

void setup() {
  Serial.begin(115200);
  terminal.println("\Starting");  
  terminal.flush();
  EEPROM.begin(100); // max 512 bytes of EEPROM starting at address 0
  DataLocation = 1; // e.g. for Blynk token
  EEPROMputE(DataLocation, theData);  // save the TOKEN in EEPROM
  delay(50);
  EEPROMgetE(DataLocation, theData);
  delay(50);
  // ****************************Now check EEPROM write and read******************************
  if(DataRetrieved[18] == '3'){ 
    terminal.println("Smartphone AP boot - row 36");
    terminal.flush();
  }
  if(DataRetrieved[19] == '2'){  
    terminal.println("EEPROM boot - row 39");
    terminal.flush();
  }
  // ****************************End of checking EEPROM write and read************************ 
  //Blynk.begin(auth, ssid, pass, localserver);   // change localserver to cloudserver for Blynk cloud server         
  Blynk.begin(auth, ssid, pass);
  int mytimeout = millis() / 1000;
  while (Blynk.connect(1000) == false) {        // wait here until connected to the server
    if((millis() / 1000) > mytimeout + 8){      // try to connect to the server for less than 9 seconds
      break;                                    // continue with the sketch regardless of connection to the server
    }
  }    
  ArduinoOTA.setHostname(OTAhost);   
  ArduinoOTA.begin();                           // for local OTA updates   
}

void EEPROMputE(int DataLocation, String theData){  // Store DATA in EEPROM
  int lenofstr = theData.length() + 1;  // holds length of the String PLUS 1 to cover null terminator of array
  char Data2bStored[lenofstr];  // e.g 32 characters + 1 null terminator for Blynk TOKEN field, also max for SSID and PWD       
  theData.toCharArray(Data2bStored, lenofstr); 
  for(int j = 0; j < (theData.length()); j++){
    EEPROM.write(DataLocation + j, Data2bStored[j]);
    EEPROM.commit();
    delay(5);  
  } 
  terminal.println("DATA stored OK"); 
  terminal.flush();
}

void EEPROMgetE(int DataLocation, String theData){     // Read DATA from EEPROM
  char value;                                    // Each retrieved char from EEPROM
  for(int k = 0; k < (theData.length()); k++){   // Token, SSID and PWD 32 character fields
    value = EEPROM.read(DataLocation + k);
    DataRetrieved[k] = value;  // place characters retrieved from EEPROM in char array
                        // ****Comment out this Serial print section******* 
    if((DataLocation + k)< 10){
      Serial.print(" ");                         // pad out address by 1 character for display purposes
    }
    Serial.print(DataLocation + k);
    Serial.print("   ");
    terminal.println(value);
    terminal.flush();
                       //  ****End of Serial print section*****************
    delay(5); 
  } 
  Serial.print("DATA read OK of: \""); 
  Serial.print(DataRetrieved);
  terminal.println("\"");  
  terminal.flush();
}

void reconnectBlynk() {                         // reconnect to server if disconnected, timer checks every 60 seconds
  if (!Blynk.connected()) {
    if(Blynk.connect()) {
      BLYNK_LOG("Reconnected");
    } else {
      BLYNK_LOG("Not reconnected");
    }
  }
}

void loop() {
  if (Blynk.connected()) {   // to ensure that Blynk.run() function is only called if we are still connected to the server
    Blynk.run();
  }
  timer.run();
  ArduinoOTA.handle();       // for local OTA updates  
  yield();
}

I just put terminal widget

You have several calls to the Terminal BEFORE you are connected to Blynk and this is impossible. If you have Terminal set up correctly then the calls made after you are connected should be fine.

Edit: actually all your calls to Terminal are before your connection to Blynk so you will never see anything in the Terminal widget.

Hmm, I did not know that. So how do I do, can you give me an example please based on above sketch ?

Itā€™s the same with ALL widgets, they only become available when connected to Blynk, hence the reason we are using Blynk.

Perhaps if you explain what you want to do it might help.

I am using 2 relays for switching ignition and starter. I have 2 buttons and one terminal widget and also 2 LED indicators on the app. I want to my D1 mini connected to another wifi hotspot(friendsā€™ or any other wifi ) or I want to manually enter ssid and pass.

@speed57 I looked through my last sketch and noticed that all it did was create two functions for the ESP called EEPROMputE() and EEPROMgetE() which each take 2 variables. The first is an integer variable for the data location in EEPROM to read or write to / from and the second is a String variable for the data to be stored (Blynk token, SSID or pwd etc).

You need to use these two functions in the sketch I provided before I created the functions, substituting the functions for the regular EEPROM functions.

Guys, I know it is old topicā€¦ At the beggining I understood the topic, now I get lost. Can anyone please paste the code that I need to have if I want the ability to change ssid and password. I am using Thermostat_X in my minicamper for controlling the heater. Usually I connect it to my phones AP, but I would need the possibility to easily change ssid and password if I have free wifi signal in campsite.