     --hasMailPrevious;
   }
   Serial.print(value);
+  Serial.print(' ');
+  Serial.print(medianValue());
   Serial.print("|");
   Serial.print(hasMailPrevious);
   Serial.println();

unsigned long restartPressed = 0;
const short RESTART_DURATION = 5000;
short threshold = 0;
byte hasMailPrevious = 0;
WiFiClient client;

void sensorSetup() {
  pinMode(13, INPUT);

  WiFi.mode(WIFI_STA);
  Serial.println("Calibrating...");
  short value;
  for(int i = 0; i < 20; i++)
  {
    value = system_adc_read();
    if (value > threshold)
    {
      threshold = value;
    }
    delay(50);
  }
  threshold += 5;
  Serial.print("Threshold is ");
  Serial.print(threshold);
  Serial.println(".");


void sendEmail()
{
  WiFi.mode(WIFI_STA);
  Serial.println("Waiting for WiFi...");
  while (WiFi.status() != WL_CONNECTED) {
    delay(250);
  };
  Serial.println("\nWiFi successfully connected.");

  long start = millis();
  if (client.connect("going-postal.me", 80)) {
    client.print("POST /api/test/email HTTP/1.1\r\n");
