 #include <ESP8266WiFi.h>
 #include <EEPROM.h>
-#include <Ticker.h>
 #include <PubSubClient.h>
+// #include <Ticker.h>
 
 #include "Adafruit_VCNL4010.h"
 
-Ticker tickerHeartbeat;
-Ticker tickerUpdate;
+// Ticker tickerHeartbeat;
+// Ticker tickerUpdate;
 
 Adafruit_VCNL4010 proxim_sensor;
 
 #define NB_PROXIM_SAMPLES 20
-#define NB_ANOMALY_COUNTS 8
+#define NB_ANOMALY_COUNTS 15
 
 uint16_t proxim_nominal = 2000;
 uint16_t proxim_anomaly = 100;

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

  setup_wifi();
  mqttClient.setServer(MQTT_SERVER, MQTT_PORT);

  // Prepare client
  connectClient();
  
  // Schedulers
  // 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;
