Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <SPI.h>
- const char* ssid = "Kony";
- const char* password = "Heslo";
- char server[] = "server.eu";
- unsigned long cas = 0;
- String line;
- WiFiClient client;
- void setup() {
- // Nastartuj seriovou linku, do ktere budu vypisovat provozni informace
- pinMode(0, OUTPUT);
- Serial.begin(9600);
- // Pripojeni k Wi-Fi
- 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());
- }
- // Smycka loop se opakuje stale dokola
- void loop() {
- if (millis() - cas >= 6000 || cas == 0) {
- cas = millis();
- if (client.connect(server, 80)) { //starts client connection, checks for connection
- client.println("GET http://server.eu/doma/test/3Dzasuvka.php");
- client.println("Host: server.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:");
- Serial.println(line); //odpoveď webservera - naše dáta
- if(line=="0"){
- digitalWrite(0, LOW);
- Serial.println("Vypnuto");
- }
- else if(line=="1"){
- digitalWrite(0, HIGH);
- Serial.println("Zapnuto");
- }
- }
- else {
- Serial.println("Pripojenie na webserver sa nepodarilo");
- }
- client.stop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement