MachineQ Developer Documentation logo DOCS

Managed Campaigns

Managed campaigns upgrade many devices over time based on a few settings. A managed campaign runs on a single gateway for multiple days, weeks, or months. It listens for devices heard by the specified gateway, checks their firmware versions, and when it hears from devices matching the version pattern it is looking for, it schedules a campaign to upgrade those devices at a preferred time.

Before You Begin

You need:

Campaign vs. Managed Campaign

Campaign Managed Campaign
Can only upgrade devices whose DevEUIs have been specified in advance Can upgrade any number of devices, even if their DevEUIs are not known
Runs a limited number of times or until all specified devices are updated Can run in the background indefinitely to upgrade new devices as they appear
Can start at a specific date, but by default starts immediately Waits at least 24 hours while gathering its first list of devices, then starts at a specified time of day
Gateway can be determined automatically Gateway must be specified

How to Run a Managed Campaign

Create the managed campaign with the create managed campaign API. The response contains a managed_campaign_id, which you use later to get the status of the managed campaign.

Create a managed campaign
curl -sS -X POST "https://fuota.machineq.net/api/v3.2/managed_campaigns" \
  -H "Authorization: Bearer $MQ_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Managed Campaign Demo: 0.123.x.x and 0.122.99.x to 0.123.4.56",
    "image_name": "firmware_v0.123.4.56",
    "gateways": ["1122334455667788"],
    "include_versions": ["....7B00........", "..637A00........"],
    "expected_version": "38047B00........",
    "preferred_start_time_utc": "11:00",
    "run_until": "2025-01-01T12:00:00.000000Z"
  }' | jq

Required Parameters

Field Required Description
name Yes A convenient name to describe the managed campaign.
image_name Yes The image file name previously uploaded using the images API.
include_versions Yes A list of 16-character hexadecimal patterns. The managed campaign attempts to load the image onto any device the gateway saw in the past 24 hours whose hexadecimal firmware version matches any of these patterns.
expected_version Yes A hexadecimal pattern in the same format as an include_versions entry, which all upgraded devices must match after the update.
gateways Yes The list of gateways the managed campaign uses to observe devices.

Note: Currently, only one gateway is supported in a managed campaign. Support for more than one gateway is planned.

Optional Parameters

Field Description Default
exclude_versions A list in the same format as include_versions, with the opposite effect. It takes priority over include_versions, so a device matching a pattern in both is excluded. []
preferred_start_time_utc The time of day when the server schedules new campaigns. Noon (12:00)
run_until How long the managed campaign continues running. Creation date + 7 days
stop_when_no_match If True, the managed campaign stops if no matching devices are found at the preferred start time. If False, it does not create a campaign but keeps running until run_until. False
whole_subscriber If True, runs over all gateways belonging to the subscriber instead of a single gateway. Not supported yet. False

The following payload upgrades every device except those matching 0.1.2.3:

Managed campaign that excludes a version
{
  "name": "Managed Campaign Demo: Everything except 0.1.2.3 to 0.123.4.56",
  "image_name": "firmware_v0.123.4.56",
  "gateways": ["1122334455667788"],
  "include_versions": ["................"],
  "exclude_versions": ["03020100........"],
  "expected_version": "38047B00........"
}

Uploading Keys

The FUOTA server must know the multicast keys in advance to run the managed campaign. The managed campaign cannot include any devices for which it does not know or cannot generate keys.

Any DevEUI starting with 2CC407 can have its multicast key auto-generated and does not need a key uploaded. For all other devices, upload keys using the Multicast Key Management API before including them.

Multicast keys mapping DevEUI to key
{
  "0011223344556677": "aabbccddeeffaabbccddeeffaabbccdd",
  "0102030405060708": "01020304050607080102030405060708"
}

Each DevEUI is an 8-byte hex string, and each key is a 16-byte hex string.

Managed Campaign Behavior

The managed campaign scans for devices for the first 24 hours after creation. Any device that matches an include_versions filter and does not match any exclude_versions filter is scheduled for the next campaign.

Once at least one device is scheduled, the server creates the first campaign at the preferred start time. While that campaign runs, the managed campaign continues to listen for new devices and includes them in the next campaign, which runs at the preferred start time 24 hours later.

As the managed campaign approaches its run_until time, it stops creating new campaigns. After passing run_until, it stops and transitions into a "Finished" state.

State

A call to the get managed campaign API returns the creation parameters plus:

Field Description
managed_campaign_id The ID of the managed campaign.
next_update_session_time The next time the managed campaign will attempt to create a campaign.
scheduled_devices The devices that will be included in the next campaign so far.
stage_str The state of the managed campaign (see below).
updated_devices The devices updated by the managed campaign.

The stage_str field can be:

  • GATHERING_DEVICES — The main phase, where the server listens to devices and creates campaigns when new devices match the version filter.
  • RUNNING_LAST_CAMPAIGN — A campaign is running, and no more campaigns will be created after it.
  • FINISHED — The managed campaign is done.
  • CLEANED — The managed campaign is done and its campaign history has been removed.
Get the managed campaign state
curl -sS "https://fuota.machineq.net/api/v3.2/managed_campaigns/<managed_campaign_id>" \
  -H "Authorization: Bearer $MQ_TOKEN" | jq
Inspect the managed campaign response
{
  "expected_version": "04030200........",
  "gateways": ["1122334455667788"],
  "image_name": "fuota_v2.3.4.bin",
  "include_versions": ["03020100........"],
  "managed_campaign_id": "mWa77N",
  "name": "Some managed campaign",
  "next_update_session_time": "2024-08-01T11:12:13.141516Z",
  "preferred_start_time_utc": "11:00",
  "run_until": "2025-01-01T12:00:00.000000Z",
  "scheduled_devices": {
    "1111222233334444": {
      "reported_at": "2024-07-01T01:01:01.010101Z",
      "version_hex": "03020100abcdef00"
    }
  },
  "stage": 1,
  "stage_str": "GATHERING_DEVICES",
  "started_at": "2024-06-06T06:06:06.654321Z",
  "stop_when_no_match": true,
  "updated_devices": {
    "1212232334344545": {
      "reported_at": "2024-06-20T00:00:00.000000Z",
      "version_hex": "04030200abcdef00"
    }
  },
  "whole_subscriber": false
}

State Transition Diagram

No

Yes

No

Yes

Yes

No

No

Yes

No

Yes

Yes

No

No

Yes

Managed Campaign is Created

stage is INITIALIZING

stage is GATHERING_DEVICES

Collect devices matching the version filters

now + 24 hours >= run_until

>=24 hours since preferred start time
on the creation date, OR >=24 hours
since last campaign created

stage is RUNNING_LAST_CAMPAIGN

There is a running campaign

At least one collected device

if stop_when_no_match

Create new campaign with collected devices

There is an active campaign

stage is FINISHED

Delete all campaigns older than 7 days

Any campaigns remain in history

stage is CLEANED

Problematic Devices

The managed campaign tracks devices that were included in campaigns but failed for any reason. Any device that fails in more than two campaigns is treated as a "problematic device" and is not included in future campaigns.

Use the get problematic devices API to list these devices, the campaigns they failed in, and why they failed.

Inspect the problematic devices response
[
  {
    "deveui": "0102030405060700",
    "failed_campaigns": [
      ["mQKuKK", "Some failure reason"],
      ["Zne1Vm", "Some other failure reason"]
    ]
  }
]

You can clear the problematic devices list with the delete problematic devices API, which allows the managed campaign to try including those devices again.

Deleting a Managed Campaign

You can delete a finished managed campaign with the delete managed campaign API. If a managed campaign is still running, you must halt it before deleting it.

Halting a Managed Campaign

To cancel a running managed campaign and put it into a finished state where it can be deleted, use the halt managed campaign API. It can return different status codes:

  • 202 — The managed campaign is in the process of being halted.
  • 204 — The managed campaign has been successfully halted.

Note: The managed campaigns feature does not support upgrade delegation yet.

What's Next?