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

    return -1;
  }
  // cast floats to strings
  String sl(lux, 0);
  String slmin(lmin, 0);
  String slmax(lmax, 0);
  // generate the payload
  String payload = "{lux: " + sl +
      // also publish daily max and min values when button pressed

  pinMode(powerPin, OUTPUT);
  pinMode(D7, OUTPUT);       // the integrated LED signals readout errors
  digitalWrite(powerPin, HIGH);
  // first connection to the MQTT broker
  client.connect("glpphoton");
}


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