Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- */
- /*
- char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; //valid auth
- char ssid[] = "aaaaaaaa"; // default ssid
- char pass[] = "bbbbbbbbbbbb"; // default pass
- */
- char auth[] = "6a9442c5d30d4e83a7d5c2xxxxxxxxx"; //valid auth
- char ssid[] = "aaa";
- char pass[] = "12345678";
- char t_auth[] = "77778888999911112222333344445555"; // declare same 32 char
- char t_ssid[] = "same AP name 123456789"; // declare
- char t_pass[] = "same AP password 123456789"; // declare
- #define BLYNK_PRINT Serial
- #include <ESP8266_Lib.h>
- #include <BlynkSimpleShieldEsp8266.h>
- #include <EEPROM.h>
- #define EspSerial Serial // Set ESP8266 Serial object
- ESP8266 wifi(&EspSerial);
- WidgetTerminal terminal(V15);
- const int SW_pin = 8; //Working mode switch. HIGH = default WiFi. LOW = castom WiFi
- String y_ssid = "";
- String y_pass = "";
- String y_auth = "";
- int wpis = 0;
- int dl_i = 0;
- int dl_j = 0;
- int dl_k = 0;
- BLYNK_WRITE(V15)
- {
- String coscos = param.asStr(); // string from terminal
- switch (wpis)
- {
- case 1:
- y_auth = coscos; //from terminal
- dl_i = y_auth.length() + 1; //change string to char[]
- y_auth.toCharArray(t_auth, dl_i); //change string to char[]
- break;
- case 2:
- y_ssid = coscos;
- dl_j = y_ssid.length() + 1;
- y_ssid.toCharArray(t_ssid, dl_j);
- break;
- case 3:
- y_pass = coscos;
- dl_k = y_pass.length() + 1;
- y_pass.toCharArray(t_pass, dl_k);
- break;
- default: ;
- }
- }
- BLYNK_WRITE(V17) //button SETUP
- {
- String coscos;
- int klawin = param.asInt(); //klaw SETUP
- if (klawin == 1) {
- wpis = wpis + 1;
- if ((wpis > 4) || (wpis < 1)) {
- wpis = 1;
- }
- switch (wpis)
- {
- case 1:
- terminal.println("print your auth: ");
- terminal.flush();
- break;
- case 2:
- terminal.println("print your ssid: ");
- terminal.flush();
- break;
- case 3:
- terminal.println("print your pass: ");
- terminal.flush();
- break;
- case 4:
- terminal.print("your auth: ");
- terminal.println(t_auth);
- terminal.print("your ssid: ");
- terminal.println(t_ssid);
- terminal.print("your pass: ");
- terminal.println(t_pass);
- terminal.println("data wifi OK ?");
- terminal.flush();
- break;
- default: ;
- }
- }
- }
- BLYNK_WRITE(V18)
- {
- int klawplus = param.asInt();
- if (klawplus == 1) {
- terminal.println("**** DEF ****");
- terminal.print("auth: ");
- terminal.println(auth);
- terminal.print("ssid: ");
- terminal.println(ssid);
- terminal.print("pass: ");
- terminal.println(pass);
- terminal.println("********");
- terminal.flush();
- }
- }
- BLYNK_WRITE(V19)
- {
- int klawminus = param.asInt();
- if (klawminus == 1) {
- terminal.println("**** SET ****");
- terminal.print("your_auth: ");
- terminal.println(t_auth);
- terminal.print("your_ssid: ");
- terminal.println(t_ssid);
- terminal.print("your_pass: ");
- terminal.println(t_pass);
- terminal.println("********");
- terminal.flush();
- }
- }
- BLYNK_WRITE(V20) //button OK
- {
- int klawok = param.asInt();
- if (klawok == 1) {
- int eeAddr = 0;
- EEPROM.put(eeAddr, auth); //................................auth not change
- eeAddr = 50;
- EEPROM.put(eeAddr, t_ssid);
- eeAddr = 100;
- EEPROM.put(eeAddr, t_pass);
- terminal.println("save new WiFi data");
- terminal.flush();
- }
- }
- BLYNK_WRITE(V21) // button READ for test only
- {
- int klawread = param.asInt();
- if (klawread == 1) {
- int eeAddr = 0;
- EEPROM.get(eeAddr, t_auth);
- eeAddr = 50;
- EEPROM.get(eeAddr, t_ssid);
- eeAddr = 100;
- EEPROM.get(eeAddr, t_pass);
- terminal.print("your data from ee ");
- terminal.println(t_auth);
- terminal.println(t_ssid);
- terminal.println(t_pass);
- terminal.flush();
- }
- }
- void wyborwifi() // choice wifi setup data after reset - SW_pin = HIGH > default wifi, LOW > new setup wifi
- {
- pinMode(SW_pin, INPUT_PULLUP);
- int m = digitalRead(SW_pin);
- if (m == 0) {
- int eeAddr = 0;
- EEPROM.get(eeAddr, t_auth);
- eeAddr = 50;
- EEPROM.get(eeAddr, t_ssid);
- eeAddr = 100;
- EEPROM.get(eeAddr, t_pass);
- Blynk.begin(t_auth, wifi, t_ssid, t_pass);
- }
- else
- {
- Blynk.begin(auth, wifi, ssid, pass);
- }
- }
- //+++++++++++++++++++++++++++++++++++++++++++++++++++ setup
- void setup() {
- Serial.begin(115200); // Set console baud rate
- EspSerial.begin(115200); // Set ESP8266 baud rate
- wyborwifi();
- Serial.println("Arduino.cc 1.6.9"); // Arduino.org doesn't have EEPROM.get i EEPROM.put functions
- }
- void loop() {
- Blynk.run();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement