 void update() {
   static uint16_t counter = 0;
   static uint16_t index = 0;
+  static uint16_t printer_count = 0;
+
   uint16_t proxim_value = proxim_sensor.readProximity();
+
   if ( proxim_value > proxim_nominal + proxim_anomaly ) {
+    printer_count = 2 * 1000 / 54;    // print 2 seconds of reading
     // integrate the anomaly
     if (event_count < NB_ANOMALY_COUNTS) {
       event_count++;

Adafruit_VCNL4010 proxim_sensor;

#define NB_PROXIM_SAMPLES 20
#define NB_ANOMALY_COUNTS 15

#define MAX_CLIENT_RETRIES 10

uint16_t proxim_nominal = 1960;
uint16_t proxim_anomaly = 160;
uint16_t event_count = 0;

uint16_t proxim_samples[NB_PROXIM_SAMPLES];


void loop() {
  static bool raised = false;
  static uint16_t counter = 0;
  static uint16_t hearbeat_period_ticks = 30000 / 54; // average loop period = 54ms
  static unsigned long last_millis = millis();

  unsigned long now_millis = millis();
  if ( now_millis - last_millis > 50 ) {
    update();
    counter++;
    if ( counter > hearbeat_period_ticks ) {
      // publish heartbeat
      heartbeat();
      counter = 0;
    }
