daily pastebin goal
95%
SHARE
TWEET

Untitled

a guest Mar 24th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Arduino.h>
  2.  
  3. #include <ESP8266WiFi.h>
  4. #include <ESP8266WiFiMulti.h>
  5.  
  6. #include <ESP8266HTTPClient.h>
  7.  
  8. #include <WiFiClient.h>
  9.  
  10. byte hud_sensor = A0;
  11.  
  12. ESP8266WiFiMulti WiFiMulti;
  13.  
  14. void setup() {
  15.  
  16.     pinMode(9, OUTPUT);
  17.     pinMode(10, OUTPUT);
  18.    
  19.  
  20.   Serial.begin(115200);
  21.   // Serial.setDebugOutput(true);
  22.  
  23.   Serial.println();
  24.   Serial.println();
  25.   Serial.println();
  26.  
  27.   for (uint8_t t = 4; t > 0; t--) {
  28.     Serial.printf("[SETUP] WAIT %d...\n", t);
  29.     Serial.flush();
  30.     delay(1000);
  31.   }
  32.  
  33.   WiFi.mode(WIFI_STA);
  34.   WiFiMulti.addAP("netis2419", "gyeskova");
  35.  
  36. }
  37.  
  38. void loop() {
  39.   // wait for WiFi connection
  40.   if ((WiFiMulti.run() == WL_CONNECTED)) {
  41.  
  42.     WiFiClient client;
  43.  
  44.     HTTPClient http;
  45.  
  46.     Serial.print("[HTTP] begin...\n");
  47.    
  48.     int vlhkost = 1023 - analogRead(hud_sensor);  // vzorec z netu
  49.  
  50.     /*TOTE DIODY*/
  51.  if(vlhkost >= 0 && vlhkost < 150){
  52.       digitalWrite(9, HIGH);
  53.       digitalWrite(10, LOW);
  54.      
  55.    } else if(vlhkost >= 150 && vlhkost < 250){
  56.      
  57.       digitalWrite(9, LOW);
  58.       digitalWrite(10, LOW);
  59.    } else if(vlhkost >= 250 && vlhkost <= 1023){
  60.       digitalWrite(9, LOW);
  61.       digitalWrite(10, HIGH);
  62.      
  63.    }
  64.  
  65.  
  66.    
  67.  
  68.     /*KONIEC => TOTE DIODY*/
  69.    
  70.     if (http.begin(client, "http://vermi.xyz/api/zapis.php?teplota=" + String(vlhkost))) {  // http adresa to co potrebujes vratene subor.php a atributov za ? ....
  71.  
  72.  
  73.       Serial.print("[HTTP] GET...\n");
  74.       // start connection and send HTTP header
  75.       int httpCode = http.GET();
  76.  
  77.       // httpCode will be negative on error
  78.       if (httpCode > 0) {
  79.         // HTTP header has been send and Server response header has been handled
  80.         Serial.printf("[HTTP] GET... code: %d\n", httpCode);
  81.  
  82.         // file found at server
  83.         if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
  84.           String payload = http.getString();
  85.           Serial.println(payload);
  86.         }
  87.       } else {
  88.         Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
  89.       }
  90.  
  91.       http.end();
  92.     } else {
  93.       Serial.printf("[HTTP} Unable to connect\n");
  94.     }
  95.   }
  96.    
  97.   delay(60000);
  98. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top