Facebook
From Crimson Coyote, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 38
  1. #include <ESP8266WiFi.h>
  2. #include <ESP8266HTTPClient.h>
  3. #include "DHT.h"
  4.  
  5. #define DHT11_PIN 2
  6. #define DHTTYPE DHT11
  7.  
  8. DHT dht(DHT11_PIN, DHT11);
  9.  
  10.  
  11. // The commented out fragments will be useful during debugging,
  12. // if we have the ability to display information on the serial port monitor.
  13. // They can be removed during final production.
  14.  
  15.  
  16. const char* ssid = "WIFI_SSID";
  17. const char* password = "WIFI_PASSWORD";
  18.  
  19. // username and password for HTTP Basic Authentication
  20. const char* authUsername = "AUTHORIZATION_USERNAME";
  21. const char* authPassword = "AUTHORIZATION_PASSWORD";
  22.  
  23. void setup () {
  24.  
  25.   WiFi.begin(ssid, password);
  26.  
  27. //  Serial.begin(9600);
  28. //
  29. //  while (WiFi.status() != WL_CONNECTED) {
  30. //
  31. //    delay(1000);
  32. //    Serial.println("Connecting...");
  33. //
  34. //  }
  35.  
  36. }
  37.  
  38. void loop() {
  39.  
  40.   float temp = dht.readTemperature();
  41.   float hum = dht.readHumidity();
  42.  
  43.   if (WiFi.status() == WL_CONNECTED) {
  44.  
  45.     HTTPClient http;
  46.  
  47.     http.begin("http://arduino.gaway.pl/api/measurement/post/");
  48.     http.setAuthorization(authUsername,authPassword);
  49.     http.addHeader("Content-Type", "application/json");
  50.     int httpCode = http.POST("{\"temp\":" + String(temp) + ",\"humidity\":" + String(hum)+" }");
  51.    
  52. //    printing HTTP response
  53. //
  54. //    if (httpCode > 0) {
  55. //      Serial.println(httpCode);
  56. //      String payload = http.getString();
  57. //      Serial.println(payload);
  58. //    }
  59.    
  60.     http.end();
  61.  
  62.   }
  63.  
  64.  
  65.   delay(300000);
  66. }

Replies to githubversion rss

Title Name Language When
Re: githubversion Mustard Stork text 1 Month ago.