Skip to content

Instantly share code, notes, and snippets.

Created January 14, 2019 01:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxibor/22193342789692b0f8716744bbd8864e to your computer and use it in GitHub Desktop.
Save maxibor/22193342789692b0f8716744bbd8864e to your computer and use it in GitHub Desktop.
Wunderground - Weather underground Temperature Upload with DS18B20 and ESP8266 for Personal Weather Station
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
const char* ssid = "<yourNetworkName>";
const char* password = "<yourNetworkPassword>";
int sleeptime = 300000; // sleep time in ms
#define ONE_WIRE_BUS 2 //nodeMCU-ESP8266 pin D4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress deviceAddress = {0x28, 0xFF, 0xD2, 0xDE, 0xB4, 0x16, 0x05, 0xDA}; // DS18B20 device address see
String WS_ID = "<Wunderground personal weather station ID>";
String WS_SECRET = "<Wunderground personal weather station key>";
String wu_sha1 = "12:DB:BB:24:8E:0F:6F:D4:63:EC:45:DD:5B:ED:37:D7:6F:B1:5F:E5"; // Wunderground https certificate sha1 fingerprint.
void setup () {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
float getTemperature(DeviceAddress deviceAddress){
// method 2 - faster
float tempC = sensors.getTempC(deviceAddress);
Serial.print("Temp C: ");
Serial.print(" Temp F: ");
void wunderground_upload (DeviceAddress deviceAddress, String wu_sha1, String WS_ID, String WS_SECRET){
float thetemp = getTemperature(deviceAddress);
float ftemp = thetemp * 1.8 + 32;
String server = "";
String server_before = "/weatherstation/updateweatherstation.php?ID="+WS_ID+"&PASSWORD="+WS_SECRET+"&dateutc=now&tempf=";
String server_after = "&softwaretype=Arduino&action=updateraw&realtime=1&rtfreq=10";
String server_close = "/ HTTP/1.1\r\nHost: host:port\r\nConnection: close\r\n\r\n";
String server_close2 = "\r\n\r\n\r\n";
String therequest = server+server_before+String(ftemp)+server_after+server_close+server_close2;
HTTPClient http;
http.begin(therequest, wu_sha1);
int httpCode = http.GET();
if (httpCode > 0) {
Serial.printf("HTTP GET ... code: %d\n", httpCode);
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
} else {
Serial.printf("HTTP GET failed, error: %s\n", http.errorToString(httpCode).c_str());
void loop (){
wunderground_upload(deviceAddress, wu_sha1, WS_ID, WS_SECRET);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment