I use Multi wifi i can chenge user and pass of wifi from Text Input or not. Now it not work
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
ESP8266WiFiMulti wifiMulti;
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h> //Blynk
SimpleTimer timer;
#define WIFI_LED 13
char auth[] = "xxxxxxxxxxxxxxxxxxxxx";
char server[] = "192.168.0.X";
char ssid[] = "ArcHeR-OMEN";
char pass[] = "55555555";
char ssid1[] = "";
char pass1[] = "";
int port = 8080;
bool isFirstConnect = true;
int slider;
bool lock1 = false;
String textIn1;
String textIn2;
char c[20] = "";
char f[20] = "";
BLYNK_CONNECTED() {
if (isFirstConnect) {
Blynk.syncAll();
//Blynk.notify("Device 2 Starting!!!!");
isFirstConnect = false;
Serial.println(String("แอพเริ่มทำงาน!!")); // used for debugging
}
}
void CheckUserWiFi()
{
String ssid1 = textIn1;
String pass1 = textIn2;
Serial.println(String("textIn1 : ")+ ssid1); // used for debugging
Serial.println(String("textIn2 : " + pass1)); // used for debugging
}
BLYNK_WRITE(V0) {
textIn1 = param.asStr(); // Text Input Widget - Strings
}
BLYNK_WRITE(V1) {
textIn2 = param.asStr(); // Text Input Widget - Strings
}
BLYNK_WRITE(V2) {
int k = param.asInt();
if(k == 1)
{
String ssid1 = textIn1;
String pass1 = textIn2;
char c[20];
char f[20];
ssid1.toCharArray(c, sizeof(c));
pass1.toCharArray(f, sizeof(f));
wifiMulti.addAP(ssid, pass);
wifiMulti.addAP(c, f);
Serial.println(String("c : ")+ c); // used for debugging
Serial.println(String("f : ")+ f); // used for debugging
Serial.println("Config OK");
String showSave = "บันทึกแล้ว";
Blynk.setProperty(V2, "offLabel", String(showSave));
}else{
}
}
void setup()
{
Serial.begin(115200);
Serial.println("\n Starting");
wifiMulti.addAP(ssid, pass);
wifiMulti.addAP(ssid1, pass1);
wifiMulti.addAP(c, f);
Blynk.config(auth, server, port);
Blynk.connect();
Serial.println("Connecting Wifi...");
if(wifiMulti.run() == WL_CONNECTED) {
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
timer.setInterval(15000, reconnectBlynk); // check every 15 seconds if we are connected to the server
timer.setInterval(10000L, CheckUserWiFi);
}
void reconnectBlynk() // reconnect to server if disconnected, timer checks every 15 seconds
{
if (!Blynk.connected()) {
if(Blynk.connect()) {
BLYNK_LOG("Reconnected");
digitalWrite(WIFI_LED,LOW);
} else {
BLYNK_LOG("Not reconnected");
digitalWrite(WIFI_LED,HIGH);
}
}
}
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();
if(wifiMulti.run() != WL_CONNECTED) {
Serial.println("WiFi not connected!");
delay(1000);
}
}