Implementing a Hubble Scanner
How to build your own scanner, in firmware or software, that sends directly to Hubble's Gateway API.
- If your device runs iOS or Android, use the Gateway SDK instead. It does everything on this page for you.
- If your gateways send scans to your own backend and you want to forward them from there, see Forwarding Scans From Your Cloud.
- If you have not chosen a path yet, start with Becoming a Hubble Scanner.
Who This Is For
This page is for the direct integration path. Your own firmware or software on the gateway scans and calls the Gateway API directly:
[Gateway] --> [Hubble Gateway API]
Each gateway registers with Hubble and gets its own identity and credentials. Before a gateway can register, it needs a Gateway Group ID specific to your organization. See Getting a Gateway Group ID.
On Linux, the reference application implements everything on this page. Run it, adapt it, or use it as a working example while you build your own.
This page covers how a scanner must behave: what to scan for, what metadata to attach, and how to handle authentication, batching, errors, and connectivity loss. It does not specify hardware, operating system, or connectivity (cellular, Wi-Fi, or Ethernet).
For each endpoint's request and response schema, see the Gateway API reference.
Before You Start
You need:
- A Hubble account and a Gateway Group ID. See Getting a Gateway Group ID.
- Gateway hardware that can do BLE 4.0+ passive scanning.
- Internet connectivity on the gateway.
- A reliable time source on the gateway: NTP, GPS, or cellular network time.
Base URL
Production: https://gw-api.hubble.com
All paths on this page are relative to this URL. TLS 1.2 or higher is required.
Terminology
| Term | Definition |
|---|---|
| Gateway | A device that scans for Hubble BLE advertisements and forwards them to Hubble. Also called a scanner. |
| Advertisement | A BLE broadcast packet sent by a Hubble device. |
| Packet | One scanned BLE advertisement and its metadata. |
| Gateway Group ID | An identifier for your organization's gateway group. Sent in the X-Sdk-Key header, and only at registration. |
| Gateway ID | A UUID the server assigns to one registered gateway (gatewayId). |
| Device token | A short-lived Bearer token that authenticates a registered gateway's requests. |
| Refresh token | A long-lived token that gets a new device token without registering again. |
| Batch ID | A UUID the client generates. It is the idempotency key for an upload (batchId). |
Register the Gateway
On first launch, the gateway registers with PUT /api/v1/gateways (reference), authenticated with the X-Sdk-Key header set to your Gateway Group ID. The response contains:
gatewayId: the gateway's identity for all later callsdeviceTokenandrefreshTokenexpiresInSeconds: the device token lifetimeconfigandcommands, which may be empty. See Apply Server Config and Commands.
Choosing a deviceId
deviceId must be stable and unique per physical device. Hubble uses the pair of deviceId and Gateway Group ID to identify a gateway, so:
- If the same device registers again, for example after a factory reset that wiped its stored credentials, it gets the same
gatewayIdwith fresh credentials. - If two devices send the same
deviceId, they become one gateway. Do not derivedeviceIdfrom anything shared across units, such as a model number or a firmware build.
Good sources are a BLE MAC address, /etc/machine-id, or a serial number burned in at manufacture.
Describing the Device
The registration body requires sentAtMillis, deviceId, type, manufacturer, model, and capabilities. A missing, null, or empty required field fails the request with 400 invalid_payload.
- Set
typetofixedfor stationary installs, ormobilefor gateways that move. Send the operating system inos(for example,linux) and its version inosVersion. - Send the hardware's
manufacturerandmodel. - Send
firmwareVersionfor the gateway's own firmware. It is required unlesstypeismobile. - List what the gateway can do in
capabilities, with at least one ofble_scan,location,push. If you includepush, send apushToken. - Send optional state when you have it:
batteryLevel(omit or send null for mains-powered gateways),bleAdapterState,locale.
Storing Credentials
Store these in non-volatile storage, so a restart does not register the gateway again:
gatewayIddeviceTokenrefreshToken- The device token's expiry time, computed from
expiresInSeconds - The most recent server
config
Restrict access to the gateway process, for example with a file of mode 0600. Use hardware-backed secure storage where it is available. See Security Requirements.
Manage Tokens
Send Authorization: Bearer {deviceToken} on every request after registration.
- Refresh before expiry. Do not hard-code the token lifetime: read
expiresInSeconds. Refresh shortly before the stored expiry withPOST /api/v1/auth/refresh(reference). That request has no auth header, because the refresh token in the body is the proof of identity. - Persist the rotated pair right away. Each refresh returns a new refresh token and invalidates the old one. The server accepts the previous refresh token for a 60-second grace period, which covers a crash between receiving and saving the new pair. Write the new tokens to storage before you use them. The refresh response can also carry
configandcommands: apply them as described in Apply Server Config and Commands. - Handle expiry mid-request. If a request returns
401withtoken_expired, refresh, then retry the original request once. - Re-register when credentials are no longer valid. If you get
token_revoked,invalid_refresh_token, orgateway_not_found, discard the stored credentials and register again. Because registration is idempotent, the gateway gets back its oldgatewayId.
Scan for Hubble Advertisements
Use passive BLE scanning, with no scan requests and no connections. The gateway only listens. It never connects to or talks to Hubble devices.
Hubble does not set scan interval or scan window values. Tune them to your hardware and deployment to capture as many advertisements as you can.
Identifying a Hubble Advertisement
An advertisement is a Hubble packet if it contains a Service Data – 16-bit UUID AD structure (AD type 0x16) for the Hubble Service UUID 0xFCA6 (on air: 0xA6 0xFC), with non-empty service data.
Discard advertisements that do not. Hubble devices usually also list 0xFCA6 in a 16-bit Service UUID list AD structure, but do not require that list: filter on the Service Data. For the full packet layout, see Advertising Packet.
Extracting the Payload
Extract the bytes that come after the AD type and UUID in the Service Data AD structure:
| Byte(s) | Contents |
|---|---|
| 0 | AD structure length |
| 1 | AD type: Service Data (0x16) |
| 2–3 | Hubble Service UUID (0xA6 0xFC, little-endian) |
| 4+ | Hubble service data payload. Extract and forward these bytes. |
The payload is 10 to 23 bytes, depending on whether the device adds a custom application payload.
Treat the payload as an opaque byte array. Do not parse, decrypt, interpret, or change it. Forward it exactly as you received it.
Build Each Packet
Each scanned advertisement becomes one entry in a packet upload. For the full schema, see Upload BLE scan packets.
| Field | What to send |
|---|---|
deviceAddress | The broadcasting device's Bluetooth address as uppercase, colon-separated hex, for example AA:BB:CC:DD:EE:FF. |
rssi | Received signal strength in dBm (a signed integer), as your radio measured it. Send 127 if you have no reading. Do not send 0: the server drops a packet with an RSSI of 0. |
timestampMillis | When the gateway received the advertisement, in epoch milliseconds. |
serviceUuid | fca6. A full 128-bit Bluetooth Base UUID (0000fca6-0000-1000-8000-00805f9b34fb) is also accepted. |
serviceData | The extracted payload, base64-encoded. |
location | The gateway's position at scan time. See Location. |
Timestamps and Clock Skew
All timestamps are epoch milliseconds. Every upload, registration, and heartbeat also carries sentAtMillis, the gateway's clock at send time. Hubble's backend compares sentAtMillis with its own receive time to detect and correct clock skew. That correction only works if the gateway clock is steady, so keep the gateway synced to a reliable time source.
The server drops, without telling the gateway, any packet whose timestamp is 0 or falls outside the accepted window after skew correction.
Location
Each packet carries a location with WGS 84 coordinates.
- Required:
latitude,longitude,horizontalAccuracyMeters,timestampMillis - Optional:
altitude,verticalAccuracyMeters,bearing,bearingAccuracyDegrees,speed,speedAccuracyMetersPerSecond
Guidance:
- Reuse the last fix, with its real timestamp. If location fixes are intermittent, for example a stationary install with periodic GPS, attach the most recent fix and report when that fix was taken, not the current time.
- Never send
0, 0as a placeholder. The server reads alatitudeorlongitudeof0as "no fix" and drops the packet. - Fixed installs: configure the surveyed position and a realistic accuracy.
Proof of presence is only as good as the scanner's location, so make it as accurate as you can.
Deduplication
A Hubble device can repeat the same advertisement many times a second. Before you upload, merge repeated sightings of the same deviceAddress, serviceUuid, and serviceData within a short window, and keep the strongest RSSI. Use dedupWindowMs (or activeDedupWindowMs while the gateway is moving) from the server config when it is set.
Upload in Batches
Upload packets with POST /api/v1/gateways/{gatewayId}/packets (reference).
Request Rules
- Content type. Every request body is JSON with
Content-Type: application/json. - Compression. Send
Content-Encoding: gzipfor anything but small batches. 5000 packets are about 2.3 MB uncompressed. batchId. Generate a new UUID for each batch. When you retry a batch, send it again with the samebatchId: the server deduplicates bybatchIdper gateway for 24 hours. Never reuse abatchIdfor different content.sentAtMillis. Set it when the request is sent, including on a retry.- Batch size and interval. Use the server's
uploadBatchSizeanduploadIntervalMs/activeUploadIntervalMswhen they are set.
Batch Limits
| Endpoint | Max items per batch | Max body (uncompressed) |
|---|---|---|
| Packets | 5000 | ~4 MB |
| Logs | 200 | ~1 MB |
| Locations | 500 | ~1 MB |
A batch over these limits fails with 400 invalid_payload. There is no separate error code for it, so stay under the limits on the client.
What the Server Validates
Upload endpoints check authentication and schema, then queue the batch and return 202 Accepted. Processing happens later, after the response.
- Whole-batch failure. If a required field is missing or null, the whole batch fails with
400 invalid_payload. - Silent per-item drops. If a field is present but unusable, the server drops that one packet and still accepts the batch. This covers an
rssiof0, alatitudeorlongitudeof0, and a timestamp that is0or out of range. Dropped packets are not reported back to the gateway, so validate on the client.
Standalone Locations
If the gateway records location fixes separately from scans, for example continuous GPS tracking, you can also upload them with POST /api/v1/gateways/{gatewayId}/locations (reference). This endpoint is in addition to the per-packet location. It does not replace it.
Handle Errors and Retries
Every non-2xx response has an ErrorResponse body with code, message, and retryable. Base the decision to retry on the retryable flag.
| HTTP | code | What the gateway must do |
|---|---|---|
| 400 | invalid_payload | Malformed body, missing required field, wrong Content-Type, or a batch or body that is too large. Do not resend the same payload. If the batch is oversized, split it. Otherwise, log it and drop the batch. |
| 401 | invalid_sdk_key | The Gateway Group ID is wrong or no longer valid. Stop registering and alert an operator. Do not retry in a loop. |
| 401 | missing_token | No Bearer token was sent. Fix the request, refreshing or registering first if needed. |
| 401 | token_expired | Refresh the device token, then retry the original request once. |
| 401 | token_revoked | Discard credentials and register again. |
| 401 | invalid_refresh_token | Discard credentials and register again. |
| 403 | gateway_disabled | An administrator disabled this gateway. Stop uploading and alert an operator. Registering again is also refused, so do not loop. |
| 404 | gateway_not_found | The stored gatewayId is stale or does not match the token. Register again. |
| 429 | rate_limited | Back off, then retry. Rate limits are per gatewayId. |
| 503 | server_error | Temporary backend failure. If retryable is true, back off and retry. |
Backoff
The server never sends a Retry-After header or a wait time, so the client sets its own retry schedule. For retryable errors:
- Start at a few seconds or more.
- Double the delay after each consecutive failure of the same request.
- Cap the delay. Five minutes is a reasonable ceiling.
- Add random jitter, up to about 50% of the interval, so a fleet does not retry in lockstep.
Handle 429 and retryable 503 responses this way. Retry uploads with the same batchId.
Buffer Through Connectivity Loss
If Hubble cannot be reached, buffer packets locally. When the connection returns, send them in chronological order. Because of the 24-hour batchId window, sending a batch that was already accepted again does no harm.
- Buffer size. Hubble does not set a size, because it depends on your hardware. Buffer at least 1 hour of data at your expected scan volume.
- When the buffer is full, drop the oldest packets first to make room for new ones.
Delivery is best effort. Guaranteed delivery is not required, but buffering should be reasonable.
Send Heartbeats
A heartbeat is a periodic PUT /api/v1/gateways/{gatewayId} (reference) with the same body as registration. A heartbeat does three things:
- Lets Hubble tell a working gateway in a quiet area from one that is offline.
- Updates device state, such as battery level, BLE adapter state, locale, and push token.
- Returns updated server config and any pending commands.
Send a heartbeat:
- Every 5 minutes while online
- On startup
- When the firmware or software version changes
- When the BLE adapter state changes, for example from
offtoon - When the battery level crosses a significant threshold. Every 10% is recommended.
A heartbeat does not change type or deviceId. If either differs from the registered value, the server keeps the registered value and still accepts the heartbeat. To change type, register again with the same deviceId. A different deviceId registers a separate gateway: see Choosing a deviceId.
Apply Server Config and Commands
Registration, token refresh, and heartbeat responses can include a config object and a commands list. Handle them the same way whichever call they come from.
Config
Read the config object like this:
| Response | Meaning |
|---|---|
| A field is absent or null | Use your default for that field. |
config is null | Clear all server values and go back to your defaults. |
The config key is missing entirely | The server could not work out a config this time. Keep your current values. |
Store the latest config with your credentials and apply it from the next cycle onward. Ignore unknown fields, because new ones may be added without a version change.
These are the config fields that apply to direct integrations. Some fields in the API reference are sent only to Hubble's SDKs.
| Field | Meaning |
|---|---|
uploadIntervalMs | Upload interval while idle |
activeUploadIntervalMs | Upload interval while active (moving) |
uploadBatchSize | Packets per upload batch |
dedupWindowMs | Deduplication window while idle |
activeDedupWindowMs | Deduplication window while active |
uploadOnCellular | false means hold uploads until a non-cellular link is available |
Commands
type | What the gateway must do |
|---|---|
upload_logs | Send the local debug log buffer to POST /api/v1/gateways/{gatewayId}/logs (reference). |
scan_now | Run a BLE scan cycle right away, without waiting for the normal interval. |
re_register | Discard local credentials and run registration again. |
Ignore command types you don't recognize.
Security Requirements
Transport
All traffic to the Gateway API must use TLS 1.2 or higher. Never send packet data or credentials in plaintext.
Credentials
- Gateway Group ID. A public, non-secret key, used only at registration. It is not a device credential, and you can embed it in firmware. See Getting a Gateway Group ID.
- Device token. Short-lived. Store it at rest with access restricted to the gateway process.
- Refresh token. Long-lived. Store it like the device token. Anyone who has it can act as the gateway until it is revoked, so never log it or send it off the gateway.
Rotation
Device and refresh tokens rotate on every refresh. To rotate a Gateway Group ID, create a new group in the dashboard and roll its ID out to your gateways. When no gateways depend on the old group any more, disable it. Disabling a group disables every gateway registered with it.
Disabled Gateways
An administrator can disable a gateway, or disable its whole gateway group. Disabling revokes its tokens, so the gateway usually sees 401 token_revoked first, and then 403 gateway_disabled if it tries to register again. The gateway should stop and alert an operator rather than retry.
Compliance
Radio regulations and data privacy rules apply to every scanner. See Compliance.
Implementation Checklist
- Stable, unique
deviceIdfor each physical gateway - Registration with
X-Sdk-Keyand all required fields, includingmanufacturerandmodel - Credentials and config stored with restricted access
- Token refreshed before expiry, with the rotated pair stored right away
-
token_expiredhandled with one refresh and one retry - Re-registration on
token_revoked,invalid_refresh_token,gateway_not_found, and there_registercommand - Passive scan that keeps advertisements with non-empty
0x16Service Data for0xFCA6 - Payload forwarded unchanged, base64-encoded
- No
rssiof0and no0, 0coordinates. Last fix reused with its real timestamp. - Gateway clock synced to NTP, GPS, or cellular time
- Sightings deduplicated, keeping the strongest RSSI
- Batches under the limits, gzip on large batches, a new
batchIdfor each batch, the samebatchIdon retry - Retries driven by
retryable, with exponential backoff, jitter, and a cap - At least 1 hour of local buffer, dropping the oldest packets first
- Heartbeat every 5 minutes and on state changes
- Server config applied and unknown fields ignored
-
upload_logs,scan_now, andre_registercommands handled - TLS 1.2+, refresh token never logged
ℹ️ Was this page useful? Please give us feedback.