IR sensors read handler should be Interrupt supported, so anytime an activity is detected by sensors it generates a hardware interrupt possibly of Low to High type and a corresponding IRQ handler takes care of counter increment. This is necessary to handle exceptions of missing counts when ESP is busy doing WiFI or MQTT transactions.