Hướng dẫn chi tiết
Bài 4: BLE Advertising — Cách node gửi dữ liệu
Hiểu BLE Advertising, format payload text, giới hạn packet size, và cách dùng nRF Connect để xem node đang advertise.
Cập nhật 10/05/2026
BLE Advertising là gì?
Node phát (broadcast) dữ liệu định kỳ qua BLE. Gateway scan và nhận — không cần kết nối pair.
Node → BLE Advertising (100–200ms/lần)
→ Gateway đang scan
→ Nhận payload → xử lý
Payload Format
IOTLABS|<node_id>|<mode>|<SensorType>|<key>=<value>[|unit=<unit>]
| Trường | Ví dụ |
|---|---|
| Prefix | IOTLABS |
| Node ID | node_001 |
| Mode | mock hoặc real |
| Sensor Type | TemperatureSensor | DoorSensor |
| Metric | temperature=28.5 | door_open=true |
| Unit | unit=C (nếu có) |
Giới hạn BLE Packet
BLE scan response giới hạn ~29 ký tự cho device name. Payload dài hơn bị cắt bớt — không ảnh hưởng học tập vì log Serial luôn hiển thị đầy đủ.
Xem BLE với nRF Connect
- Tải nRF Connect for Mobile (iOS/Android)
- Mở app → Scan
- Tìm thiết bị có tên chứa
IOTLABS - Xem payload trong phần tên thiết bị
Chu kỳ advertising
Mỗi 5 giây (theo ADVERTISE_INTERVAL_MS), node gửi lần lượt:
- Advertise TemperatureSensor payload
- Advertise DoorSensor payload
