ESP8266: Uploading Weather Data to

A couple of months ago I designed a small weather station to measure weather data such as temperature, humidity and barometric pressure using an ESP8266 module and a couple of sensors. How this outdoor weather sensor is constructed is described in an older blog post. allows to connect a home made weather station to its network of weather stations around the world (currently >40.000). This may help to improve the data which is provided by

Uploading measured weather data is easily accomplished by performing an HTTP POST to using basic authentication.

This manual describes how to upload weather data. Which weather details may be submitted in the post is illustrated in the table of the manual.


An account for is required. The username and password must be translatedinto BASE64 encoding. This online tool helps to transfer username:password for into the required format.

The location of the weather station is required as GPS coordinates. The latitude and the longitude of the location of the weather station can be determined with google maps for example. All it needs is to click on the location on the map. The coordinates will be displayed in a small window below the adress.

Components used

Outdoor weather sensor

Source Code

The Arduino sketch for the outdoor weather sensor may be enhanced. For brevity I concentrate in this example on the additional functionality required to upload the weather data, not on their measurement.

#include <ESP8266WiFi.h> //
#include <WiFiClient.h> //

boolean debug=true;
// WiFi connection data
const char* ssid = "SSID";
const char* password = "PASSWORD";

const char* server = "";
const int serverPort = 80;

const unsigned long BAUD_RATE = 115200; // serial connection speed
const unsigned long HTTP_TIMEOUT = 10000; // max respone time from server

void initSerial();
void connectWiFi();
bool connect(const char* hostName, const int port);
bool sendPost(const char* hostName, float temperature, float humidity, float pressure);
void displayResponse();
void disconnect();
WiFiClient client;

unsigned long previousMillis = 0;
#define INTERVAL_MS 60000

#define CredentialsBase64 "sOmECRYPticStRiNggg" // enter here the BASE64 encoded credentials in the form &amp;amp;amp;lt;username&amp;amp;amp;gt;:&amp;amp;amp;lt;password&amp;amp;amp;gt;
const String stationName = "MyOwnWeatherStation"; // enter the station name (it will be displayed on
// use coordinates from google maps
const String lat = "xx.xxxxx"; // latitude
const String lng = "yy.yyyyy"; // longitude
const String alt = "5"; // altitude of the location in meters without decimals

void setup() {

void loop() {
unsigned long currentMillis = millis();
// run every minute
if (currentMillis - previousMillis >= INTERVAL_MS) {
previousMillis = currentMillis;
if( debug ) Serial.println("loop: measure weather data");
float temperature=14.6;
float humidity=89.1;
float pressure=1004.6;
// TODO use measured data from sensors!

if( connect(server, serverPort) ) {
if( sendPost(server, temperature, humidity, pressure) ) {

// send the HTTP POST request to the server
bool sendPost(const char* hostName, float temperature, float humidity, float pressure) {
if( debug ) {
Serial.print("POST weather data to");
Serial.print("t = ");
Serial.print("h = ");
Serial.print("p = ");

// construct packet
String packet = "";
packet += "temp=";
packet += (int)temperature;
packet += "&humidity=";
packet += (int)humidity;
packet += "&pressure=";
packet += (int)pressure;
packet += "&lat=";
packet += lat;
packet += "&long=";
packet += lng;
packet += "&alt=";
packet += alt;
packet += "&name=";
packet += stationName;

// construct POST request
String cmd = "POST /data/post HTTP/1.1\n";
cmd += "Host: ";
cmd += hostName;
cmd += "\n";
cmd += "Content-Type: application/x-www-form-urlencoded\n";
cmd += "Authorization: Basic ";
cmd += CredentialsBase64;
cmd += "\n";
cmd += "Content-Length: ";
cmd += packet.length();
cmd += "\n";
cmd += "Connection: close\n\n";
cmd += packet;
cmd += "\r\n\r\n";

if( debug ) {
Serial.print("packet: ");
Serial.print("cmd: ");
return true;

void displayResponse() {
char reply[400];
size_t length = client.readBytes(reply, 400);
reply[length] = 0;
String replyString = String(reply);

if( debug ) {
Serial.print("HTTP response ");

// initialize serial port
void initSerial() {
while (!Serial) {
; // wait for serial port to initialize
if( debug ) Serial.println("Serial ready");

// attempt to connect to WiFi
void connectWiFi() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
if( debug ) Serial.print(".");
if( debug ) {
Serial.println("WiFi connected");
Serial.print("IP address: ");

// open connection to the HTTP server
bool connect(const char* hostName, const int port) {
if( debug ) {
Serial.print("Connect to ");
bool ok = client.connect(hostName, port);
if( debug ) Serial.println(ok ? "Connected" : "Connection Failed!");
return ok;

// close the connection with the HTTP server
void disconnect() {
if( debug ) Serial.println("Disconnect from HTTP server");


The HTTP POST to upload weather data boils down to

POST /data/post HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Authorization: Basic sOmECRYPticStRiNggg
Content-Length: 80
Connection: close


The content length is the length of the string containing the measured weather data, the coordinates etc. . More weather parameters may be added – everything that is measurable can be interesting for the upload.

How to find the own Weather Station

Finding the data from the own weather station after the upload was a bit tricky. It looks like is working on improvements for uploading weather data as I conclude from this support answer. At least the documentation for upploading data needs improvements.

The station ID is returned in the HTTP response to the post. This is easy to miss. If the upload of weather data was successful the response should look similar to this:

HTTP response header HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Sat, 20 Aug 2016 11:37:00 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
X-Powered-By: Fat-Free Framework (
Pragma: no-cache
Cache-Control: no-cache, must-revalidate


The ID can be used to observe the station using the URL .

To retrieve the weather data from this station in JSON format an HTTP GET request can be performed using this URL in a browser:<YOURAPPID&gt; .

With some delay the uploaded data becomes visible in JSON format:


Inspirational Links


Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

Du kommentierst mit Deinem Abmelden /  Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )


Verbinde mit %s