Browse Source

Skip NTAG write ACK check — PN5180 can't capture 4-bit response

  IRQ logging revealed the tag IS responding (RX_SOF_DET set) but the
  PN5180 cannot capture the 4-bit ACK as a complete frame — RX_IRQ
  never fires and RX_STATUS stays zero. Skip per-page ACK checking
  and rely on the read-back verification in ntag_write_pages().
maziggy 2 months ago
parent
commit
918dec4c19
2 changed files with 8 additions and 24 deletions
  1. 1 1
      CHANGELOG.md
  2. 7 23
      spoolbuddy/daemon/pn5180.py

+ 1 - 1
CHANGELOG.md

@@ -17,7 +17,7 @@ All notable changes to Bambuddy will be documented in this file.
 - **SpoolBuddy Install Script Now Upgrades System Packages** — The install script now runs `apt-get upgrade -y` after installing required packages and the WiFi safeguard. This ensures the Pi is fully up to date before SpoolBuddy is deployed, and the WiFi safeguard protects connectivity during the upgrade.
 - **SpoolBuddy Install Script Now Upgrades System Packages** — The install script now runs `apt-get upgrade -y` after installing required packages and the WiFi safeguard. This ensures the Pi is fully up to date before SpoolBuddy is deployed, and the WiFi safeguard protects connectivity during the upgrade.
 
 
 ### Fixed
 ### Fixed
-- **SpoolBuddy NFC Write Fails on NTAG Tags** — Multiple issues prevented writing to NTAG 213/215/216 tags. (1) Some chips report SAK `0x04` (MIFARE Ultralight family) instead of `0x00` during anticollision, and the write gate only accepted `0x00`, causing "Incompatible tag type" errors — both SAK values are now accepted. (2) The PN5180 had TX CRC disabled for both NTAG WRITE and READ commands, but the NTAG spec requires CRC on all command frames — enabled TX CRC for both. (3) The WRITE ACK check only looked at complete bytes in `RX_STATUS`, but the NTAG ACK is 4 bits — it reported 0 bytes with 4 extra bits, so every successful write was treated as a failure. Fixed by checking both byte and bit fields.
+- **SpoolBuddy NFC Write Fails on NTAG Tags** — Multiple issues prevented writing to NTAG 213/215/216 tags. (1) Some chips report SAK `0x04` (MIFARE Ultralight family) instead of `0x00` during anticollision, and the write gate only accepted `0x00`, causing "Incompatible tag type" errors — both SAK values are now accepted. (2) The PN5180 had TX CRC disabled for both NTAG WRITE and READ commands, but the NTAG spec requires CRC on all command frames — enabled TX CRC for both. (3) The PN5180 state machine wasn't being reset between SELECT and WRITE — added proper IDLE→TRANSCEIVE transition. (4) The NTAG WRITE ACK is only 4 bits, which the PN5180 cannot capture as a complete frame (SOF detected but RX_IRQ never fires). Removed per-page ACK checking and rely on the existing full read-back verification instead.
 - **Database Connection Pool Exhaustion on Large Printer Farms** — Users with 100+ printers connected simultaneously experienced `QueuePool limit of size 10 overflow 20 reached, connection timed out` errors. Increased the SQLAlchemy connection pool from 30 total (10 base + 20 overflow) to 220 (20 base + 200 overflow), and raised the SQLite busy_timeout from 5 to 15 seconds to reduce write contention under heavy concurrent MQTT updates.
 - **Database Connection Pool Exhaustion on Large Printer Farms** — Users with 100+ printers connected simultaneously experienced `QueuePool limit of size 10 overflow 20 reached, connection timed out` errors. Increased the SQLAlchemy connection pool from 30 total (10 base + 20 overflow) to 220 (20 base + 200 overflow), and raised the SQLite busy_timeout from 5 to 15 seconds to reduce write contention under heavy concurrent MQTT updates.
 - **SpoolBuddy Update Check Always Shows "Up to Date"** — The SpoolBuddy daemon update check compared the device's firmware version against GitHub releases instead of the running Bambuddy backend version. This meant the check could incorrectly report "up to date" even when the daemon was behind. Fixed by comparing directly against `APP_VERSION` from the backend config.
 - **SpoolBuddy Update Check Always Shows "Up to Date"** — The SpoolBuddy daemon update check compared the device's firmware version against GitHub releases instead of the running Bambuddy backend version. This meant the check could incorrectly report "up to date" even when the daemon was behind. Fixed by comparing directly against `APP_VERSION` from the backend config.
 - **SpoolBuddy Updates Now Use SSH** — Replaced the fragile self-update mechanism (daemon pulls its own code via git, permission errors on `.git/`, hardcoded `main` branch) with SSH-based updates driven by the Bambuddy backend. Bambuddy now SSHes into the SpoolBuddy Pi and runs git fetch/checkout, pip install, systemctl restart, and kiosk browser restart remotely. Updates automatically use the same branch as Bambuddy. SSH key pairing is fully automatic — Bambuddy generates an ED25519 keypair and includes the public key in the device registration response; the daemon deploys it to `authorized_keys` on first connect. The install script creates the `spoolbuddy` user with a bash shell and sudoers entries for daemon and kiosk restart. A "Force Update" button allows re-deploying even when versions match. The SSH public key is also shown in SpoolBuddy Settings → Updates → SSH Setup for manual pairing if needed.
 - **SpoolBuddy Updates Now Use SSH** — Replaced the fragile self-update mechanism (daemon pulls its own code via git, permission errors on `.git/`, hardcoded `main` branch) with SSH-based updates driven by the Bambuddy backend. Bambuddy now SSHes into the SpoolBuddy Pi and runs git fetch/checkout, pip install, systemctl restart, and kiosk browser restart remotely. Updates automatically use the same branch as Bambuddy. SSH key pairing is fully automatic — Bambuddy generates an ED25519 keypair and includes the public key in the device registration response; the daemon deploys it to `authorized_keys` on first connect. The install script creates the `spoolbuddy` user with a bash shell and sudoers entries for daemon and kiosk restart. A "Force Update" button allows re-deploying even when versions match. The SSH public key is also shown in SpoolBuddy Settings → Updates → SSH Setup for manual pairing if needed.

+ 7 - 23
spoolbuddy/daemon/pn5180.py

@@ -474,7 +474,9 @@ class PN5180:
         """Write 4 bytes to a single NTAG page.
         """Write 4 bytes to a single NTAG page.
 
 
         NTAG WRITE command: 0xA2 + page_number + 4 bytes data.
         NTAG WRITE command: 0xA2 + page_number + 4 bytes data.
-        TX CRC on (tag requires it), RX CRC off (ACK is 4-bit). Returns True on ACK (0x0A).
+        TX CRC on (tag requires it). Always returns True — the 4-bit ACK
+        cannot be captured by the PN5180, so verification is deferred to
+        ntag_write_pages() which reads back all written data.
         """
         """
         if len(data) != 4:
         if len(data) != 4:
             return False
             return False
@@ -496,28 +498,10 @@ class PN5180:
         self.send_data([0xA2, page] + list(data))
         self.send_data([0xA2, page] + list(data))
         time.sleep(0.010)
         time.sleep(0.010)
 
 
-        # Check for ACK: NTAG ACK is 4-bit 0x0A.
-        # RX_STATUS bits 8:0 = complete bytes, bits 17:9 = extra bits.
-        # A 4-bit ACK reports 0 bytes + 4 bits, so check both fields.
-        irq_status = self.read_reg(0x02)
-        rx_status = self.read_reg(0x13)
-        rx_bytes = rx_status & 0x1FF
-        rx_bits = (rx_status >> 9) & 0x1FF
-        logger.debug(
-            "NTAG write page %d: irq=0x%08X, rx_status=0x%08X, rx_bytes=%d, rx_bits=%d",
-            page,
-            irq_status,
-            rx_status,
-            rx_bytes,
-            rx_bits,
-        )
-        if rx_bytes == 0 and rx_bits == 0:
-            logger.warning("NTAG write page %d: no ACK received (irq=0x%08X)", page, irq_status)
-            return False
-
-        ack = self.read_data(1)
-        logger.debug("NTAG write page %d: ACK byte=0x%02X", page, ack[0])
-        return ack[0] == 0x0A
+        # The NTAG ACK is only 4 bits (0x0A). The PN5180 detects SOF but
+        # cannot capture sub-byte frames — RX_IRQ never fires. Skip ACK
+        # checking; ntag_write_pages() verifies by reading back all data.
+        return True
 
 
     def ntag_write_pages(self, start_page: int, data: bytes) -> bool:
     def ntag_write_pages(self, start_page: int, data: bytes) -> bool:
         """Write data to consecutive NTAG pages starting at start_page.
         """Write data to consecutive NTAG pages starting at start_page.