Guest User

Untitled

a guest
Nov 19th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. //blynk-dhtxxDemo.ino
  2. //octubre 2018
  3. //rPrim Tech, Barcelona
  4.  
  5. //Copyright (C) 2018 by jaume Nogués <jnogues at gmail dot com>
  6.  
  7. #define BLYNK_PRINT Serial
  8. #include <ESP8266WiFi.h>
  9. #include <BlynkSimpleEsp8266.h>
  10.  
  11. #include <OneWire.h>
  12. #include <DallasTemperature.h>
  13. #define ONE_WIRE_BUS 10//GPIO10, potser GPIO9 en algunes nodeMCU
  14. OneWire oneWire(ONE_WIRE_BUS);
  15. DallasTemperature DS18B20(&oneWire);
  16.  
  17. float temperatura=0;//variable per guardar valor de T
  18.  
  19. char auth[] = "YourAuthToken";//afegiu el token del vostre projecte!!
  20.  
  21. char ssid[] = "IoT";
  22. char pass[] = "pitufito";
  23. char vpsServer[] = "vps249990.ovh.net";
  24. //IPAddress ipServer (192, 168, 1, 222);//Servidor local
  25. BlynkTimer timer; // Creem un temporitzador anomenat "timer"!
  26.  
  27.  
  28. void setup()
  29. {
  30. Serial.begin(115200);
  31. pinMode(16, OUTPUT);
  32. DS18B20.begin();
  33. Blynk.begin(auth, ssid, pass,vpsServer,8080);
  34. timer.setInterval(1000L, intermitaLed16);//configuro una tasca que es repeteix cada 1000ms
  35. timer.setInterval(15000L, mesuraTemperatura);//configuro una tasca que es repeteix cada 15s
  36. }
  37.  
  38. void loop()
  39. {
  40. Blynk.run();
  41. timer.run();
  42. }
  43.  
  44. void intermitaLed16()//tasca a repetir cada 1000ms
  45. {
  46. digitalWrite(16, !digitalRead(16));
  47. }
  48.  
  49. void mesuraTemperatura()//tasca dada 15s
  50. {
  51. DS18B20.requestTemperatures();
  52. temperatura = DS18B20.getTempCByIndex(0);
  53.  
  54. Blynk.virtualWrite(V0,temperatura);
  55. Blynk.virtualWrite(V1,humitat);
  56. }
Add Comment
Please, Sign In to add comment