Advertisement
Krzyspx

setupwifi2

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