More a project FOR Blynk than a project made with Blynk.
Screenshot above of DroidTerm running on my Samsung S3 phone to change the Blynk access credentials of the connected Arduino (with ESP8266). You can change the routers SSID, password and Blynk token details without having access to the Arduino sketch.
So you take that Blynk connected remote control buggy that you built round to a friend’s house and want to demonstrate it, but he doesn’t have access to the Arduino IDE. Or perhaps you have built the latest ‘must have’ Arduino based device but don’t want everyone to ‘borrow’ your sketch.
As long as your friends or clients have access to a Serial connection then they are good to go. The sketch below is the basic details you need to implement this. Very crude coding from a newbie, but it works.
Inspired by recent discussions here with @Lichtsignaal and the WiFIManager built by @tzapulica for ESP8266 standalone systems etc. Please note this sketch is for Arduinos with ESP8266 but NOT standalone.
/*
BlynkSecureV1.0.4.ino built with Arduino 1.6.4 on the 14th Jan 2016
Arduino IOT products with Blynk access via ESP8266 NOT standalone.
You want users to be able to use the Arduino IOT device you made, from different routers and
maybe even with different Blynk tokens, but you don't want users to be able to change the sketch.
Changes are simply made via Serial, no flash webpage options and users will need terminal access to
your device like RealTerm http://realterm.sourceforge.net/index.html or Arduino Serial Monitor etc.
Works with DroidTerm (Pro or Free versions) https://play.google.com/store/apps/details?id=com.felhr.droidterm
1. Connect a switch to Arduino digital pin 5 (this is to change access credentials)
2. Wire up the ESP with a separate switch
3. 1. and 2. could be combined because you only want one switch on at a time
4. Normal operation ESP ON and Access OFF
5. To change Access details boot up with Access ON and ESP OFF
6. Maximum characters: SSID 24 Password 16 Blynk Token 32
7. Baud Rate setting of 115200 for both console and ESP
8. Set Input options to LF and baud of 115200 when using DroidTerm
*/
//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>
#include <EEPROM.h>
// Set ESP8266 Serial object
#define EspSerial Serial
#define SwitchPin 5 // switch on D5
ESP8266 wifi(EspSerial);
char auth[33]; // max 32 plus NULL
char ssid[25]; // max 24 plus NULL
char pwd[17]; // max 16 plus NULL total 75 i.e. array 0 to 74
int address = 0; // first EEPROM address
char newbigstring[75];
int proceedFlag = 1;
String inputString; // a string to hold incoming data
boolean stringComplete = false; // check if data entry string is complete
char inChar;
byte justonce = 0;
void setup()
{
pinMode(SwitchPin, INPUT_PULLUP); // set D5 as input but set high when not pressed
// Set console baud rate
Serial.begin(115200);
delay(10);
for (unsigned int t=0; t<74; t++){ // 0 to 74 is 75 characters which includes 3 NULL's between SSID and pwd and final NULL after auth
newbigstring[t] = EEPROM.read(t);
}
Serial.println("\n Access details for this system.");
Serial.print("\n Network SSID: ");
for (unsigned int t=0; t<25; t++){ //24
ssid[t] = newbigstring[t];
}
char * n = strchr (ssid, '\n'); // search for space or newline or carriage return
if (n) // if found, truncate
*n = 0;
Serial.print(" <");
Serial.print(ssid);
Serial.print(">");
Serial.print("\n Password: "); // miss 1 memory address for final NULL
for (unsigned int t=25; t<42; t++){ //16
pwd[t-25] = newbigstring[t];
}
char * q = strchr (pwd, '\n'); // search for space or newline or carriage return
if (q) // if found, truncate
*q = 0;
Serial.print(" <");
//Serial.print(pwd); // remove comment and comment out row below if you wish to display router password
Serial.print("************");
Serial.print(">");
Serial.print("\n Blynk Token is: "); // miss 1 memory address for final NULL
for (unsigned int t=42; t<74; t++){ //32
auth[t-42] = newbigstring[t];
}
char * r = strchr (auth, '\n'); // search for space or newline or carriage return
if (r) // if found, truncate
*r = 0;
Serial.print(" <");
Serial.print(auth);
Serial.print(">");
Serial.println("\n\n Turn OFF ESP and Turn ON Access Switch");
Serial.println(" then reboot to change the access details");
Serial.println();
delay(3000); // wait 3 seconds to read credential details
// Set ESP8266 baud rate
EspSerial.begin(115200);
delay(10);
Blynk.begin(auth, wifi, ssid, pwd);
}
void(* resetFunc) (void) = 0; //reset function
void loop()
{
if (digitalRead(SwitchPin) == LOW){
if (justonce == 0){
ChangeDetails();
justonce++; // i.e. just on bootup
}
}
if (digitalRead(SwitchPin) == HIGH){
Blynk.run();
}
}
void ChangeDetails(){ // change ssid, pwd or auth
if (digitalRead(SwitchPin) == LOW){
Serial.print("\n\n Enter your SSID: "); // max 24 characters
if (stringComplete) { // print the string when a newline arrives
inputString = ""; // clear the string
stringComplete = false;
}
}
}
void serialEvent() {
if(digitalRead(SwitchPin) == LOW){
while (Serial.available()) {
inChar = (char)Serial.read(); // get the new byte:
inputString += inChar; // add it to the inputString:
if (inChar == '\n') { // if the incoming character is a newline, set a flag so the main loop can do something about it
Serial.println(inputString);
if (proceedFlag == 1){
int SSIDLen = inputString.length();
for (unsigned int t=0; t<SSIDLen; t++){
EEPROM.update(t, inputString[t]);
delay(10);
}
}
if (proceedFlag == 2){
int PWDLen = inputString.length();
for (unsigned int t=0; t<PWDLen; t++){
EEPROM.update((25+t), inputString[t]);
delay(10);
}
}
if (proceedFlag == 3){
int AUTHLen = inputString.length();
for (unsigned int t=0; t<AUTHLen; t++){
EEPROM.update((42+t), inputString[t]);
delay(10);
}
}
proceedFlag ++;
if (proceedFlag == 2){
inputString = "";
Serial.print (F(" Enter your WiFi password: "));
}
if (proceedFlag == 3){
inputString = "";
Serial.print (F(" Enter your 32 character Blynk token: "));
}
if (proceedFlag > 3){
Serial.println(" Turn Access Switch OFF and Swtch ON ESP");
Serial.println(" New credentials stored, rebooting .....");
delay(10000);
resetFunc(); // reset Arduino
}
stringComplete = true;
}
}
}
}