Skip to content

Instantly share code, notes, and snippets.

@teos0009
Created November 11, 2016 08:03
Show Gist options
  • Save teos0009/d2fc73a89e75ff08552f169f6489d112 to your computer and use it in GitHub Desktop.
Save teos0009/d2fc73a89e75ff08552f169f6489d112 to your computer and use it in GitHub Desktop.
#include <DHT.h> // DHT.h library from adafruit
#include <ESP8266WiFi.h> // ESP8266WiFi.h library
#define DHTPIN 4 //GPIO4 = D2
#define DHTTYPE DHT22
const char* ssid = "SSID";
const char* password = "PASSWORD";
const char* host = "api.thingspeak.com";
const char* writeAPIKey = "API_KEY";
//DHT dht(DHTPIN, DHTTYPE, 15);
DHT dht(DHTPIN, DHTTYPE);
void setup() {
//Serial.begin(9600);
// Initialize sensor
dht.begin();
delay(1000);
// Connect to WiFi network
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}
void loop() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
//Serial.print("humidity ");
//Serial.println(humidity);
//Serial.print("temperature ");
//Serial.println(temperature);
if (isnan(humidity) || isnan(temperature)) {
//Serial.println("no dht22 data");
return;
}
// make TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
return;
}
String url = "/update?key=";
url+=writeAPIKey;
url+="&field1=";
url+=String(temperature);
url+="&field2=";
url+=String(humidity);
url+="\r\n";
// Request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(1000);
}
@teos0009
Copy link
Author

teos0009 commented Nov 11, 2016

replaced libm.a in C:\Users\USER_NAME\AppData\Roaming\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9\xtensa-lx106-elf\lib

with the one downloaded from libm.a.tbz at here esp8266/Arduino#612

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment