Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #define BLYNK_PRINT Serial
  2.  
  3. #include <ESP8266WiFi.h>
  4. #include <BlynkSimpleEsp8266.h>
  5.  
  6. const char* ssid     = "ITStep-Student";
  7. const char* password = "studentstudent";
  8. const char* token    = "4c3112a82451477c8c8f548f94413ec7";
  9.  
  10. bool login() {
  11.   const char* host = "wifi.itstep.kiev.ua";
  12.   const int httpPort = 80;
  13.   String url = "/?request=&ADD";
  14.  
  15.   WiFiClient client;
  16.   if (!client.connect(host, httpPort)) {
  17.     return false;
  18.   }
  19.  
  20.   client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
  21.   unsigned long timeout = millis();
  22.   while (client.available() == 0) {
  23.     if (millis() - timeout > 5000) {
  24.       client.stop();
  25.       return false;
  26.     }
  27.   }
  28.  
  29.   return true;
  30. }
  31.  
  32. void setup() {
  33.   Serial.begin(115200);
  34.   delay(10);
  35.  
  36.   Serial.println();
  37.   Serial.println();
  38.   Serial.print("Connecting to ");
  39.   Serial.println(ssid);
  40.  
  41.   WiFi.mode(WIFI_STA);
  42.   WiFi.begin(ssid, password);
  43.  
  44.   while (WiFi.status() != WL_CONNECTED) {
  45.     delay(500);
  46.     Serial.print(".");
  47.   }
  48.  
  49.   Serial.println("");
  50.   Serial.println("WiFi connected");
  51.   Serial.println("IP address: ");
  52.   Serial.println(WiFi.localIP());
  53.  
  54.   Serial.println("Loginning to IT-Step WiFi...");
  55.   while (!login()) {}
  56.   Serial.println("Done!");
  57.   Serial.println("");
  58.  
  59.   Blynk.config(token);
  60.   Serial.println("Connecting to Blynk server...");
  61.   while (!Blynk.connect()) {}
  62.   Serial.println("Done!");
  63.   Serial.println("");
  64. }
  65.  
  66. void loop() {
  67.   Blynk.run();
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement