SHARE
TWEET

Untitled

a guest Jan 23rd, 2020 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define IO_USERNAME    "Addamm"
  2. #define IO_KEY         "1dc26502236e48eb93cd338fb89a5286"
  3.  
  4. #define WIFI_SSID       "TP-LINK_324C"
  5. #define WIFI_PASS       "90379734"
  6.  
  7. #include "AdafruitIO_WiFi.h"
  8. AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
  9. //********************************************************************************
  10. #include <Adafruit_Sensor.h>
  11. #include <DHT.h>
  12.  
  13. #define DHTPIN D6  
  14. #define DHTTYPE DHT22
  15. DHT dht(DHTPIN, DHTTYPE);
  16.  
  17. AdafruitIO_Feed *temperature = io.feed("temperature");
  18. AdafruitIO_Feed *humidity = io.feed("humidity");
  19.  
  20.  
  21. unsigned long startMillis;  
  22. unsigned long currentMillis;
  23. const unsigned long period = 10000;  
  24.  
  25.  
  26. void setup() {
  27.   Serial.begin(115200);  
  28.   startMillis = millis();  
  29.   dht.begin();
  30.  
  31.   Serial.print("Connecting to Adafruit IO");
  32.   io.connect();
  33.   Serial.print("Connected to Adafruit IO");
  34.  
  35.   while (io.status() < AIO_CONNECTED) {
  36.     Serial.print(".");
  37.     delay(500);
  38.     }
  39.  
  40.   Serial.println();
  41.   Serial.println(io.statusText());
  42. }
  43.  
  44. void loop() {
  45.   io.run();
  46.   currentMillis = millis();  
  47.   if (currentMillis - startMillis >= period)  
  48.   {
  49.     startMillis = currentMillis;
  50.       float hum = dht.readHumidity();
  51.       float temp = dht.readTemperature();
  52.  
  53.     Serial.print("celsius: ");
  54.     Serial.print(temp);
  55.     Serial.println("C");
  56.     Serial.print("Humidity: ");
  57.     Serial.print(hum);
  58.     Serial.println("%");
  59.     Serial.println("...................................");
  60.     temperature->save(temp);
  61.     humidity->save(hum);
  62.   }
  63. }
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