Declaring Blynk auth code in Setup(). is this possible?

My project involves starting an ESP8266 in Access Point mode, then loading a web page for a user to enter their WiFi SSID, Password and Blynk Auth Code that is saved to EEPROM.

When these details are correct, the ESP re-starts in Client mode in order to connect to Blynk.

The problem is that Iwant to declare the WiFi SSID, Password and Blynk Auth Code in setup() (loaded from EEPROM). It seems that the WIFI SSID and WiFi Password work in this manner but the Blynk Auth code is invalid.

This works:

const char authCode[] = “xxxxxxxxxxxxxxxxxxxxx”;

setup(){
char wifiPassword[]= “passwordxxx”;
char wifiSSID[] =“ssidxxx”;
Blynk.begin(authCode, wifiSSID, wifiPassword);
}

but this throws an invalid auth code:

setup(){
const char authCode[] = “xxxxxxxxxxxxxxxxxxxxx”;
char wifiSSID[] =“ssidxxx”;
char wifiPassword[]= “passwordxxx”;
Blynk.begin(authCode, wifiSSID, wifiPassword);
}

Is it possible to declare the auth code dynamically?

It should work if you change const char to char.
The way auth tokens are normally changed dynamically is with a library called WiFiManager. It is written by a fellow Blynker @tzapulica

Thank you Costas,

I changed const char to char as follows but still it gives and invalid auth code:

setup(){
char authCode[] = “xxxxxxxxxxxxxxxxxxxxx”;
char wifiSSID[] =“ssidxxx”;
char wifiPassword[]= “passwordxxx”;
Blynk.begin(authCode, wifiSSID, wifiPassword);
}

I have installed WiFIManager but I cannot understand how to use it. I will read the documentation more closely.

Are you sure the token you have is valid?

In WiFiManager you need to look at the “additional parameters” docs. The token becomes an additional parameter that you enter via the browser interface.

Yes the authorisation code is valid because I get a normal blynk connection when it is declared prior to setup().
When I cut and paste the auth code declaration into setup(). and run, I get an invalid auth code.
I am looking at wifimanager but it will not start in access point mode for me for some reason. More reading and experimentation is required.

Don’t put the token in setup() then. You can redefine a token with WiFiManager or other tools.

Problem solved. It now works.
.
My web page delivered the token as a string and it needs to be converted to char array and then copied into the Blynk token char array.

The solution is:
1- Declare the Blynk Authorisation Token to be returned from the web page as a global String; eg String strBToken ="";

2- Declare the Blynk Authorisation Token to be used in Blynk.begin() as a global char array variable before setup(): eg char charBToken[] ="";

3- In setup() retrieve the token from the web page or EEPROM as a String:

4- Declare a temporary dummy array: eg char dummy[strBToken.length() +1];

5- Convert the token as String to the dummy char array using strBToken.toCharArray(dummy,strBToken.length() +1);

6- Copy the resultant char array into the global token char array: eg strcopy (charBToken, dummy);

7- Intitate blynk: Blynk.begin(charBToken, “SSID” , “Password”);

I have also managed to get WiFiManger to work as well.

Costas, thank you for your assistance.

Sorry and apologies.
I messed up the numbering of the points in the previous post. They should have been points 1 to 7.

@Phillip glad you got it sorted. The site has strange ways of handling numbering. Could you edit the numbered post and put them as '1 '2 '3 etc, doesn’t look pretty but better than weird numbers everywhere.