├── .travis.yml ├── README.md ├── cloud_data_logger └── cloud_data_logger.ino └── dht_test └── dht_test.ino /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | sudo: false 3 | before_install: 4 | - source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh) 5 | install: 6 | - arduino --install-library "DHT sensor library" 7 | script: 8 | - build_platform esp8266 9 | notifications: 10 | email: 11 | on_success: change 12 | on_failure: change -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cloud Temperature Logger with the ESP8266 [![Build Status](https://travis-ci.org/openhomeautomation/esp8266-cloud.svg)](https://travis-ci.org/openhomeautomation/esp8266-cloud) 2 | 3 | Cloud temperature logger using the ESP8266 chip with Dweet.io & Freedboard.io 4 | 5 | You can find the article on our website: 6 | 7 | [https://www.openhomeautomation.net/cloud-temperature-logger-esp8266/](https://www.openhomeautomation.net/cloud-temperature-logger-esp8266/) 8 | -------------------------------------------------------------------------------- /cloud_data_logger/cloud_data_logger.ino: -------------------------------------------------------------------------------- 1 | // Import required libraries 2 | #include "ESP8266WiFi.h" 3 | #include "DHT.h" 4 | 5 | // WiFi parameters 6 | const char* ssid = "your_wifi_network"; 7 | const char* password = "your_wifi_password"; 8 | 9 | // Pin 10 | #define DHTPIN 5 11 | 12 | // Use DHT11 sensor 13 | #define DHTTYPE DHT11 14 | 15 | // Initialize DHT sensor 16 | DHT dht(DHTPIN, DHTTYPE, 15); 17 | 18 | // Host 19 | const char* host = "dweet.io"; 20 | 21 | void setup() { 22 | 23 | // Start Serial 24 | Serial.begin(115200); 25 | delay(10); 26 | 27 | // Init DHT 28 | dht.begin(); 29 | 30 | // We start by connecting to a WiFi network 31 | Serial.println(); 32 | Serial.println(); 33 | Serial.print("Connecting to "); 34 | Serial.println(ssid); 35 | WiFi.begin(ssid, password); 36 | while (WiFi.status() != WL_CONNECTED) { 37 | delay(500); 38 | Serial.print("."); 39 | } 40 | 41 | Serial.println(""); 42 | Serial.println("WiFi connected"); 43 | Serial.println("IP address: "); 44 | Serial.println(WiFi.localIP()); 45 | } 46 | 47 | void loop() { 48 | 49 | Serial.print("Connecting to "); 50 | Serial.println(host); 51 | 52 | // Use WiFiClient class to create TCP connections 53 | WiFiClient client; 54 | const int httpPort = 80; 55 | if (!client.connect(host, httpPort)) { 56 | Serial.println("connection failed"); 57 | return; 58 | } 59 | 60 | // Reading temperature and humidity 61 | int h = dht.readHumidity(); 62 | // Read temperature as Celsius 63 | int t = dht.readTemperature(); 64 | 65 | // This will send the request to the server 66 | client.print(String("GET /dweet/for/myesp8266?temperature=") + String(t) + "&humidity=" + String(h) + " HTTP/1.1\r\n" + 67 | "Host: " + host + "\r\n" + 68 | "Connection: close\r\n\r\n"); 69 | delay(10); 70 | 71 | // Read all the lines of the reply from server and print them to Serial 72 | while(client.available()){ 73 | String line = client.readStringUntil('\r'); 74 | Serial.print(line); 75 | } 76 | 77 | Serial.println(); 78 | Serial.println("closing connection"); 79 | 80 | // Repeat every 10 seconds 81 | delay(10000); 82 | 83 | } 84 | 85 | -------------------------------------------------------------------------------- /dht_test/dht_test.ino: -------------------------------------------------------------------------------- 1 | // Libraries 2 | #include "DHT.h" 3 | 4 | // Pin 5 | #define DHTPIN 5 6 | 7 | // Use DHT11 sensor 8 | #define DHTTYPE DHT11 9 | 10 | // Initialize DHT sensor 11 | DHT dht(DHTPIN, DHTTYPE, 15); 12 | 13 | void setup() { 14 | 15 | // Start Serial 16 | Serial.begin(115200); 17 | 18 | // Init DHT 19 | dht.begin(); 20 | } 21 | 22 | void loop() { 23 | 24 | // Reading temperature and humidity 25 | float h = dht.readHumidity(); 26 | // Read temperature as Celsius 27 | float t = dht.readTemperature(); 28 | 29 | // Display data 30 | Serial.print("Humidity: "); 31 | Serial.print(h); 32 | Serial.print(" %\t"); 33 | Serial.print("Temperature: "); 34 | Serial.print(t); 35 | Serial.println(" *C "); 36 | 37 | // Wait a few seconds between measurements. 38 | delay(2000); 39 | 40 | } 41 | --------------------------------------------------------------------------------