     Serial.print(".");
   }
 
-  Serial.println("");
+  Serial.println();
   Serial.println("WiFi connected");  
   Serial.println("IP address: ");
   Serial.println(WiFi.localIP());
 }
 
-int value = 0;
+void loop() {
+  if (nextTime > millis()) {
+        return;
+  }
 
-void loop() {
-  delay(5000);
-  ++value;
-
-  Serial.print("connecting to ");
-  Serial.println(host);
+  Serial.println("connecting to " + String(host));
   
   // Use WiFiClient class to create TCP connections
   WiFiClient client;
-  const int httpPort = 8080;
+  
   if (!client.connect(host, httpPort)) {
     Serial.println("connection failed");
     return;
   }
 
-  String url = "/devices";
-  
-  Serial.print("Requesting URL: ");
-  Serial.println(url);
+  String path = "/devices";
+  Serial.println("Requesting URL: " + path);
 
-  //char* body = printf(requestBody, clientId, "90", "44");
-  
-  // This will send the request to the server
-  client.print("POST " + url + " HTTP/1.1\r\n" +
+  // TODO Read temperature and humidity from sensors
+  float temperature = 55.3;
+  float humidity = 33.4;
+
+  // prepare request body
+  String body = "{\"name\":\"" + String(clientId) + "\"," +
+                "\"weatherData\": { \"temperature\":\"" + temperature + "\"," +
+                "\"humidity\":\"" + humidity + "\" }}";
+   
+  // send request to the server
+  client.print("POST " + path + " HTTP/1.1\r\n" +
                "Host: " + host + "\r\n" + 
                "Connection: close\r\n" + 
                "Content-Type: application/json\r\n" +
-               "Content-Length: 73\r\n" +
+               "Content-Length: " + body.length() + "\r\n" +
                "\r\n" +
-               "{\"name\":\"node2\", \"weatherData\": { \"temperature\":\"33\", \"humidity\":\"55\" } }");
-  unsigned long timeout = millis();
+               body);
+
+  // process connection timeout
+  unsigned long startTime = millis();
   while (client.available() == 0) {
-    if (millis() - timeout > 8000) {
-      Serial.println(">>> Client Timeout !");
+    if (millis() - startTime > timeout) {
+      Serial.println("Connection Timeout");
       client.stop();
       return;
     }

#include <ESP8266WiFi.h>

const char* ssid     = "FRITZ!Box Fon WLAN 7360";
const char* password = "62884846722859294257";

const char* host = "192.168.178.34";
char* clientId = "photo1";
char* requestBody = "{ \"name\":\"%s\", \"weatherData\": { \"temperature\":\"%f\", \"humidity\":\"%f\" } }";

int delayInMillis = 10000;

void setup() {
  Serial.begin(115200);
  delay(10);

  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

    String line = client.readStringUntil('\r');
    Serial.print(line);
  }

  Serial.println();
  Serial.println("Close connection");

  // do delay
  nextTime = millis() + delayInMillis;
}
