Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 KB | None | 0 0
  1. #define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
  2. #include <ESP8266WiFi.h>
  3. #include <BlynkSimpleEsp8266.h>
  4. #include <BlynkSimpleUserDefined.h>
  5. #include <DHT.h>
  6. #include <SPI.h>
  7. #include <SimpleTimer.h>
  8. // You should get Auth Token in the Blynk App.
  9. // Go to the Project Settings (nut icon).
  10.  
  11. char auth[] = "9f6b50ad57894fe7b3fd07035c17f8b1";
  12. // Your WiFi credentials.
  13. // Set password to "" for open networks.
  14. char ssid[] = "mvn77_home";
  15. char pass[] = "";
  16.  
  17. IPAddress server_ip (192, 168, 0, 254);
  18. // Mac address should be different for each device in your LAN
  19. byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
  20. IPAddress device_ip  (192, 168,   0,  80);
  21. IPAddress dns_ip     (  8,   8,   8,   8);
  22. IPAddress gateway_ip (192, 168,   0,   1);
  23. IPAddress subnet_mask(255, 255, 255,   0);
  24.  
  25.  
  26. #define DHTPIN 2          // What digital pin we're connected to
  27.  
  28. // Uncomment whatever type you're using!
  29. #define DHTTYPE DHT11     // DHT 11
  30. //#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
  31. //#define DHTTYPE DHT21   // DHT 21, AM2301
  32.  
  33. DHT dht(DHTPIN, DHTTYPE);
  34. SimpleTimer timer;
  35.  
  36.  
  37.                                                                              
  38.  
  39. // This function sends Arduino's up time every second to Virtual Pin (5).
  40. // In the app, Widget's reading frequency should be set to PUSH. This means
  41. // that you define how often to send data to Blynk App.
  42. void sendSensor()
  43. {
  44.   float h = dht.readHumidity();
  45.   float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  46.  
  47.   if (isnan(h) || isnan(t)) {
  48.     Serial.println("Failed to read from DHT sensor!");
  49.     return;
  50.   }
  51.   // You can send any value at any time.
  52.   // Please don't send more that 10 values per second.
  53.    Blynk.virtualWrite(V5, h);
  54. Blynk.virtualWrite(V6, t);
  55. }
  56.  
  57.  
  58. void setup()
  59. {
  60.   Serial.begin(9600);
  61.  
  62.   // Setup WiFi network
  63.   WiFi.config(device_ip, gateway_ip, subnet_mask);
  64.   WiFi.begin(ssid, pass);
  65.   dht.begin();
  66.   Blynk.begin(auth, server_ip, 8442 );
  67.    Blynk.connect();
  68.   // Setup a function to be called every second
  69.   timer.setInterval(1000L, sendSensor);
  70. }
  71.  
  72. void loop()
  73. {
  74.   Blynk.run(); // Initiates Blynk
  75.   timer.run(); // Initiates SimpleTimer
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement