Activating a device
Activate a batch of GPS devices through Navixy GraphQL API with automatic or manual setup, correct a wrong phone number, resend a lost SMS, and list the devices still waiting to connect.
This guide shows how to activate GPS devices in your workspace through the Business Data Repository API and how to handle what goes wrong on the way: a wrong phone number, a lost SMS, and a device that never connects. You will check that the phone numbers are available, activate a batch of devices, correct one of them, resend the settings to another, and list the devices that are still waiting to connect. Then you will activate a device that you set up by hand.
Every operation on this page reads or changes the data of the workspace named by your access token. For the shortest path from a token to one activated device, see Getting started. This guide starts where that page ends.
Prerequisites
You need an access token for the workspace, with a role that creates and updates devices. See Authentication for how to get a token and what your roles allow. For each device you also need its identifier: the IMEI or, for a Suntech model, the serial number. For automatic setup, which the scenario below uses, you also need the phone number of its SIM card and the APN settings of the carrier.
Activation needs the ID of a supported device model. List the supported models, narrowed to the model you hold:
query SupportedModel {
bdr {
deviceModels(filter: { supported: true, titleContains: "FMB003" }) {
nodes {
id
code
title
vendor {
title
}
}
}
}
}Response:
An empty list means that the model isn't supported: the platform doesn't decode its data, so deviceActivate refuses it. Only supported models can be activated.
The last step of the scenario filters devices by status. Read the IDs of the built-in statuses once:
Response:
Save the ID of awaiting_connection. Status IDs are the same in every workspace, so you can read them once.
How activation works
deviceActivate creates the device record with the value of identifier as its identifier and sets its status to awaiting_connection. The identifier is the value that the protocol of the model names a device by:
Model
identifier
Stored as
Suntech models
The serial number that the device sends: 6 to 10 digits, not all zeros. Leading zeros are kept.
The SERIAL_NUMBER identifier of the device, in the suntech namespace
Every other model
The IMEI: exactly 15 digits
The IMEI identifier of the device
The API checks the value against the model. The examples on this page activate Teltonika devices, so they send an IMEI.
Before the device can send data, it needs two settings: the address of the Navixy server and the APN of the carrier. The setup field of the input says how the device gets them:
setup
How the device gets its settings
phone and apn
AUTOMATIC, the default
deviceActivate queues an SMS to the SIM card. The SMS contains the APN settings and the address of the Navixy platform. When the device receives it, the device connects to the platform on its own. The platform sends this SMS to Teltonika models only.
Required
MANUAL
You enter the server address, the port, and the APN on the device yourself, for example in the configuration tool of the manufacturer. deviceActivate sends nothing to the device.
Optional. When you send them, they must have the correct format. apn.password is ignored.
deviceActivate stores the phone number and the APN settings that you send, and activation.setup of the device returns the setup. Every activated device gets the built-in gps_tracker type, so the input takes no type. The scenario below uses automatic setup. For manual setup, see Activation with manual setup.
With automatic setup, activationSms in the response says whether the SMS was queued:
activationSms
Meaning
QUEUED
Every SMS is queued for sending. Some models take the settings in several SMS. The value doesn't say whether an SMS was sent or delivered.
SERVICE_UNAVAILABLE
Your installation of Navixy can't send activation SMS. No SMS is queued.
MODEL_NOT_SUPPORTED
The platform can't build the SMS for this device. The model or its protocol has no such command, the installation publishes no server address, or the device lacks the identifier that its protocol needs. No SMS is queued.
QUEUE_REFUSED
The command queue refused an SMS, for example, because the queue is full. The SMS queued before it stay queued, but they don't contain all the settings.
With any value except QUEUED, the device is still created and awaiting_connection. Enter the server address, the port, and the APN on the device yourself, from activation.server when it isn't null. With manual setup, activationSms is null, because nothing is sent.
The Device Management web app expects a device to connect within 2 minutes after activatedAt. The app measures the 2 minutes on the server clock, not on the clock of the browser. To do the same, read serverTime at the root of the query and compare it with activatedAt:
Response:
The device was activated 2 minutes and 21 seconds ago by the server clock. Each request reads the clock again, so serverTime changes with every request. If a device with automatic setup is still awaiting_connection after 2 minutes, the app offers Retry activation. The retry sends deviceActivate again with the same IMEI, as the correction and resend steps of the scenario below do.
A second activation with the serial number of a Suntech device always fails with DUPLICATE on input.identifier, whatever the status of the device. Three rules decide what happens to a second activation with the same IMEI:
While the device is
not_activatedorawaiting_connection, the call attaches to it. It replaces the setup, the phone number, the APN settings, and the model, and it replaces the title when you send a title that isn't blank. If the SMS of the earlier activation is still waiting to be sent, the call cancels it. With automatic setup, it then queues a new SMS. Use it to correct a typo, to resend a lost SMS, or to change the setup of a device that hasn't connected yet.Once the device is
activeorinactive, the IMEI is taken, and the call fails withDUPLICATEoninput.identifier.An IMEI that belongs to a device of another workspace fails the same way. The error doesn't say which workspace holds it.
The second activation replaces the phone number and the APN settings even when it doesn't send them. A re-run with manual setup and without phone leaves the device with no phone number, and the number becomes available for another device.
The phone number is unique across the platform too. A second device with the same number fails with DUPLICATE on input.phone. Devices with manual setup that have no phone number don't conflict with each other. To check a number before you activate, call deviceActivationPhoneAvailable, as the first step of the scenario shows. With automatic setup, the APN password goes into the SMS only: the API neither stores nor returns it, so every re-run needs it again.
A device that was created with deviceCreate can be activated later with the same call. It attaches to the existing record, because that record is not_activated.
Devices documents every field of the input and of DeviceActivation.
Example scenario: A fleet operator activates a shipment of devices
TransLog GmbH runs delivery trucks out of Hamburg. A shipment of three Teltonika FMB003 devices arrived, each with a SIM card from the same carrier. The administrator checks that the three phone numbers are available and activates the devices, then finds that one phone number was typed wrong and that another device didn't receive its SMS.
Check that the phone numbers are available
A phone number can belong to only one device on the platform. Before you activate, check the three numbers with deviceActivationPhoneAvailable. deviceActivationPhoneAvailable checks one number per call, so give each number its own alias in the bdr block. See Aliases to learn how aliases work. Run this query:
Response:
true means that no device in any workspace has the number, so deviceActivate accepts it. false means that another device has the number, and deviceActivate with it fails with DUPLICATE on input.phone. The response doesn't say which device or workspace has the number.
Key fields:
phoneis 5 to 20 digits, as indeviceActivate.identifieris optional. It's the identifier of the device that you activate, as indeviceActivate. Send it when you run the activation again for a device of your workspace. Then the number that this device has returnstrue, because the re-run keeps the number. Withoutidentifier, the same number returnsfalse.
The check doesn't reserve the number. If another device gets the number before your activation, deviceActivate still fails with DUPLICATE. The check doesn't find a typo either: a wrong number that no device has returns true. See Correct a wrong phone number for an example.
A phone in the wrong format or an identifier of more than 64 characters returns VALIDATION_ERROR, and field is phone or identifier, without the input. prefix. A shorter identifier in any format is accepted and matches no device. deviceActivationPhoneAvailable never returns null, so an error on one alias makes the whole data null: the other numbers get no result either. Before you send the query, check that every number has 5 to 20 digits and nothing else.
The query needs the rights to read and create devices, because the response can show that a device of another workspace has the number. Without these rights, it returns PERMISSION_DENIED.
Activate the first device
Send the IMEI, the SIM phone number, and the APN settings:
Variables:
Response:
The device exists, holds its IMEI, and is awaiting_connection. activationSms says that the platform queued the SMS, not that the SMS arrived. activation shows what was sent, without the password.
Key fields:
identifieris the IMEI for this model: exactly 15 digits. It becomes theIMEIidentifier of the device.phoneis 5 to 20 digits, with no+, spaces, or dashes.apn.nameis 1 to 40 characters of letters, digits,.,_, or-.apn.userandapn.passwordare optional and at most 40 characters each, with@allowed too.titleis optional. Without it, or when it's blank, the API names a new device after the model and the identifier, for example,FMB003 356307042772396.
Activate the other devices in one request
A bdr block runs one mutation at a time, so give each device its own aliased bdr block. See Aliases to learn how aliases work. The root fields run in the order you write them:
Response:
When one activation fails, the others still run. The failed alias holds null, and its error names the alias in path, for example ["truck03", "deviceActivate"]. Read errors and activationSms for every alias before you treat the batch as done.
Correct a wrong phone number
Truck 02 doesn't connect within 2 minutes. The administrator finds that its phone number ends in 79 on the SIM card, not 97 as typed. Run the activation again with the same IMEI and the corrected number. The device is still awaiting_connection, so the call attaches to it:
Response:
The same device came back: the id didn't change, version moved on, and title stayed because the input didn't send one. activation.phone holds the corrected number, activatedAt is the time of the re-run, and the SMS was queued again. Send the APN password again on every re-run, because the API doesn't keep it.
A wrong IMEI can't be corrected this way. A re-run with another IMEI and the same phone number fails with DUPLICATE on input.phone, because the phone number still belongs to the first device, and nothing is created. Delete the device with the wrong IMEI first, then activate again.
Resend a lost SMS
Truck 03 has the right number but doesn't connect within 2 minutes either: it didn't receive the SMS. Run the activation again with the same input. Nothing changes on the device except activatedAt and version, and the SMS is queued once more:
Response:
activationSms is QUEUED again, so the SMS is in the queue. The value doesn't say whether the SMS left the platform or reached the device.
List the devices that are still waiting to connect
The platform moves a device to active when it admits the first message from it. Nothing notifies you, so list the devices that are still awaiting_connection, with the status ID from the prerequisites:
Response, 10 minutes after the re-runs:
Truck 01 and Truck 02 connected and left the list. Truck 03 is still waiting after the resend, so the problem is on the device side: the SIM card, its data plan, or the power. The list is ordered by title. It's the same devices query as everywhere else, so combine statusIds with identifierContains or titleContains to find one device.
Activation with manual setup
With manual setup, you enter the server address, the port, and the APN on the device yourself, and the platform sends no SMS. Use it when you configure devices before you install them, or when the SIM card can't receive SMS.
Server address for manual setup
Read the server address before you activate, so that you can configure the device first. deviceActivationServer accepts the ID of the model that you activate:
Response:
host is a host name or an IP address, and port is a TCP port. The port is the port of the model's protocol, so models of different vendors can return different ports. Enter both on the device, together with the APN of the carrier.
The query returns null when your installation of Navixy publishes no server address. Then you can't set up a device by hand: use automatic setup, or ask the people who run your installation. A model that isn't supported fails with VALIDATION_ERROR on modelId, as in deviceActivate. The query needs the right to create devices.
Device activation without a phone number
Send setup: MANUAL. The phone number and the APN settings are optional, so this device is activated with its IMEI only:
Response:
The device is awaiting_connection, and nothing was sent to it. activation.server returns the same address as deviceActivationServer, so you can read the address from the device later. The port follows the model of the device: after deviceUpdate changes the model, activation.server returns the port of the new model. It's null when your installation publishes no address, or when the platform doesn't know the protocol of the device's model.
If you know the phone number or the APN settings, send them too. deviceActivate checks their format and stores them, and the search filter then finds the device by its phone number. A phone number that another device has fails with DUPLICATE on input.phone, as with automatic setup.
The platform can't read the settings of the device. The device stays awaiting_connection until its first message arrives, and then it becomes active. You don't need to run the activation again: list the devices that are still waiting, as in the last step of the scenario.
Related operations
Read the activation of one device. device(id:) returns activation with how the device receives its settings (setup), the phone number, the APN name and user, the server address for manual setup (server), and activatedAt. With manual setup, phone and apn are null when the activation didn't send them. The field is null for a device created with deviceCreate that was never activated. For a device of another workspace, device itself returns null.
Rename a device. Once the device is active, change its title with deviceUpdate. Send the version from your last read, so a concurrent change isn't overwritten. See Managing device records and identifiers.
Find every activated device. Filter devices by the status of your choice. The four built-in statuses are not_activated, awaiting_connection, active, and inactive. Only deviceActivate sets awaiting_connection, and only the platform sets active.
Retire a device. deviceDelete hides the device and detaches it from the assets that used it. A required DEVICE field that holds the device, or an IoT Logic flow that lists it in a workspace that has IoT Logic, refuses the delete with IN_USE; see Deleting a device. The IMEI stays reserved by the deleted record, so the same hardware can't be activated again with a new record today. The phone number is released.
Error handling
The activation operations return errors in the shared format. See Error handling for the response structure and the general codes.
PERMISSION_DENIED
The API couldn't tell which workspace the request acts in, or your roles don't allow creating devices. Attaching to an existing device also needs the right to update it. deviceActivationPhoneAvailable needs the right to read devices too. deviceActivationServer needs the right to create devices.
Request a token issued for the workspace, or ask an administrator of your organization for a role that reads, creates, and updates devices.
VALIDATION_ERROR
identifier doesn't fit the model (15 digits for an IMEI, 6 to 10 digits for the serial number of a Suntech model), phone isn't 5 to 20 digits, apn.name breaks its format, or the model isn't supported. Or setup is AUTOMATIC, the default, and the input has no phone (input.phone) or no apn (input.apn.name). field names the argument.
Read field and detail and correct the value. Pick the model from deviceModels(filter: { supported: true }). To activate without a phone number or APN, send setup: MANUAL.
NOT_FOUND
modelId names no model.
Send the id as deviceModels returned it.
DUPLICATE
The IMEI belongs to a device that is active or inactive, to a deleted device, or to a device of another workspace (input.identifier). Or the serial number of a Suntech model belongs to any device (input.identifier). Or the phone number belongs to another device (input.phone).
Check the IMEI and the phone number against the SIM card and the device label. For a wrong IMEI on an existing record, delete that record first.
Activating with a model that the platform doesn't support returns this error:
How to handle an unsupported model
Read field: input.modelId means that the model exists but isn't supported. List the supported models with deviceModels(filter: { supported: true }) and pick the one that matches the hardware. If your hardware isn't in that list, the platform can't activate it. Register it with deviceCreate instead and configure it by other means.
Activating a second device with a phone number that is already in use returns this error:
How to handle a duplicate phone number
Find the device that has the number with devices(filter: { search: "<phone number>" }): search matches the activation phone number of a device too. An empty result means that the device with this number belongs to another workspace or that your role can't read it. If that record has the wrong IMEI, delete it and activate again. If the number is really shared, the SIM card is in the wrong device.
See also
Getting started: The shortest path from a token to one activated device.
Managing device records and identifiers: Update and delete devices, and manage their identifiers.
Creating assets and assigning devices: Link the activated devices to the vehicles they track.
Devices: Every device operation and type, including
deviceActivateandDeviceActivation.Error handling: The error format, every error code, and how to handle each one.
Last updated
Was this helpful?