|
| 1 | +# Trash Sorter Pro v2.1.0 — Cloud Map & Hardware Bridge |
| 2 | + |
| 3 | +**Released:** 2026-06-20 |
| 4 | +**Production:** <https://trash-sorter-v2.vercel.app> |
| 5 | +**Scope:** desktop recognition, cloud dashboard, realtime bin map, EcoPet AI, |
| 6 | +and the secure Admin hardware bridge. |
| 7 | + |
| 8 | +## What people can understand at a glance |
| 9 | + |
| 10 | +Trash Sorter Pro has two connected applications: |
| 11 | + |
| 12 | +| Application | Who uses it | Main job | |
| 13 | +| --- | --- | --- | |
| 14 | +| Desktop app | Operator/Admin at the machine | Runs the USB camera, YOLO detection, UART/Arduino commands, sound, and reads physical fullness sensors. | |
| 15 | +| Web dashboard | Admin and User | Shows cloud data: bins, alerts, collection schedules, Eco Score, reports, and EcoPet AI. | |
| 16 | + |
| 17 | +The web dashboard does **not** drive a User’s camera or machine. Admin camera |
| 18 | +and training actions travel through the protected hardware bridge; ordinary map |
| 19 | +and chat data use the cloud database directly. |
| 20 | + |
| 21 | +## Map sensor button: exact meaning |
| 22 | + |
| 23 | +The map control is intentionally **not a reset button**. |
| 24 | + |
| 25 | +`Gán cảm biến` means: *choose which cloud bin receives a physical fullness |
| 26 | +reading from the hardware machine.* For example, choosing the recyclable bin |
| 27 | +with index `3` maps the next `BIN:3:87` UART reading to that selected bin. The |
| 28 | +web map then updates to `87%`, creates/updates the appropriate alert, and User |
| 29 | +views receive the realtime update. |
| 30 | + |
| 31 | +```mermaid |
| 32 | +flowchart LR |
| 33 | + A[HC-SR04 / firmware] -->|BIN:3:87| B[Desktop agent] |
| 34 | + B --> C[Supabase hardware synchronizer] |
| 35 | + C -->|looks up current Admin assignment| D[demo_hardware_targets] |
| 36 | + D --> E[Selected bin in bins table] |
| 37 | + E --> F[Realtime event and alert] |
| 38 | + F --> G[Admin and assigned User map] |
| 39 | +``` |
| 40 | + |
| 41 | +### What Admin sees |
| 42 | + |
| 43 | +1. Open **Bản đồ thùng**. |
| 44 | +2. Open a station marker. |
| 45 | +3. Read the green explanation block: it says the action assigns a physical |
| 46 | + sensor and does not reset the current fill percentage. |
| 47 | +4. Press **Gán cảm biến** on the intended O/R/I bin. |
| 48 | +5. The action changes to **Đang nhận dữ liệu cảm biến** and a success message |
| 49 | + confirms the `BIN:<index>` mapping, station, and non-reset behavior. |
| 50 | +6. Refreshing the page keeps the selected state because the assignment is read |
| 51 | + back from Supabase. |
| 52 | + |
| 53 | +Only one physical demo target is active at once. Selecting a different bin |
| 54 | +changes the destination for future hardware readings; it does not modify old |
| 55 | +history, erase alerts, or set a percentage to zero. |
| 56 | + |
| 57 | +### What User sees |
| 58 | + |
| 59 | +Users can see the assigned station, current fullness, and the label |
| 60 | +**Cảm biến phần cứng đang đồng bộ**. They cannot change the mapping. This avoids |
| 61 | +one User accidentally rerouting the shared physical sensor away from another |
| 62 | +station. |
| 63 | + |
| 64 | +### What happens when the bin is full |
| 65 | + |
| 66 | +- Under `80%`: normal state. |
| 67 | +- From `80%` to `94%`: warning / near full. |
| 68 | +- From `95%`: full state and an alert is created or refreshed. |
| 69 | +- Map refresh: authenticated User map checks realtime events every 1.2 seconds; |
| 70 | + the regular refresh remains as a fallback. |
| 71 | + |
| 72 | +## Security and role boundaries |
| 73 | + |
| 74 | +| Action | Admin | User | |
| 75 | +| --- | --- | --- | |
| 76 | +| Assign the shared physical sensor target | Yes | No | |
| 77 | +| View assigned bins and realtime fullness | Yes | Yes, only assigned stations | |
| 78 | +| Use camera/live/training through bridge | Yes | No | |
| 79 | +| Read another account’s map/history | No special restriction for operations | No | |
| 80 | + |
| 81 | +The assignment is validated server-side against an active station and active |
| 82 | +bin. A User cannot forge an owner name. The bridge exports neither images, |
| 83 | +tokens, raw logs, passwords, nor arbitrary local endpoints. |
| 84 | + |
| 85 | +## Operating the bridge |
| 86 | + |
| 87 | +On the hardware computer, run: |
| 88 | + |
| 89 | +```powershell |
| 90 | +powershell -ExecutionPolicy Bypass -File scripts/start_public_hardware_bridge.ps1 |
| 91 | +``` |
| 92 | + |
| 93 | +The script starts or reuses the local agent, Supabase state synchronizer, and |
| 94 | +Cloudflare tunnel. Copy its HTTPS URL into Vercel Production as |
| 95 | +`TRASH_SORTER_HARDWARE_BRIDGE_URL`; the bridge secret must match |
| 96 | +`TRASH_SORTER_HARDWARE_BRIDGE_SECRET` on both sides. |
| 97 | + |
| 98 | +For a real deployment, use a named Cloudflare Tunnel or service manager. A |
| 99 | +Quick Tunnel URL changes whenever `cloudflared` restarts, so Vercel must be |
| 100 | +updated and redeployed after a URL change. |
| 101 | + |
| 102 | +## EcoPet AI in this release |
| 103 | + |
| 104 | +- Runs server-side with DeepSeek; no API key is exposed to the browser. |
| 105 | +- Answers in Vietnamese with diacritics, short practical guidance, and |
| 106 | + role-scoped context. |
| 107 | +- User quota is 36 requests per month. |
| 108 | +- If AI is unavailable or returns poor Vietnamese text, EcoPet uses a safe |
| 109 | + Vietnamese fallback and does not invent machine status. |
| 110 | + |
| 111 | +## Verification completed |
| 112 | + |
| 113 | +- Web build completed successfully. |
| 114 | +- Unit suite: **89/89 passed**. |
| 115 | +- Production alias and external bridge health endpoint were verified before |
| 116 | + this release candidate. |
| 117 | + |
| 118 | +## Upgrade checklist |
| 119 | + |
| 120 | +1. Apply the Supabase migrations, including |
| 121 | + `202606180004_demo_hardware_targets.sql`. |
| 122 | +2. Set `NEXT_PUBLIC_DEMO_HARDWARE_TARGET=1` on Vercel only when the demo sensor |
| 123 | + control is intentionally enabled. |
| 124 | +3. Set `TRASH_SORTER_DEMO_HARDWARE_TARGET=1` only on the hardware bridge. |
| 125 | +4. Confirm a bridge health response before enabling Admin camera controls. |
| 126 | +5. Sign in as Admin, assign one sensor target, then send a safe test reading |
| 127 | + such as `BIN:3:65` from the hardware firmware. |
| 128 | +6. Sign in as the assigned User and confirm the map updates without exposing |
| 129 | + Admin controls. |
0 commit comments