HTTP Interaction

HTTP交互服务(测试)


功能描述

HTTP交互服务又称UbiHTTP,UbiHTTP允许在设备、网站和Web服务之间进行通信,无需在设备级上实现协议。您可以在UbiHTTP中指定操作,然后在其他Ubibot功能中触发这些操作,比如预警功能。

创建一个UbiHTTP请求

1.创建一个新的UbiHTTP请求。单击“数据工厂”->“HTTP交互”,然后单击新建UbiHTTP;

2.指定设置,并非每种类型的请求都需要所有设置。所有UbiHTTP请求都需要以下参数;

必选参数 描述
名字 为您的UbiHTTP请求输入一个唯一的名称
API密钥 自动为UbiHTTP请求生成的API密钥
网址 输入请求数据或写入数据的网站网址,以http://或https://开始
方法 选择访问网站网址所需的以下HTTP请求方法之一:GET,POST,PUT,DELETE。

针对您发出请求的性质,可以指定其他参数。例如,对需要身份验证的服务器的UbiHTTP请求需要用户名和密码。

可选参数 描述
HTTP 授权用户名 如果您的URL需要身份验证,请输入身份验证用户名以访问私人频道或网站。
HTTP身份验证密码 如果您的URL需要验证,请输入验证密码以访问私人频道或网站。
内容类型 输入请求内容的MIME或表单类型。例如,application/x-www-form-ubibot。
主机 如果您的UbiHTTP请求需要主机地址,请输入域名。例如,api.ubibot.cn。
内容 输入想包含在请求中的消息。如果出现以下字符,将被替换成具体字符值,例如:
%%trigger_subject%% 后台构建的报警标题
eg: 预警提醒-编号为xxxx的设备(测试开关)已超出警戒范围
%%trigger_body%% 后台构建的报警消息完整内容
eg: 编号为xxxx的设备(测试开关)已超出预设定的警戒范围。
传感器:field1 (开关状态),报警瞬间值:1。(规则名:智能开关开启)。
本条预警触发记录的ID是:2692595。您可以进入管理控制台进行查看。
%%trigger_field%% 对应field名字
eg: field1 (开关状态)
%%channel_id%% 空间编号ID
eg: xxxx
%%name%% channel的名字
eg: 测试开关
%%trigger_type%% 触发类型,如果为recover则为恢复预警 仅恢复时返回
eg: recover
%%sampled_at%% 数据采集时间 (返回时间戳)
eg: 1603263103
%%rule_type%% 预警类型 (numeric-数据预警 | no_data_check-离线预警 | status_field-USB断电预警 | field_no_data_check-数据未返回预警)
eg: numeric
%%rule_name%% 预警名称
eg: 智能开关开启
%%rule_condition%% 预警阈值
eg: 10
%%action_frequency%% (change_only-突变预警 | change_only_delayed-延迟突变预警 | always-持续预警 | always_delayed-延迟持续预警)
eg: change_only
%%frequency%% (当预警为延迟预警时所设置的延迟时间单位S)
eg: 120
%%criteria%% 预警关系
eg: >
%%trigger_id%% 预警ID
eg: 2692622
%%trigger%% 预警瞬间值
eg: 1

3.保存请求。通过添加预警功能并选择UbiHTTP,您的UbiHTTP可供将来使用。

触发UbiHTTP

使用GET或POST请求,通过设置预警规则触发UbiHTTP。

  1. 单击进入“数据仓库”->“我的数据仓库”;
  2. 单击进入“数据仓库”->“我的数据仓库”;
  3. 按照应用情景进行预警信息设置;
  4. 报警方式选择“HTTP交互”->选择刚刚设置好的UbiHTTP请求名字;
  5. 保存预警;

当设备的传感器检测值到达用户设定的阈值时,UbiHTTP 请求被触发。

Overview

HTTP interaction services, also known as UbiHTTP. It allows the communication between devices, websites, and Web services without implementing protocols at the device level. You can specify operations in UbiHTTP and then trigger them in other Ubibot functions, such as the alert function.

Create a UbiHTTP request

  1. Create a new UbiHTTP request. Click “Data factory” -> “HTTP interaction”, and then click new UbiHTTP;
  2. Specify Settings. Not all Settings are required for every type of request. All UbiHTTP requests require the following parameters.
Required parameters Description
Name Enter a unique name for your UbiHTTP request.
API Key API key generated automatically for UbiHTTP requests.
Url Enter the web site address where the data is requested or written, starting with http:// or https://.
Method Select one of the following HTTP request methods to access the web site url: GET,POST,PUT,DELETE.

Additional parameters can be specified depending on the nature of your request. For example, UbiHTTP requests to servers that require authentication require a user name and password.

Optional parameters Description
HTTP authorized user name If your URL requires authentication, enter an authentication user name to access a private channel or website.
HTTP authentication password If your URL needs authentication, enter the authentication password to access the private channel or website.
Content type Enter the MIME or form type of the requested content. For example, application/x-www-form-ubibot.
Host If your ThingHTTP request requires a host address, enter the domain name. For example, api.ubibot.cn.
Content Enter the message you want to include in the request. If you want to include variables in the message content, the following types of substitution characters are currently supported:
%%trigger_subject%% Subject of Alert Message
eg:
Alert Reminder – The channel id XXXX (C-xxxx) is out of alert range
%%trigger_body%% Full Contents of Alert Message
eg:
Alert Reminder – The channel id XXXX (C-xxxx) is out of alert range.
Sensor:field1 (temperature),trigger value:1 (rule name:high temperature warning).
The trigger ID is 2692595. You can log in the console to check it.
%%trigger_field%% Trigger_field Value
eg: field1 (temperature)
%%channel_id%% Channel ID
%%name%% Channel Name
%%trigger_type%% Trigger Type
%%sampled_at%% Data acquisition time (return timestamp)
eg: 1603263103
%%rule_type%% Mode of Alert
(numeric- Sensor Alert | no_data_check- Offline Alert | status_field- USB Down Alert)
eg: numeric
%%rule_name%% Rule Name
%%rule_condition%% Threshold Value of the Rule
%%action_frequency%% (change_only – Once-only Alert | change_only_delayed- Delayed Once-only Alert | always- Continuous Alert | always_delayed- Delayed Continuous Alert)
%%frequency%% The delay time set when the alert is Delayed Alert ( unit:s )
eg: 120
%%criteria%% Condition of Alert
eg: >
%%trigger_id%% Trigger ID
eg: 2692622
%%trigger%% Trigger Value
eg: 1

Trigger UbiHTTP

UbiHTTP is triggered by setting up an alert rule using a GET or POST request.

  1. Click “Data Warehouse” -> “Data Warehouse”;
  2. Select the device to set HTTP interaction -> “Rules” -> “Create Offline/Sensor/USB Down Alert”;
  3. Set the early alert information according to the application situation;
  4. Mode of alert select “HTTP interaction” -> select the UbiHTTP request name just set up;
  5. Save alert;

UbiHTTP requests are triggered when the device’s sensor detection value reaches a user-set threshold.

Supported Substitution Characters

For example,

Body: The temperature now is %%trigger%% ℃.

Display: The temperature now is 27℃.

Body: The trigger field is %%trigger_field%%.

Display: The trigger field is field1 (Temperature).