# Timelapse Device Agent (Pi4 + DSLR) Agent này chạy trên thiết bị Pi4 đầu cuối để: 1. Claim thiết bị về server bằng claim code 2. Poll trạng thái approved/rejected 3. Lưu API key one-time vào `/boot/timelapse/agent.key` 4. Gửi heartbeat định kỳ về server ## Không chạy trên Mac Script install chỉ chạy trên Pi/Linux systemd. ## Setup trên Pi 4 ```bash cd /opt/timelapse git pull # install agent service sudo bash apps/device-agent/scripts/install-agent.sh # theo dõi logs journalctl -u timelapse-agent.service -f ``` ## Mock Device Simulator (test nhanh) Có thể giả lập thiết bị mà không cần phần cứng thật: ```bash # 1) giả lập thiết bị mới xin claim code python3 apps/device-agent/mock-device-cli.py claim \ --server http://localhost:3001 \ --count 5 # 2) giả lập heartbeat cho device seed demo python3 apps/device-agent/mock-device-cli.py heartbeat \ --server http://localhost:3001 \ --demo \ --interval 5 # 3) custom device list python3 apps/device-agent/mock-device-cli.py heartbeat \ --server http://localhost:3001 \ --device DEMO-001:dev-api-key-demo-001 \ --device DEMO-002:dev-api-key-demo-002 ``` Mẹo: mở dashboard và theo dõi trạng thái thay đổi realtime khi script heartbeat đang chạy. ## ## Mock Device Simulator (test nhanh) Có thể giả lập thiết bị mà không cần phần cứng thật: ```bash # 1) giả lập thiết bị mới xin claim code python3 apps/device-agent/mock-device-cli.py claim \ --server http://localhost:3001 \ --count 5 # 2) giả lập heartbeat cho device seed demo python3 apps/device-agent/mock-device-cli.py heartbeat \ --server http://localhost:3001 \ --demo \ --interval 5 # 3) custom device list python3 apps/device-agent/mock-device-cli.py heartbeat \ --server http://localhost:3001 \ --device DEMO-001:dev-api-key-demo-001 \ --device DEMO-002:dev-api-key-demo-002 ``` Mẹo: mở dashboard và theo dõi trạng thái thay đổi realtime khi script heartbeat đang chạy. ## ## Cấu hình File: `/etc/timelapse/agent.env` ```env TL_SERVER_URL=http://:3001 TL_DEVICE_NAME=Pi-DSLR-01 TL_SERIAL_NO=PI4-DSLR-01 TL_HEARTBEAT_INTERVAL=30 TL_CLAIM_POLL_INTERVAL=10 TL_CONFIG_DIR=/boot/timelapse ``` ## Luồng claim Khi service chạy lần đầu: - Agent in claim code ra terminal/log - Dashboard admin approve device - Agent tự nhận API key và bắt đầu heartbeat ## File runtime - `/boot/timelapse/agent.json` — metadata (deviceUuid, deviceId) - `/boot/timelapse/agent.key` — API key (chmod 600)