Advertisement
Guest User

Untitled

a guest
Oct 28th, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2.  
  3. // Nazev Wi-Fi site, do ktere se mam pripojit
  4. const char* ssid = "Kony";
  5. // Heslo Wi-Fi site, do ktere se mam pripojit
  6. const char* password = "heslokwifi";
  7. char server[] = "konycz.eu"; //URL adresa serveru
  8. WiFiClient client;
  9. unsigned long cas = 0;
  10. String cas_aktualni;
  11.  
  12. void setup() {
  13. // komunikace přes sériovou linku rychlostí 9600 baud
  14. Serial.begin(9600);
  15. Serial.println();
  16. Serial.print("Pripojuji k ");
  17. Serial.println(ssid);
  18. WiFi.begin(ssid, password);
  19.  
  20. // Dokud nejsem pripojeny k Wi-Fi,zapisuj do seriove linky tecky progressbaru
  21. while (WiFi.status() != WL_CONNECTED) {
  22. delay(100);
  23. Serial.print(".");
  24.  
  25. }
  26.  
  27. // Jsem pripojeny k Wi-Fi a mohu pokracovat
  28. Serial.println();
  29. Serial.println("WiFi pripojena!");
  30.  
  31.  
  32. // Napis IP adresu, kterou mikropocitac dostal
  33. Serial.print("Pouzij k pripojeni tuto adresu: ");
  34. Serial.print("http://");
  35. Serial.println(WiFi.localIP());
  36. }
  37.  
  38.  
  39. void hodiny() {
  40. if (millis() - cas >= 6000 || cas == 0) {
  41. cas = millis();
  42. if (client.connect(server, 80)) { //starts client connection, checks for connection
  43. client.println("GET http://konycz.eu/doma/test/cas.php");
  44. client.println(" HTTP/1.0");
  45. client.println("Host: konycz.eu");
  46. // client.println("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
  47. client.println("Connection: close");
  48. client.println();
  49. delay(1000);
  50. while (client.connected()) {
  51. String line = client.readStringUntil('\n');
  52. // Serial.println(line); //ak chceme vypísať HTTP header
  53. if (line == "\r") {
  54. break;
  55. }
  56. }
  57. String line = client.readStringUntil('\n');
  58. // Serial.println("Nacitany payload response: Cas - ");
  59. Serial.println(line); //odpoveď webservera - naše dáta
  60. cas_aktualni = line;
  61. }
  62. else {
  63. Serial.println("Pripojenie na webserver sa nepodarilo");
  64. }
  65. client.stop();
  66. }
  67. Serial.print("Cas : ");
  68. Serial.println(cas_aktualni);
  69. }
  70.  
  71.  
  72. void loop() {
  73. hodiny();
  74. Serial.println("_________________________");
  75. delay(5000);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement