Advertisement
Krzyspx

setupwifi1

Sep 4th, 2016
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.91 KB | None | 0 0
  1. /*
  2. set new wifi
  3.  
  4. V15 - terminal
  5. V17 - button SETUP - setup new wifi data
  6. V18 - button -View default wifi data
  7. V19 - button - View new setup wifi data
  8. V20 - button OK - save to eeprom new setup wifi data
  9. v21 - button RED - read from eeprom setup wifi data (test only)
  10.  
  11. */
  12.  
  13.  
  14. char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; //valid auth
  15. char ssid[] = "aaaaaaaa";   // default ssid
  16. char pass[] = "bbbbbbbbbbbb"; // default pass
  17.  
  18. char t_auth[] = "77778888999911112222333344445555"; // declare same 32 char
  19. char t_ssid[] = "same AP name 123456789"; // declare
  20. char t_pass[] = "same AP password 123456789"; // declare
  21.  
  22. #define BLYNK_PRINT Serial    
  23. #include <ESP8266_Lib.h>
  24. #include <BlynkSimpleShieldEsp8266.h>
  25. #include <EEPROM.h>
  26.  
  27. #define EspSerial Serial // Set ESP8266 Serial object
  28. ESP8266 wifi(&EspSerial);
  29.  
  30. WidgetTerminal terminal(V15);
  31.  
  32. String      y_ssid = "";
  33. String      y_pass = "";
  34. String      y_auth = "";
  35.  
  36.  
  37. int wpis = 1;
  38. String coscos = "";
  39. int dl_i = 0;
  40. int dl_j = 0;
  41. int dl_k = 0;
  42. BLYNK_WRITE(V15)
  43. {
  44.   coscos = param.asStr(); // string from terminal
  45.   switch (wpis)  
  46.   {
  47.  
  48.     case 1:
  49.       terminal.print("your auth: ");
  50.       y_auth = coscos;  //from terminal
  51.  
  52.       dl_i = y_auth.length() + 1;  //change string to char[]
  53.       y_auth.toCharArray(t_auth, dl_i); //change string to char[]
  54.  
  55.       terminal.println(t_auth);
  56.       terminal.println("print your ssid: ");
  57.       terminal.flush();
  58.       break;
  59.     case 2:
  60.       terminal.print("your ssid: ");
  61.       y_ssid = coscos;
  62.  
  63.       dl_j = y_ssid.length() + 1;
  64.       y_ssid.toCharArray(t_ssid, dl_j);
  65.  
  66.       terminal.println(t_ssid);
  67.       terminal.println("print your pass: ");
  68.       terminal.flush();
  69.       break;
  70.     case 3:
  71.       terminal.print("your pass: ");
  72.       y_pass = coscos;
  73.  
  74.       dl_k = y_pass.length() + 1;
  75.       y_pass.toCharArray(t_pass, dl_k);
  76.  
  77.       terminal.println(t_pass);
  78.       terminal.print("your ssid: ");
  79.       terminal.println(t_ssid);
  80.       terminal.print("your auth: ");
  81.       terminal.println(t_auth);
  82.       terminal.println("data wifi OK ?");
  83.       terminal.flush();
  84.       break;
  85.     default: ;
  86.   }
  87.  
  88.   wpis = wpis + 1;
  89.   if (wpis > 3) {
  90.     wpis = 1;
  91.   }
  92.   if (wpis < 1) {
  93.     wpis = 1;
  94.  
  95.   }
  96. }
  97.  
  98.  
  99. int klawin = 0;
  100. BLYNK_WRITE(V17) //button SETUP
  101. {
  102.   klawin = param.asInt(); //klaw SETUP
  103.   if (klawin == 1) {
  104.     wpis = 1;
  105.     terminal.println("print your auth: ");
  106.     terminal.flush();
  107.   }
  108. }
  109. int klawplus = 0;
  110. BLYNK_WRITE(V18)
  111. {
  112.   klawplus = param.asInt();
  113.   if (klawplus == 1) {
  114.     terminal.println("**** DEF ****");
  115.     terminal.print("auth: ");
  116.     terminal.println(auth);
  117.     terminal.print("ssid: ");
  118.     terminal.println(ssid);
  119.     terminal.print("pass: ");
  120.     terminal.println(pass);
  121.     terminal.flush();
  122.     terminal.println("********");
  123.     terminal.flush();
  124.   }
  125. }
  126.  
  127. int klawminus = 0;
  128. BLYNK_WRITE(V19)
  129. {
  130.   klawminus = param.asInt();
  131.   if (klawminus == 1) {
  132.     terminal.println("**** SET ****");
  133.     terminal.print("your_auth: ");
  134.     terminal.println(t_auth);
  135.     terminal.print("your_ssid: ");
  136.     terminal.println(t_ssid);
  137.     terminal.print("your_pass: ");
  138.     terminal.println(t_pass);
  139.     terminal.flush();
  140.     terminal.println("********");
  141.     terminal.flush();
  142.   }
  143.  
  144. }
  145. int klawok = 0;
  146. BLYNK_WRITE(V20) //button OK
  147. {
  148.  
  149.   klawok = param.asInt();
  150.   if (klawok == 1) {
  151.  
  152.     int eeAddr = 0;
  153.     EEPROM.put(eeAddr, auth); //................................not change auth
  154.  
  155.     eeAddr = 50;
  156.     EEPROM.put(eeAddr, t_ssid);
  157.  
  158.     eeAddr = 100;
  159.     EEPROM.put(eeAddr, t_pass);
  160.  
  161.     terminal.println("save to eeprom");
  162.     terminal.flush();
  163.  
  164.   }
  165. }
  166.  
  167. int klawread = 0;
  168. BLYNK_WRITE(V21) // button READ
  169. {
  170.  
  171.   klawread = param.asInt();
  172.   if (klawread == 1) {
  173.  
  174.     int eeAddr = 0;
  175.     EEPROM.get(eeAddr, t_auth);
  176.  
  177.     eeAddr = 50;
  178.     EEPROM.get(eeAddr, t_ssid);
  179.  
  180.     eeAddr = 100;
  181.     EEPROM.get(eeAddr, t_pass);
  182.  
  183.  
  184.     terminal.println("read from eeprom");
  185.     terminal.print("your data from ee ");
  186.     terminal.println(t_auth);
  187.     terminal.println(t_ssid);
  188.     terminal.println(t_pass);
  189.  
  190.     terminal.flush();
  191.  
  192.   }
  193. }
  194.  
  195. void wyborwifi() // choice wifi setup data after reset - pin 8 = HIGH > default wifi, LOW > new setup wifi
  196. {
  197.   pinMode(8, INPUT_PULLUP);
  198.  
  199.   int m = digitalRead(8);
  200.   if (m == 0) {
  201.  
  202.     int eeAddr = 0;
  203.     EEPROM.get(eeAddr, t_auth);
  204.  
  205.     eeAddr = 50;
  206.     EEPROM.get(eeAddr, t_ssid);
  207.  
  208.     eeAddr = 100;
  209.     EEPROM.get(eeAddr, t_pass);
  210.  
  211.     Blynk.begin(t_auth, wifi, t_ssid, t_pass);
  212.   }
  213.   else
  214.   {
  215.     Blynk.begin(auth, wifi, ssid, pass);
  216.   }
  217.  
  218. }
  219.  
  220. //+++++++++++++++++++++++++++++++++++++++++++++++++++   setup
  221.  
  222. void setup() {
  223.  
  224.   Serial.begin(115200);  // Set console baud rate
  225.   EspSerial.begin(115200);  // Set ESP8266 baud rate
  226.  
  227.   wyborwifi();
  228.  
  229.   Serial.println("Arduino.cc 1.6.9"); //  Arduino.org  doesn't have  EEPROM.get i EEPROM.put functions
  230. }
  231.  
  232. void loop() {
  233.   Blynk.run();
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement