这个动作被设计用来通过REST API检索JSON数据。它支持 "POST "和 "GET"数据请求类型。
identifier:rest_request
属性
rest_url。REST API URL
可能的值。其他URL
- 要求:是
- 例如 :"https://myfcc.com/sampledata/enginedata"
request_type:REST请求类型
可能的值:"POST","GET"
value_path:JSON数据值的路径
例子。
"$.rpm" //check Jayway JsonPath for more examples
rest_params。应该传递给REST服务的参数
可能的值。湿度
例子。
\<list name="rest_params"
listType="NAMED">
\<param name="serial"
type="string">1337\</param>
\</list>
repeat_every_ms:时间间隔,以毫秒为单位,之后动作会请求新的值。
可能的值。整数
payload_path。一个可选择的路径,可以存储接收到的值。如果没有给出路径,将使用 "sensor_value"。
可能的值。字符串
实例
让我们考虑一个JsonPath,给定以下JSON结构。
[{
"color"="blue",
"id"=87427,
"name"="Blueforce87427",
"position"={
"datetime"="2017-07-20T13: 58: 47.947513+02: 00",
"positionX"=2722,
"positionY"=2,
"positionZ"=3980
}
}{
"color"="red",
"id"=11111,
"name"="Opfor11111",
"position"={
"datetime"="2017-07-20T13: 58: 47.947513+02: 00",
"positionX"=3222,
"positionY"=232,
"positionZ"=4000
}
}]
你可以使用以下JsonPath字符串来从端点检索数据。
1.JsonPath。
$[0]['name']
1.返回的字符串。
Blueforce87427
2.JsonPath。
$[0]['position']
2.返回的字符串。
[{
"datetime"="2022-07-27T13:58:47.925260+02:00,
"positionX"=2722,
"positionY"= 2,
"positionZ"= 3980
}]
3.JsonPath。
$[*]
3.返回的字符串。包含两个对象的整个数组
最小的
<rest_request id="my_rest_test0">
<param name="rest_url" type="string">https://alex.dev.ubimax.com/sampledata/enginedata</param>
<param name="request_type" type="string">POST</param>
<param name="value_path" type="string">$.rpm</param>
<list name="rest_params" listType="NAMED">
<param name="serial" type="string">1337</param>
</list>
</rest_request>
所有选项
<rest_request id="my_rest_test0">
<param name="rest_url" type="string">https://alex.dev.ubimax.com/sampledata/enginedata</param>
<param name="request_type" type="string">POST</param>
<param name="value_path" type="string">$.rpm</param>
<param name="repeat_every_ms" type="string">5000</param>
<param name="payload_path" type="string">myPayload</param>
<list name="rest_params" listType="NAMED">
<param name="serial" type="string">1337</param>
</list>
</rest_request>