OTA Updates

Cập nhật firmware và software cho thiết bị từ xa qua mạng không cần can thiệp vật lý

OTA Updates (Over-the-Air)

OTA Updates cho phép cập nhật firmwaresoftware cho thiết bị IoT từ xa mà không cần truy cập vật lý. Admin upload firmware một lần, platform phân phối tới hàng nghìn thiết bị và theo dõi trạng thái.

Upload Firmware Package

Vào OTA Updates > Create new package:

TrườngMô tả
TitleTên firmware (vd: ESP32_MainFirmware)
VersionPhiên bản (vd: v2.1.0)
TypeFirmware hoặc Software
Device ProfileProfile áp dụng (vd: Temperature Sensor)
FileFile binary (.bin, .hex, .elf...)
ChecksumTự động tính MD5 hoặc SHA256

Gán Firmware cho Thiết bị

Gán cho từng thiết bị

Device Details > Firmware > Chọn version

Thiết bị sẽ nhận lệnh cập nhật ngay lập tức.

Gán cho Device Profile

Device Profile > Firmware > v2.1.0

Tất cả thiết bị thuộc profile sẽ nhận cập nhật.


Trạng thái cập nhật

Platform theo dõi trạng thái từng thiết bị theo lifecycle:

QUEUED → INITIATED → DOWNLOADING → DOWNLOADED → VERIFIED → UPDATING → UPDATED ↓ (lỗi) FAILED
Trạng tháiÝ nghĩa
QUEUEDĐã xếp hàng, chờ thiết bị online
INITIATEDThiết bị bắt đầu nhận thông báo
DOWNLOADINGĐang tải firmware
DOWNLOADEDTải xong, chờ verify
VERIFIEDChecksum hợp lệ
UPDATINGĐang cài đặt
UPDATEDThành công
FAILEDThất bại (xem fw_error attribute)

Thiết bị nhận OTA qua MQTT

Thiết bị subscribe topic để nhận thông báo firmware mới:

# Subscribe nhận thông báo v1/devices/me/attributes/response/+ # Request firmware chunk v1/devices/me/firmware?title=ESP32_MainFirmware&version=v2.1.0&chunk=0&size=8192

Ví dụ Arduino/ESP32:

// Báo trạng thái cho platform void reportOTAStatus(const char* state, int progress = -1) { StaticJsonDocument<200> doc; doc["fw_state"] = state; if (progress >= 0) doc["fw_progress"] = progress; String payload; serializeJson(doc, payload); client.publish("v1/devices/me/telemetry", payload.c_str()); } // Vòng lặp tải firmware void downloadFirmware(const char* title, const char* version) { reportOTAStatus("DOWNLOADING", 0); int chunk = 0; int chunkSize = 8192; // 8KB mỗi chunk while (true) { char topic[128]; snprintf(topic, sizeof(topic), "v1/devices/me/firmware?title=%s&version=%s&chunk=%d&size=%d", title, version, chunk, chunkSize); client.publish(topic, ""); // Request chunk // ... nhận chunk và ghi vào flash reportOTAStatus("DOWNLOADING", chunk * 100 / totalChunks); chunk++; if (isDone) break; } // Verify checksum if (checksumValid()) { reportOTAStatus("VERIFIED"); reportOTAStatus("UPDATING"); ESP.restart(); // Apply firmware } else { reportOTAStatus("FAILED"); } }

Firmware Dashboard

VieLang IoT cung cấp dashboard theo dõi tổng quan OTA:

  • Biểu đồ phân bổ firmware version theo fleet
  • Danh sách thiết bị theo trạng thái update
  • Thống kê tỷ lệ thành công/thất bại
  • Lịch sử cập nhật từng thiết bị

Checksum & Bảo mật

MD5: 32 ký tự hex (nhanh, dùng cho integrity check) SHA256: 64 ký tự hex (an toàn hơn, khuyến nghị cho production)

Platform tự động tính checksum khi upload. Thiết bị verify trước khi cài đặt.


Attributes theo dõi OTA

Platform ghi các attribute này cho từng thiết bị:

AttributeÝ nghĩa
fw_titleTên firmware đang chạy
fw_versionVersion đang chạy
fw_stateTrạng thái OTA hiện tại
fw_progressTiến độ download (%)
fw_errorThông báo lỗi nếu FAILED
sw_titleSoftware title
sw_versionSoftware version