Nouveau : le pare-feu IA surveille toute la plateforme et explique chaque incident en termes simples. Découvrez comment ça marche

Reply To: Reject button at a rework station misses quick presses. Also, can Forge count these for us?

Owen has it. The press is shorter than your loop, so polling misses it. Use an interrupt so the count happens the moment the pin falls, and do the debounce by time inside it. I’ve had pulse counters on gas meters for years done like this:

volatile uint32_t rejects = 0;          // since boot
volatile uint32_t lastEdgeUs = 0;

void IRAM_ATTR onPress() {
  uint32_t now = micros();
  if (now - lastEdgeUs > 30000) {       // ignore bounce within 30 ms
    rejects++;
  }
  lastEdgeUs = now;
}

void setup() {
  pinMode(D5, INPUT_PULLUP);           // button to GND
  attachInterrupt(digitalPinToInterrupt(D5), onPress, FALLING);
}

Remove the delay(50) from loop(). In the publish, copy the counter with interrupts briefly off.

Hardware: on a factory floor the button cable is often metres long next to motor cables. Add a 1 kΩ series resistor and 100 nF at the ESP pin, or better, run the button at 24 V into an optocoupler. Otherwise you’ll start counting phantom rejects.

Send a cumulative counter, not « rejects this minute »: {"rejects.total": 1532}. If a message is lost, the next one still has the right total, and a chart with the increase aggregate gives you rejects per hour.

Timestamps in UTC or it didn't happen.
Solution acceptée♥ 9