Advertisement
Guest User

Untitled

a guest
Jan 31st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. #include <ESP8266Influxdb.h>
  2. #include <ESP8266WiFi.h>
  3. #include <WiFiClient.h>
  4. #include <ESP8266WebServer.h>
  5. #include <ESP8266mDNS.h>
  6. #include <ESP8266HTTPUpdateServer.h>
  7. #include <WiFiUdp.h>
  8. #include <Arduino.h>
  9.  
  10. ADC_MODE(ADC_VCC); // to use getVcc
  11.  
  12. extern "C" {
  13. #include "user_interface.h"
  14. }
  15.  
  16. #include <DHTesp.h>
  17. DHTesp dht;
  18.  
  19. const char* host = "therm2";
  20. const char* ssid = "";
  21. const char* password = "";
  22.  
  23. const char *INFLUXDB_HOST = "poele";
  24. const uint16_t INFLUXDB_PORT = 8086;
  25. const char *DATABASE = "poele";
  26. const char *DB_USER = "";
  27. const char *DB_PASSWORD = "";
  28.  
  29. ESP8266WebServer httpServer(80);
  30. ESP8266HTTPUpdateServer httpUpdater;
  31.  
  32. Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
  33.  
  34. void setup(void)
  35. {
  36.  
  37. //#########################################################################################################
  38. WiFi.mode(WIFI_STA);
  39. WiFi.begin(ssid, password);
  40. while(WiFi.waitForConnectResult() != WL_CONNECTED)
  41. {
  42. WiFi.begin(ssid, password);
  43. }
  44. MDNS.begin(host);
  45. httpUpdater.setup(&httpServer);
  46. httpServer.begin();
  47. MDNS.addService("http", "tcp", 80);
  48. influxdb.opendb(DATABASE, DB_USER, DB_PASSWORD);
  49. //#########################################################################################################
  50.  
  51.  
  52. //GPIO1 (BLUE LED et desactive le TX)
  53. PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_GPIO1);
  54. pinMode(1, OUTPUT);
  55. digitalWrite(1, HIGH); //LED OFF
  56.  
  57.  
  58. //GPIO3 (PIN RX pour le OneWire)
  59. PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_GPIO3);
  60. pinMode(3, OUTPUT);
  61. digitalWrite(3, LOW);
  62. //HighZ
  63. PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0RXD_U);
  64.  
  65.  
  66. dht.setup(3);
  67.  
  68. }
  69.  
  70.  
  71. void loop(void)
  72. {
  73. httpServer.handleClient();
  74. //##################################################################################################################
  75.  
  76.  
  77. delay(dht.getMinimumSamplingPeriod());
  78. float humidity = dht.getHumidity();
  79. float temperature = dht.getTemperature();
  80.  
  81. uint32_t getVcc = ESP.getVcc();
  82. float voltage = 0.0;
  83. voltage = getVcc/1000.0;
  84.  
  85. // Writing data with influxdb HTTP API
  86. String data = "thermo,device=2 value=" + String(temperature);
  87. influxdb.write(data);
  88. delay(5000);
  89. String data2 = "humi,device=2 value=" + String(humidity);
  90. influxdb.write(data2);
  91. delay(5000);
  92. String data3 = "volt,device=2 value=" + String(voltage);
  93. influxdb.write(data3);
  94.  
  95. delay(30000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement