         digitalWrite(D7, HIGH);
       }
       else {
+        // run a loop of the MQTT code
+        client.loop();
         // all right, turn off WiFi to spare power
         WiFi.off();
       }

  pinMode(powerPin, OUTPUT);
  pinMode(D7, OUTPUT);       // the integrated LED signals readout errors
  digitalWrite(powerPin, HIGH);

  // connect to the MQTT server
  client.connect("glp_photon");

  // publish/subscribe
  if(client.isConnected()) {
    client.publish("message","hello world");
    client.subscribe("readout");
  }
}


void callback(char* topic, byte* payload, unsigned int length) {
  //char p[length + 1];
  //memcpy(p, payload, length);
  //p[length] = NULL;
  // signal we got the callback  
  digitalWrite(D7, HIGH);
  delay(500);
  digitalWrite(D7, LOW);
  delay(100);
  digitalWrite(D7, HIGH);
  delay(500);
  digitalWrite(D7, LOW);
  // and force a readout as if the button were pressed
  readout(true);
}


int getAndStoreValues() {
  lux = analogRead(photoPin) / 4096.0 * 100;    // scale to [0..100]
  // reset every day the max and min values
  if(Time.day() != day) {
    day = Time.day();

      "}";
  // make sure we're online
  waitUntil(WiFi.ready);
  // connect to the MQTT broker
  client.connect("glpphoton");
  // publish data to the MQTT broker
  if(!client.publish("glp/thlsensor/data", payload)) {
    return -1;
  }
  // clear the LED in case of previous errors
  digitalWrite(D7, LOW);
  return 0;
}


void loop() {
  // handle button and periodic readouts
  int pushButtonState = HIGH;
  if(pushButtonState == LOW) {
