Select to view content in your preferred language

Manage and Control IoT Devices with Velocity

1153
4
Jump to solution
04-04-2021 02:28 PM
ArthurXiao
Emerging Contributor

So far is it possible to manage IoT devices with Velocity? For example, send a command to device like this:

POST https://{Endpoint}/v5/iot/{project_id}/devices/{device_id}/commands
Content-Type: application/json
X-Auth-Token: ********

{
"service_id" : "WaterMeter",
"command_name" : "ON_OFF",
"paras" : {
"value" : "ON"
}
}

Tags (1)
0 Kudos
2 Solutions

Accepted Solutions
GregoryChristakos
Esri Contributor

Hi Arthur,

 

What you're asking is definitely possible with ArcGIS Velocity. To achieve this task, you would want to use the HTTP output to construct a POST request. Simply provide the URL, select the content type (JSON), and add any additional headers (e.g authorization token). For the message body, you'd wrap your JSON object using the Text() Arcade expression so that you can keep the JSON formatted. You can even parameterize the values in your JSON by referencing the fields from your processed data.

As an example, here is what I had tested using your sample data. The bold parts indicate what I mentioned about about Arcade/parametrized data:

text({
"service_id" : $feature["service_id"],
"command_name" : $feature["command_name"],
"paras" : {
"value" : $feature["paras_value"]
}
})

View solution in original post

0 Kudos
GregoryChristakos
Esri Contributor

Hi Arthur,

 

Instead of using URL parameters, you'll want to click on "configure expression" to format your JSON object using Arcade. The only thing, based on your example, that you'll want to have as a URL parameter is the authorization token.

 

Click here to configure your JSON body using Arcade:

GregoryChristakos_0-1618318324462.png


Specify the following to maintain the JSON object with dynamic field values. Note the resulting JSON when I tested the expression:

GregoryChristakos_1-1618318385759.png

Lastly, it's important to note that the field "paras_value" exists because I flattened the paras object as part of the feed schema. If you didn't flatten "paras" as part of the feed schema, then its likely your field name and value will be different.

 

View solution in original post

4 Replies
GregoryChristakos
Esri Contributor

Hi Arthur,

 

What you're asking is definitely possible with ArcGIS Velocity. To achieve this task, you would want to use the HTTP output to construct a POST request. Simply provide the URL, select the content type (JSON), and add any additional headers (e.g authorization token). For the message body, you'd wrap your JSON object using the Text() Arcade expression so that you can keep the JSON formatted. You can even parameterize the values in your JSON by referencing the fields from your processed data.

As an example, here is what I had tested using your sample data. The bold parts indicate what I mentioned about about Arcade/parametrized data:

text({
"service_id" : $feature["service_id"],
"command_name" : $feature["command_name"],
"paras" : {
"value" : $feature["paras_value"]
}
})

0 Kudos
ArthurXiao
Emerging Contributor

Hi Gregory,

We tried but failed when reference to the fields from processed data, actually it changed the $feature["field_name"] to string "$feature[\"field_name\"] ". So any further suggestion?

parameter input.JPGparameter output.JPG

0 Kudos
GregoryChristakos
Esri Contributor

Hi Arthur,

 

Instead of using URL parameters, you'll want to click on "configure expression" to format your JSON object using Arcade. The only thing, based on your example, that you'll want to have as a URL parameter is the authorization token.

 

Click here to configure your JSON body using Arcade:

GregoryChristakos_0-1618318324462.png


Specify the following to maintain the JSON object with dynamic field values. Note the resulting JSON when I tested the expression:

GregoryChristakos_1-1618318385759.png

Lastly, it's important to note that the field "paras_value" exists because I flattened the paras object as part of the feed schema. If you didn't flatten "paras" as part of the feed schema, then its likely your field name and value will be different.

 

ArthurXiao
Emerging Contributor

Great, thank you @GregoryChristakos very much, I will try.

0 Kudos