Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- set new wifi
- V15 - terminal
- V17 - button SETUP - setup new wifi data
- V18 - button -View default wifi data
- V19 - button - View new setup wifi data
- V20 - button OK - save to eeprom new setup wifi data
- v21 - button RED - read from eeprom setup wifi data (test only)
- */
- char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; //valid auth
- char ssid[] = "aaaaaaaa"; // default ssid
- char pass[] = "bbbbbbbbbbbb"; // default pass
- 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);
- String y_ssid = "";
- String y_pass = "";
- String y_auth = "";
- int wpis = 1;
- String coscos = "";
- int dl_i = 0;
- int dl_j = 0;
- int dl_k = 0;
- BLYNK_WRITE(V15)
- {
- coscos = param.asStr(); // string from terminal
- switch (wpis)
- {
- case 1:
- terminal.print("your auth: ");
- 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[]
- terminal.println(t_auth);
- terminal.println("print your ssid: ");
- terminal.flush();
- break;
- case 2:
- terminal.print("your ssid: ");
- y_ssid = coscos;
- dl_j = y_ssid.length() + 1;
- y_ssid.toCharArray(t_ssid, dl_j);
- terminal.println(t_ssid);
- terminal.println("print your pass: ");
- terminal.flush();
- break;
- case 3:
- terminal.print("your pass: ");
- y_pass = coscos;
- dl_k = y_pass.length() + 1;
- y_pass.toCharArray(t_pass, dl_k);
- terminal.println(t_pass);
- terminal.print("your ssid: ");
- terminal.println(t_ssid);
- terminal.print("your auth: ");
- terminal.println(t_auth);
- terminal.println("data wifi OK ?");
- terminal.flush();
- break;
- default: ;
- }
- wpis = wpis + 1;
- if (wpis > 3) {
- wpis = 1;
- }
- if (wpis < 1) {
- wpis = 1;
- }
- }
- int klawin = 0;
- BLYNK_WRITE(V17) //button SETUP
- {
- klawin = param.asInt(); //klaw SETUP
- if (klawin == 1) {
- wpis = 1;
- terminal.println("print your auth: ");
- terminal.flush();
- }
- }
- int klawplus = 0;
- BLYNK_WRITE(V18)
- {
- 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.flush();
- terminal.println("********");
- terminal.flush();
- }
- }
- int klawminus = 0;
- BLYNK_WRITE(V19)
- {
- 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.flush();
- terminal.println("********");
- terminal.flush();
- }
- }
- int klawok = 0;
- BLYNK_WRITE(V20) //button OK
- {
- klawok = param.asInt();
- if (klawok == 1) {
- int eeAddr = 0;
- EEPROM.put(eeAddr, auth); //................................not change auth
- eeAddr = 50;
- EEPROM.put(eeAddr, t_ssid);
- eeAddr = 100;
- EEPROM.put(eeAddr, t_pass);
- terminal.println("save to eeprom");
- terminal.flush();
- }
- }
- int klawread = 0;
- BLYNK_WRITE(V21) // button READ
- {
- 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.println("read from eeprom");
- 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 - pin 8 = HIGH > default wifi, LOW > new setup wifi
- {
- pinMode(8, INPUT_PULLUP);
- int m = digitalRead(8);
- 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