Reading flows and device data
Read IoT Logic data through Navixy GraphQL API: the attribute names of your devices, what a flow calculated, the flows of your workspace, and the flows that a device is in.
This guide shows the queries that read IoT Logic data without changing it. Use them to find the attribute names to write expressions with, to check what a flow calculated, to list your flows, and to find the flows that a device is in before you delete the device.
The examples use the two refrigerated trucks and the cold chain flow from Creating and updating flows. The guide is for developers who are comfortable with GraphQL.
Prerequisites
You need an access token for the workspace you work in, and a role with the read action on IoT Logic flows. Every query on this page is sent as an HTTP POST request with a JSON body, as shown in Prerequisites of Creating and updating flows. The steps below show only the document and its variables.
Find the attribute names of your devices
Expressions read the attributes of a device message by name, and the names depend on the device model. One model can report ignition as din1 and another as avl_2. To list the names of your devices, use the deviceAttributes query. It takes up to 1,000 device IDs:
query DeviceAttributes($deviceIds: [ID!]!) {
iotLogic {
deviceAttributes(deviceIds: $deviceIds) {
deviceId
attributes {
name
received
inFlow
}
}
}
}Variables:
Response:
Both trucks report temperature, so the cold chain flow can read it in an expression. Only Reefer truck 12 reports din1, so an expression that reads din1 would get no value for the messages of Reefer truck 17.
Use the two flags of each name to decide what your flow can do with it:
true
false
The device reports the attribute. Your flow can read it. A calculated attribute can't have this name: the write fails with ATTRIBUTE_REPORTED_BY_DEVICE.
true or false
true
A flow declares the attribute. With flowId set to your flow, these are the names of your flow. Without flowId, they can come from other flows. Your flow can't read the attributes of another flow, and it can't calculate them for the same devices (ATTRIBUTE_ALREADY_PRODUCED).
When you change a flow that already exists, send its ID as flowId. The list then shows the names that the devices report and the names of that flow only. A name of the flow has received: false for a device that the flow hasn't processed yet.
Check every name that an expression reads against this list. Validation doesn't compare the names in an expression with the data of the devices, so a misspelled name saves without an error and never gets a value.
The query needs the read action on IoT Logic flows. A name includes its channel number, such as lls_level_0, which is the form that expressions use. The result lists each device once, in the order of deviceIds. For the other rules, such as the sort order and the devices that are left out, see deviceAttributes in the reference.
The query returns names, not values. To see the values through the API, read them with flowDebugValues after the devices are in a flow. See Checking what a flow calculated. In the IoT Logic interface, Data Stream Analyzer shows the values of the devices of the flow that you open.
Checking what a flow calculated
To see what a flow calculated, read the recent values of its devices with the flowDebugValues query. It returns the last 12 values of every attribute of up to 10 devices, as the messages leave the flow. In each message, a value that the flow calculated replaces the value from the device, and the value from the device stays where the flow calculated none.
The following query reads the values of one truck of the cold chain flow:
Variables:
Response, shortened to three attributes and two messages:
The newest message comes first. In it, the truck reported 6.2 °C, so the flow calculated temperature_f as 43.16 and marked the cargo as too warm. The previous message, at 4.8 °C, was below the limit.
The two maps answer different questions:
allFieldshas one entry for each recent message. A message without the attribute has an entry withvalue: null, so the entries of all attributes line up by message. Use the map to see what the flow did with each message.nonNullFieldshas the recent values of each attribute that aren'tnull, and it can go further back thanallFields. Use it to see the last real value of an attribute that a device reports rarely. The example shows onlytemperaturein it, to keep the response short.
Each attribute has at most 12 entries, newest first. messageTime is when the device created the message, and serverTime is when Navixy received it. Large integers, times, and byte arrays are returned as strings, and durations in milliseconds.
A few more rules apply to the query:
deviceIdstakes 1 to 10 device IDs. An empty list or more than 10 different IDs fails withVALIDATION_ERROR.A device that isn't in the flow, or that your roles don't let you read, is left out of the result. A device of the flow without values yet has empty maps.
A disabled flow still returns the values that it recorded while it was enabled.
For a flow that doesn't exist in your workspace,
flowDebugValuesreturnsnull.The query returns the current values once. To follow them, send the query again.
Listing flows
To list the flows of your workspace, use flows. The query below returns the enabled flows that process one device, with the most recently changed flow first:
Variables:
Response:
The filter conditions are combined with AND:
titleContains: The title contains this text. The match ignores letter case.isEnabled: Only enabled flows, or only disabled flows.deviceId: Only flows that have this device in one of their data sources.
Without orderBy, flows are sorted by title in ascending order. You can also sort by CREATED_AT. For details on pages and cursors, see Pagination.
Finding the flows of a device
To see which flows the devices of your workspace are in, use deviceFlowLinks. It returns one link for each device in each data source, across all your flows. A device that is in no flow isn't listed. The query below returns the links of the two refrigerated trucks:
Variables:
Response:
Both trucks are in one flow, at the same data source. A device in two flows, or in two data sources of one flow, has a link for each.
The filter conditions are combined with AND:
flowId: Only the links of this flow.deviceIds: Only the links of these devices, at most 1,000 IDs. An empty list returns no links. Leave the field out to list the links of every device.
More rules apply to the query:
createdAtis when the device was added to the data source.deviceisnullin rare cases, when the flow kept a device that no longer exists. A device that a flow lists usually can't be deleted, see Devices in a flow. The link stays until you remove the device from the data source, anddeviceIdstill names the device.Links of devices that your roles don't let you read are left out, also from
total.Without
orderBy, the newest links come first. You can also sort byFLOW_TITLE, the title of the flow.A page has at most 100 links. A larger
firstorlastfails withVALIDATION_ERROR, and so does adeviceIdslist of more than 1,000 IDs.
To list the flows of a single device instead, use flows with the deviceId filter, as shown in Listing flows.
Run one of these queries before you delete a device, because a device that a flow lists can't be deleted. Remove the device from the data source with flowUpdate, or delete the flow, then delete the device. See Devices in a flow.
Errors in this guide
The queries on this page return few errors. These are the common ones:
VALIDATION_ERROR
A list of IDs is too long: more than 1,000 different devices in deviceAttributes or in the deviceFlowLinks filter, or more than 10 different devices in flowDebugValues. Or a page asks for more than 100 items
Split the request into smaller ones.
VALIDATION_ERROR
An ID in the request isn't a valid ID
Correct the ID.
PERMISSION_DENIED
Your roles don't have the read action on IoT Logic flows
Ask an administrator for a role with the action. See Authentication.
A flow that doesn't exist in your workspace isn't an error: flow and flowDebugValues return null, and devices that you can't read are left out of the results.
See also
Creating and updating flows: Create the cold chain flow that these examples read, and change it.
How IoT Logic flows work: See how a message moves through a flow and where the calculated attributes go.
Flows: Look up every field and argument of the queries on this page.
Last updated
Was this helpful?