   Serial.print("IP address: ");
   Serial.println(WiFi.localIP());  
 
-  // todo: check if registered already (check EEPROM), register with HARDAC otherwise.
+  // print the received signal strength:
+  long rssi = WiFi.RSSI();
+  Serial.print("Signal strength (RSSI):");
+  Serial.print(rssi);
+  Serial.println(" dBm");
+
+  // calculate device id
+  // Chip ID: 000000
+  // Flash ID: 0000000
+  // Serial.print("Chip ID: ");
+  // Serial.println(ESP.getChipId());
+  // Serial.print("Flash ID: ");
+  // Serial.println(ESP.getFlashChipId());
+  sDeviceId = String(ESP.getChipId()) + "_" + String(ESP.getFlashChipId());
+  Serial.println("DeviceId: " + sDeviceId);
+
+  delay(500);
+  
+  // check if registered already (check EEPROM), register with HARDAC otherwise.
+  if(sDeviceId.length() <= 1)
+  {
+    Serial.println("sDeviceId is too small. " + sDeviceId);
+  }
+  else
+  {
+    // we currently only need one byte, but 4 is the minimum to register for
+    EEPROM.begin(4);
+  
+    byte byRegKey = EEPROM.read(EEPROM_REGKEY_ADDRESS);
+    
+    Serial.print("EEPROM Value at EEPROM_REGKEY_ADDRESS: 0x");
+    Serial.println(byRegKey, HEX);
+    
+    if(byRegKey != REGISTERED)
+    {
+      Serial.println("PJ is not registered yet.");
+      registerPJ();
+    }
+  }
+}
+
+// ------------------------------------------------------------------
+// todo: this generic method will become a handle response to status message function
+// parse json response, act accordingly
+// checking on statuscode makes no sense like that
+void handleReply(reply r)
+{
+  Serial.println("");
+  Serial.println("Handling Reply");
+      
+  switch (r.iStatusCd) 
+  {
+    case 200:
+      Serial.println("Request successfull.");
+      break;
+    case 201:
+      Serial.println("Registration successfull.");
+      break;
+    case 202:
+      Serial.println("Ballot sent successfully.");
+      break;
+    case 400:
+      Serial.println("Not all parameters were given.");
+      break;
+    case 403:
+      Serial.println("Function called without being registered.");
+      break;
+    case 420:
+      Serial.println("Re-registration attempt, HARDAC tells us to calm down.");
+      break;
+    default:
+      Serial.println("That status code is not known (yet): '" + String(r.iStatusCd) + "' with line: " + r.sReply);
+    break;
+  }
+
+  // { "colour_1": "R", "colour_2": "B" }
+  if(r.sReply.length() > 24)
+  {
+    StaticJsonBuffer<200> jsonBuffer;
+    JsonObject& root = jsonBuffer.parseObject(r.sReply);
+    
+    const char* colour1 = root["colour_1"];
+    const char* colour2 = root["colour_2"];
+  
+    Serial.print("colour1: ");
+    Serial.println(colour1);
+    Serial.print("colour2: ");
+    Serial.println(colour2);
+  }
+  else
+  {
+    Serial.println("JSON seems not to be valid.");
+  }
 }
 
 // ------------------------------------------------------------------
 // will be called right after setup and then in a loop after every deep sleep cycle
+// since we (currently) deep sleep after every cycle...
 void loop() {
 
   // todo: remove me when implementing deep sleep
-  //delay(5000);
+  // delay(5000);
 
   // todo: check if button was pressed
   // if so, send ballot to server
   // otherwise just ask for current status
-
-  Serial.print("Connecting to ");
-  Serial.println(server);
-  
-  // Use WiFiClient class to create TCP connections
-  WiFiClient client;
-  if (!client.connect(server, port)) {
-    Serial.println("Connection failed, trying later...");
-    return;
-  }
-  
-  // We now create a URI for the request
-  String url = "/device_id/s/";
-  Serial.print("Requesting URL: ");
-  Serial.println(url);
-  
-  // This will send the request to the server
-  client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");
-               
-  // just a short delay to give other components the chance to do something else
-  delay(10);
-  
-  // Read all the lines of the reply from server and print them to Serial
-  while(client.available())
-  {
-    String line = client.readStringUntil('\r');
-    Serial.print(line);
-  }
+  // we also could just skip the status every other round
+
+  // ask HARDAC for status and actions
+  String sUrl = "/" + sDeviceId + "/s/";
+  reply r = callUrl(sUrl);
+
+  handleReply(r);
   
   Serial.println();
   Serial.println("Closing connection, going to deep sleep");
   delay(1000);
 
-  // go to deepsleep for one minutes
-  system_deep_sleep_set_option(0);
-  //system_deep_sleep(1 * 60 * 1000000);
-  system_deep_sleep(1 * 10 * 1000000);
+  // go to deepsleep for 10 seconds
+  ESP.deepSleep(1 * 10 * 1000000, WAKE_RF_DEFAULT);
   delay(1000);
-
-}
-
+}
+

 */

#include <ESP8266WiFi.h>

// ESP8266 SDK headers are in C, they need to be included externally or else 
// they will throw an error compiling/linking.
//
// all SDK .c files required can be added between the { }
extern "C" {
#include "user_interface.h"
}

// change these to your setup
const char* ssid    = "hardac";
const char* pwd     = "hardac";

// where your hardac server is running
const char* server  = "10.10.10.10";
const int port      = 8765;

// ------------------------------------------------------------------
// used to turn off GPIO Pi

  turnOff(0);

  // get the wifi up and running
  WiFi.begin(SSID, PWD);

  Serial.print("Connecting to network: ");
  Serial.println(SSID);

  // todo: this loops until things get connected to the wireless network
  // should we cancel after a few attempts and sleep instead to not drain
  // the battery too much when out of reach?
  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(500);
