<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ze zhang</title>
    <description>The latest articles on DEV Community by ze zhang (@ze_zhang_d4b657537c324dd8).</description>
    <link>https://dev.to/ze_zhang_d4b657537c324dd8</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4279959%2F89818663-2a9b-403c-acb2-e923a43bdb55.png</url>
      <title>DEV Community: ze zhang</title>
      <link>https://dev.to/ze_zhang_d4b657537c324dd8</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ze_zhang_d4b657537c324dd8"/>
    <language>en</language>
    <item>
      <title>Designing Fail-Closed IoT Systems: 30s HMAC QR Atomic Vending &amp; Hardware-Triggered Jetson YOLOv8</title>
      <dc:creator>ze zhang</dc:creator>
      <pubDate>Thu, 03 Dec 2026 08:09:10 +0000</pubDate>
      <link>https://dev.to/ze_zhang_d4b657537c324dd8/designing-fail-closed-iot-systems-30s-hmac-qr-atomic-vending-hardware-triggered-jetson-yolov8-adc</link>
      <guid>https://dev.to/ze_zhang_d4b657537c324dd8/designing-fail-closed-iot-systems-30s-hmac-qr-atomic-vending-hardware-triggered-jetson-yolov8-adc</guid>
      <description>&lt;p&gt;Most IoT demos look clean until money or high-speed physical sensors enter the loop:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On an &lt;strong&gt;unattended smart vending kiosk&lt;/strong&gt;, a customer taps "Brew" twice on flaky basement 4G—or shares a screenshot of their QR code in a group chat—and suddenly you are giving away free inventory or double-charging cards.&lt;/li&gt;
&lt;li&gt;On a &lt;strong&gt;Jetson Orin NX industrial vision rig&lt;/strong&gt;, running YOLOv8 looks effortless on static JPEGs—until an NVMe SSD flush or CPU jitter stalls the capture thread and shifts track-defect mileage stamps several meters off target.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both problems share the same root fix: &lt;strong&gt;stop relying on optimistic frontend/wall-clock assumptions, and move correctness down to atomic state machines and hardware triggers.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Pattern 1: 30s PII-Free HMAC QR + Fail-Closed Atomic Dispense (&lt;code&gt;RESERVED → COMMITTED / RELEASED&lt;/code&gt;)
&lt;/h2&gt;

&lt;p&gt;When we engineered a London commercial smart drink kiosk SaaS (zero-install mobile H5 checkout + Stripe subscriptions + UK GDPR compliance), three non-negotiable constraints shaped the commerce layer:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;No forced native app download&lt;/strong&gt; (walk-up customers bounce on 50MB store installs).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero member PII inside QR payloads&lt;/strong&gt; (encoding phone numbers or emails inside QR tokens violates UK/EU GDPR if photographed).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero double-dispenses and zero free pours&lt;/strong&gt; under flaky cellular retries or screenshot replay.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How the State Machine Works
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;30s One-Time HMAC QR Tokens&lt;/strong&gt;: QR payloads hold only a short-lived cryptographic HMAC digest + nonce, invalidated the instant a scan hits the server. Group-chat screenshots are dead within 30 seconds or on first scan.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stripe &lt;code&gt;event.id&lt;/code&gt; Webhook Idempotency + Row-Level Dispense Lock&lt;/strong&gt;: Every Stripe webhook deduplicates strictly on persistent &lt;code&gt;event.id&lt;/code&gt; uniqueness keys. When triggering physical dispensing, the server acquires a transactional row lock keyed by &lt;code&gt;Idempotency-Key&lt;/code&gt; in state &lt;strong&gt;&lt;code&gt;RESERVED&lt;/code&gt;&lt;/strong&gt;—never touching quota until the kiosk confirms &lt;code&gt;COMMITTED&lt;/code&gt; (auto-transitioning to &lt;strong&gt;&lt;code&gt;RELEASED&lt;/code&gt;&lt;/strong&gt; if hardware times out after 25s).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Strict Fail-Closed Offline Policy&lt;/strong&gt;: If a kiosk's heartbeat drops, checkout disables cleanly rather than allowing offline cached tokens to pour drinks before billing clears.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IANA Timezone DST Discipline&lt;/strong&gt;: Daily membership quotas in the UK shift twice a year between GMT and BST—compute midnight resets strictly against &lt;code&gt;Europe/London&lt;/code&gt; rather than hardcoded UTC offsets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Dive into full failure-mode matrices in our &lt;a href="https://space-bit.com/guides/smart-vending-30s-hmac-qr-stripe-atomic-dispense/?utm_source=devto_hashnode&amp;amp;utm_medium=article" rel="noopener noreferrer"&gt;30s HMAC QR &amp;amp; Fail-Closed Vending Guide&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Pattern 2: Hardware &lt;code&gt;FrameBurst&lt;/code&gt; Sync &amp;amp; 3-Stage Ring Buffers on Jetson Orin NX
&lt;/h2&gt;

&lt;p&gt;For an underground industrial rail vision + track-geometry inspection rig running a 10fps line-scan camera, RS485 wheel encoder, 400Hz IMU, and local YOLOv8 TensorRT inference, software wall-clock polling broke immediately under vibration and zero-signal tunnels.&lt;/p&gt;

&lt;h3&gt;
  
  
  Three Fixes That Stopped Frame Sticking &amp;amp; Mileage Drift
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Encoder-Driven Hardware &lt;code&gt;FrameBurst&lt;/code&gt; Triggers&lt;/strong&gt;: The RS485 wheel encoder directly drives camera exposure bursts at fixed millimeter travel intervals, eliminating speed distortion and scheduler drift.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hard 3-Stage Ring-Buffer Isolation&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Process A (Capture)&lt;/strong&gt;: Hardware timestamping + zero-copy raw ring storage to local NVMe.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Process B (TensorRT FP16)&lt;/strong&gt;: Pinned CUDA stream running YOLOv8 fastener/abrasion inference + 400Hz IMU GAI6 geometry alignment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Process C (Async Uplink)&lt;/strong&gt;: Uploads only flagged defect crops + exact mileage (&lt;code&gt;K12+485.20m&lt;/code&gt;) when network coverage returns.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RS485 Register Stall Diagnostics + Unattended Recovery&lt;/strong&gt;: Actively polling encoder registers flags cable/wheel slip faults early, while systemd watchdogs + Tailscale tunnels allow zero-touch remote triage after tunnel runs.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Full architecture comparison (Wall-Clock Polling vs. IEEE 1588 PTP vs. Encoder FrameBurst): &lt;a href="https://space-bit.com/guides/jetson-orin-nx-yolov8-tensorrt-linescan-encoder-sync/?utm_source=devto_hashnode&amp;amp;utm_medium=article" rel="noopener noreferrer"&gt;Jetson Orin NX YOLOv8 &amp;amp; RS485 Encoder Sync Guide&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Runnable Reference Code
&lt;/h2&gt;

&lt;p&gt;We published working Python/Go reference implementations—including 30s HMAC single-use QR replay tests (&lt;code&gt;tools/atomic_vending_guard.py&lt;/code&gt;) and concurrency locks—in our open-source kit: &lt;a href="https://github.com/bobobo2026/aiot-production-kit" rel="noopener noreferrer"&gt;github.com/bobobo2026/aiot-production-kit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;What edge synchronization or fail-closed transaction pattern saved your fleet from silent field bugs?&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>iot</category>
      <category>edgeai</category>
      <category>stripe</category>
    </item>
    <item>
      <title>OCPP 1.6J vs 2.0.1 &amp; HTTP 206 Range OTA on STM32/ESP32: What Actually Ships in UK/EU EV Chargers</title>
      <dc:creator>ze zhang</dc:creator>
      <pubDate>Thu, 03 Dec 2026 08:09:09 +0000</pubDate>
      <link>https://dev.to/ze_zhang_d4b657537c324dd8/ocpp-16j-vs-201-http-206-range-ota-on-stm32esp32-what-actually-ships-in-ukeu-ev-chargers-kf7</link>
      <guid>https://dev.to/ze_zhang_d4b657537c324dd8/ocpp-16j-vs-201-http-206-range-ota-on-stm32esp32-what-actually-ships-in-ukeu-ev-chargers-kf7</guid>
      <description>&lt;p&gt;Hardware founders building 7kW–22kW EV chargers or portable energy storage systems for the UK, EU, and ANZ markets routinely run into two costly traps right as units enter field trials:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Over-engineering an &lt;strong&gt;OCPP 2.0.1&lt;/strong&gt; stack onto an MCU that barely has RAM left for TLS, when &lt;strong&gt;hardened OCPP 1.6J&lt;/strong&gt; already satisfies regional mandates.&lt;/li&gt;
&lt;li&gt;Watching firmware updates pass every &lt;code&gt;HTTP 200&lt;/code&gt; check on an office desk—only to silently fail or brick chargers sitting in concrete basement garages.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is the production breakdown from delivering our single-binary Go CSMS + BLE + constrained OTA EV charger platform at &lt;a href="https://space-bit.com/solutions/ocpp-ev-charger/?utm_source=devto_hashnode&amp;amp;utm_medium=article" rel="noopener noreferrer"&gt;Spacebit&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. OCPP 1.6J vs OCPP 2.0.1: Don't Pay Linux BOM Tax Too Early
&lt;/h2&gt;

&lt;p&gt;OCPP 2.0.1 is not a minor patch release over 1.6J—its device model state tree and message schemas carry an entirely different embedded footprint:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Dimension&lt;/th&gt;
&lt;th&gt;Hardened OCPP 1.6J + Security Profile&lt;/th&gt;
&lt;th&gt;OCPP 2.0.1 (DC Fast / V2G)&lt;/th&gt;
&lt;th&gt;Private MQTT + Custom JSON&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;MCU RAM / Flash&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;~45KB RAM / 180KB Flash&lt;/strong&gt; (STM32F4 / ESP32-S3)&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;180KB+ RAM&lt;/strong&gt; &amp;amp; deep DeviceModel (often needs Linux SoC)&lt;/td&gt;
&lt;td&gt;~20KB RAM, zero ecosystem compatibility&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;EU/UK/ANZ CSMS Support&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Supported by &lt;strong&gt;&amp;gt;90%&lt;/strong&gt; of commercial operators&lt;/td&gt;
&lt;td&gt;Growing, sub-profile dialect quirks still common&lt;/td&gt;
&lt;td&gt;Zero third-party operator support&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;UK Smart Charging Mandate&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Satisfied via &lt;code&gt;TxDefaultProfile&lt;/code&gt; + 8 off-peak slots + &lt;strong&gt;0–600s randomized start delay&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;Built-in rich tariff/cost trees&lt;/td&gt;
&lt;td&gt;Must hand-roll every regulatory log&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;ISO 15118 Plug &amp;amp; Charge&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Proprietary vendor extensions&lt;/td&gt;
&lt;td&gt;Native standard support&lt;/td&gt;
&lt;td&gt;Unsupported&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Unless your contract explicitly mandates ISO 15118 Plug &amp;amp; Charge / V2G or targets public DC fast stations, hardened &lt;strong&gt;OCPP 1.6J&lt;/strong&gt; cuts 3–4 months off firmware schedule and BOM cost while still clearing UK Smart Charge Points regulations.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Reconciling Underground Garage BLE With Cloud OCPP Schedules
&lt;/h2&gt;

&lt;p&gt;Cellular and Wi-Fi routinely vanish in apartment basements. Drivers rely on local &lt;strong&gt;BLE&lt;/strong&gt; to force an immediate session or cap amperage—and then trouble hits the moment the charger regains 4G:&lt;/p&gt;

&lt;p&gt;If your Go/cloud CSMS blindly pushes stale off-peak profiles (&lt;code&gt;ClearChargingProfile&lt;/code&gt; / &lt;code&gt;SetChargingProfile&lt;/code&gt;) upon WebSocket reconnect, it immediately kills the active BLE session the driver just triggered.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; Share a single monotonic &lt;strong&gt;&lt;code&gt;config_ver&lt;/code&gt; counter&lt;/strong&gt; + &lt;code&gt;source&lt;/code&gt; tag (&lt;code&gt;ble&lt;/code&gt; vs &lt;code&gt;cloud&lt;/code&gt;) across local firmware and cloud state. Both endpoints increment &lt;code&gt;config_ver&lt;/code&gt; cleanly on mutation. When the charger reconnects and posts its active state snapshot, the CSMS reconciles against the highest monotonic version rather than clobbering field overrides—while replaying offline energy transactions (&lt;code&gt;Start&lt;/code&gt; / &lt;code&gt;MeterValues&lt;/code&gt; / &lt;code&gt;Stop&lt;/code&gt;) from a &amp;gt;=64-session circular Flash FIFO with composite &lt;code&gt;(charger_id, tx_id)&lt;/code&gt; idempotency.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Why STM32/ESP32 OTA Fails Despite "HTTP 200" in Cloud Tests
&lt;/h2&gt;

&lt;p&gt;This bug burned real field days before we instrumented serial logs in a garage:&lt;/p&gt;

&lt;h3&gt;
  
  
  Bug A: 500-Byte Cloud Presigned URLs Overflowing 128B Embedded Buffers
&lt;/h3&gt;

&lt;p&gt;Standard S3/OSS presigned download URLs packed with &lt;code&gt;X-Amz-Credential&lt;/code&gt;, &lt;code&gt;Expires&lt;/code&gt;, and &lt;code&gt;Signature&lt;/code&gt; easily span &lt;strong&gt;450–650 bytes&lt;/strong&gt;. Embedded C firmware writing into static &lt;code&gt;char url[128]&lt;/code&gt; or &lt;code&gt;256&lt;/code&gt; buffers silently truncates the query signature—causing S3/OSS to reject requests with &lt;code&gt;403 Forbidden&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Put a lightweight Go OTA gateway in front of object storage that verifies short HMAC tokens and exposes &lt;strong&gt;&lt;code&gt;&amp;lt;= 48-byte&lt;/code&gt; fixed endpoints&lt;/strong&gt; such as &lt;code&gt;https://ota.example.com/f/a9f3c1?s=8k2m&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bug B: Full-Image GET + 16KB Default TLS Record Buffers Starving Low-RAM MCUs
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Stream firmware strictly in &lt;strong&gt;4KB–16KB &lt;code&gt;HTTP/1.1 206 Partial Content&lt;/code&gt;&lt;/strong&gt; ranges (&lt;code&gt;Range: bytes=offset-end&lt;/code&gt;) with per-chunk CRC32 so basement Wi-Fi drops resume from the exact failed byte offset.&lt;/li&gt;
&lt;li&gt;When you shrink mbedTLS &lt;code&gt;MBEDTLS_SSL_IN_CONTENT_LEN&lt;/code&gt; to &lt;code&gt;4096&lt;/code&gt; bytes on constrained MCUs, configure Nginx with &lt;code&gt;ssl_buffer_size 4k;&lt;/code&gt; (instead of the 16KB default) so small TLS heaps never stall or fail handshake reads.&lt;/li&gt;
&lt;li&gt;Write to inactive &lt;strong&gt;Slot B&lt;/strong&gt;, verify full-slot &lt;strong&gt;SHA-256&lt;/strong&gt;, reboot, and &lt;strong&gt;gate permanent activation (&lt;code&gt;mark_app_valid&lt;/code&gt;) on actual TLS/OCPP cloud heartbeat check-in within 3 boot watchdog cycles&lt;/strong&gt;—never solely on Flash CRC or reaching &lt;code&gt;main()&lt;/code&gt;, or a broken TLS config produces an "orphan brick" that boots happily while staying offline forever.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Benchmarks &amp;amp; Reference Implementation
&lt;/h2&gt;

&lt;p&gt;For full side-by-side protocol tables, Nginx/mbedTLS sizing notes, and runnable open-source Go Range 206 OTA server code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;OCPP 1.6J vs 2.0.1 Field Guide&lt;/strong&gt;: &lt;a href="https://space-bit.com/guides/ocpp-16j-vs-201-ev-charger-offline-ble-guide/?utm_source=devto_hashnode&amp;amp;utm_medium=article" rel="noopener noreferrer"&gt;Read the full comparison&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;STM32/ESP32 Range 206 OTA Guide&lt;/strong&gt;: &lt;a href="https://space-bit.com/guides/stm32-esp32-http-range-206-ota-dual-bank-rollback/?utm_source=devto_hashnode&amp;amp;utm_medium=article" rel="noopener noreferrer"&gt;Byte-level debugging &amp;amp; A/B rollback spec&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;EV Charger Stack Overview&lt;/strong&gt;: &lt;a href="https://space-bit.com/solutions/ocpp-ev-charger/?utm_source=devto_hashnode&amp;amp;utm_medium=article" rel="noopener noreferrer"&gt;OCPP 1.6 + BLE + Single-Binary Go CSMS&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Open-Source Kit (&lt;code&gt;cmd/constrained-ota-server&lt;/code&gt;)&lt;/strong&gt;: &lt;a href="https://github.com/bobobo2026/aiot-production-kit" rel="noopener noreferrer"&gt;github.com/bobobo2026/aiot-production-kit&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Curious if anyone else hit truncated S3 URLs or &lt;code&gt;ssl_buffer_size&lt;/code&gt; mismatches when shrinking mbedTLS heaps on STM32 or ESP32?&lt;/p&gt;

</description>
      <category>iot</category>
      <category>embedded</category>
      <category>evcharging</category>
      <category>firmware</category>
    </item>
  </channel>
</rss>
