   {
     static unsigned long tock = 0;
     if (millis() - tock > REPORTING_PERIOD) {
-      cnt_minutes += ((millis() - tock) + 500) / 1000 / 60;
+      static unsigned long last_min = 0;
+      unsigned long delta = millis() - last_min;
+      unsigned int mins = delta / 60 / 1000;
+      if (mins > 0) {
+        cnt_minutes += mins;
+        last_min += mins * 60 * 1000;
+      }
       reportStats();
       tock = millis();
     }

#else
#define REPORTING_PERIOD        (10*1000)   //  10 seconds -- -- how often to report our states; in milli seconds.
#define PREFIX "test"
#endif


typedef enum doorstates { CLOSED, CHECKINGCARD, OPEN } doorstate_t;
const char doorstates_names[OPEN+1][15] = { "closed", "checking-card", "open" };

doorstate_t doorstate;
unsigned long long last_doorstatechange = 0;

void reportStats() {
  char buff[255];
  snprintf(buff, sizeof(buff),
           "[%s] alive-uptime %02ld:%02ld "
           "mqtt: %s (state %d) "
           "swipes %ld, opens %ld, closes %ld, fails %ld, mis-swipes %ld, mqtt reconnects %ld, mqtt fails %ld, "
           "door %s, state %s(%d)",
           pname, cnt_minutes / 60, (cnt_minutes % 60),
           client.connected() ? "connected" : "not-connected", client.state(),
           cnt_cards,
           cnt_opens, cnt_closes, cnt_fails, cnt_misreads, cnt_reconnects, cnt_mqttfails,
           isOpen() ? "open" : "closed",
           doorstates_names[doorstate], doorstate
          );
  client.publish(log_topic, buff);
  Serial.println(buff);
