OTA Updates
Check for, initiate, and monitor over-the-air firmware updates on RainMaker nodes.
备注
node — from getUserNodes() or getNodeDetails() after User sign in.
What This Module Does ?
Remotely update node firmware: check for an available build, push the update with a job ID, poll status until complete or failed.
Use this when a new firmware version is available and the node is online — verify with Node Management connectivity first.
Expected outcome: Firmware download and install proceed on the device; status moves through pending → in progress → completed/failed.
Common Workflows
Check, push, and read status
const otaResponse = await node.checkOTAUpdate();
if (otaResponse.otaAvailable && otaResponse.otaJobId) {
await node.pushOTAUpdate(otaResponse.otaJobId);
const status = await node.getOTAUpdateStatus(otaResponse.otaJobId);
console.log("Status:", status.status);
}
Monitor until completion
async function waitForOTA(node, otaJobId, maxAttempts = 30) {
for (let i = 0; i < maxAttempts; i++) {
const { status } = await node.getOTAUpdateStatus(otaJobId);
if (status === "completed" || status === "failed") return status;
await new Promise((r) => setTimeout(r, 5000));
}
return "timeout";
}
const ota = await node.checkOTAUpdate();
if (ota.otaAvailable) {
await node.pushOTAUpdate(ota.otaJobId);
await waitForOTA(node, ota.otaJobId);
}
Error Handling
try {
const ota = await node.checkOTAUpdate();
if (!ota.otaAvailable || !ota.otaJobId) return;
await node.pushOTAUpdate(ota.otaJobId);
} catch (error) {
console.error("OTA failed:", error);
}
On failed status, show additionalInfo from the status response.
Advanced Concepts
Mental model
Check → push → poll status.
OTA flow
Best Practices
- Check connectivity before OTA
- Show firmware version before starting
- Poll with reasonable intervals
- Warn users not to power off during update
Related Resource
- API Reference: