   setup_wifi();
   mqttClient.setServer(MQTT_SERVER, MQTT_PORT);
 
+  // Prepare client
+  connectClient();
+  
   // Schedulers
-  tickerHeartbeat.attach(10, heartbeat);
-  tickerUpdate.attach_ms(100, update);
+  // tickerHeartbeat.attach(10, heartbeat);
+  // tickerUpdate.attach_ms(100, update);
 
 }
 
 void loop() {
   static bool raised = false;
+  static uint8_t counter = 0;
+  static unsigned long last_millis = millis();
+
+  // publish heartbeat
+  unsigned long now_millis = millis();
+  if ( now_millis - last_millis > 50 ) {
+    update();
+    counter++;
+    if ( counter == 200 ) {
+      heartbeat();
+      counter = 0;
+    }
+    last_millis = now_millis;
+  }
+
+  // take care of event if any
   if ( !raised && event_count >= NB_ANOMALY_COUNTS ) {
     door_opened();
     raised = true;

PubSubClient mqttClient(espWifiClient);

void heartbeat() {
  Serial.print("average promimity = ");
  Serial.println(proxim_nominal);
}

  for (uint16_t i = 0; i < NB_PROXIM_SAMPLES; i++) {
    proxim_samples[i] = proxim_nominal;
  }
  Serial.begin(115200);
  if ( !proxim_sensor.begin() ) {
    Serial.println("Proximity Sensor not found: stop!");
    while (1);
