Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- // Nazev Wi-Fi site, do ktere se mam pripojit
- const char* ssid = "Kony";
- // Heslo Wi-Fi site, do ktere se mam pripojit
- const char* password = "heslokwifi";
- char server[] = "konycz.eu"; //URL adresa serveru
- WiFiClient client;
- unsigned long cas = 0;
- String cas_aktualni;
- void setup() {
- // komunikace přes sériovou linku rychlostí 9600 baud
- Serial.begin(9600);
- Serial.println();
- Serial.print("Pripojuji k ");
- Serial.println(ssid);
- WiFi.begin(ssid, password);
- // Dokud nejsem pripojeny k Wi-Fi,zapisuj do seriove linky tecky progressbaru
- while (WiFi.status() != WL_CONNECTED) {
- delay(100);
- Serial.print(".");
- }
- // Jsem pripojeny k Wi-Fi a mohu pokracovat
- Serial.println();
- Serial.println("WiFi pripojena!");
- // Napis IP adresu, kterou mikropocitac dostal
- Serial.print("Pouzij k pripojeni tuto adresu: ");
- Serial.print("http://");
- Serial.println(WiFi.localIP());
- }
- void hodiny() {
- if (millis() - cas >= 6000 || cas == 0) {
- cas = millis();
- if (client.connect(server, 80)) { //starts client connection, checks for connection
- client.println("GET http://konycz.eu/doma/test/cas.php");
- client.println(" HTTP/1.0");
- client.println("Host: konycz.eu");
- // client.println("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
- client.println("Connection: close");
- client.println();
- delay(1000);
- while (client.connected()) {
- String line = client.readStringUntil('\n');
- // Serial.println(line); //ak chceme vypísať HTTP header
- if (line == "\r") {
- break;
- }
- }
- String line = client.readStringUntil('\n');
- // Serial.println("Nacitany payload response: Cas - ");
- Serial.println(line); //odpoveď webservera - naše dáta
- cas_aktualni = line;
- }
- else {
- Serial.println("Pripojenie na webserver sa nepodarilo");
- }
- client.stop();
- }
- Serial.print("Cas : ");
- Serial.println(cas_aktualni);
- }
- void loop() {
- hodiny();
- Serial.println("_________________________");
- delay(5000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement