   turnOff(0);
 
   // get the wifi up and running
-  WiFi.begin(ssid, pwd);
+  WiFi.begin(SSID, PWD);
 
   Serial.print("Connecting to network: ");
-  Serial.println(ssid);
-
+  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);

}

// ------------------------------------------------------------------
// is called once after powering up, sets up the wireless network 
// and reports status on serial console (for now)
void setup() {

  // start a serial console for debugging purposes

  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());  

  // 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);

  // todo: check if button was pressed
  // if so, send ballot to server
  // otherwise just ask for current status
  // 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 10 seconds
  ESP.deepSleep(1 * 10 * 1000000, WAKE_RF_DEFAULT);
  delay(1000);
}

