/ota-backend

Firmware hosting for Over-The-Air updates

Primary LanguageJavaScriptMIT LicenseMIT

ota-backend

Firmware hosting for Over-The-Air updates

Warning: This is experimental. API and internals will change.

API

Authorization

Once you have a firmware created, use the following:

x-ota-firmware-id: <id>
x-ota-firmware-key: <key>

Devices need to send:

x-ota-firmware-id: <firmware-id>
x-ota-device-id: <random-id>

Optionally, set the env OTA_SECRET to require it for all endpoints:

x-ota-secret: <secret>

Status code

  • 401 INVALID_AUTH
Create a new firmware

POST /v1/create

Response body

{
  id: Number,
  key: String
}

Status code

  • 200
Allow a device to use OTA

POST /v1/firewall/allow

Request headers

{
  'x-ota-firmware-id': String,
  'x-ota-firmware-key': String
}

Request body

{
  device_id: String // Use 'all' to allow anyone
}

Status code

  • 200
Deny a device to use OTA

POST /v1/firewall/deny

Request headers

{
  'x-ota-firmware-id': String,
  'x-ota-firmware-key': String
}

Request body

{
  device_id: String // Use 'all' to remove the anyone allowance
}

Status code

  • 200
Upload a new OTA update

POST /v1/upload

Request headers

{
  'x-ota-firmware-id': String,
  'x-ota-firmware-key': String
}

Request body

{
  file: Object // E.g. send a file via multipart/form-data
}

Response body

{
  hash: String
}

Status code

  • 200
Check for updates

POST /v1/check/:hash?

Request headers

{
  'x-ota-firmware-id': String,
  'x-ota-device-id': String
}

Response body (on status 200)

{
  hash: String
}

Status code

  • 200 New hash
  • 204 Hash is up to date
  • 404 FIRMWARE_NOT_UPLOADED
Download a firmware

POST /v1/download/:hash

Request headers

{
  'x-ota-firmware-id': String,
  'x-ota-device-id': String
}

Status code

  • 200
  • 404 FIRMWARE_NOT_AVAILABLE

Setup

How to self-host

Set environment variables by using the .env file:

BACKEND_HOST = "127.0.0.1"
BACKEND_PORT = 1337

OTA_SECRET = "" # Optional to protect all endpoints

Run the server:

node app.js

License

MIT