Difference between revisions of "Sending data to Senfi/zh-cn"
(Created page with "Senfi监视并存储您现有系统中的时间序列数据。目前,Senfi提供了[https://mqtt.org/ 消息队列遥测传输]接口,以便接收您系统的数据。若...") |
(Created page with "# 在内容管理系统中创建integration key # 在内容管理系统中设计和创建测量 # 编写程序以从您的系统中读取数据并将其发送到Senfi的消息...") |
||
Line 1: | Line 1: | ||
Senfi监视并存储您现有系统中的时间序列数据。目前,Senfi提供了[https://mqtt.org/ 消息队列遥测传输]接口,以便接收您系统的数据。若要开始向Senfi发送数据,您需要执行以下操作: | Senfi监视并存储您现有系统中的时间序列数据。目前,Senfi提供了[https://mqtt.org/ 消息队列遥测传输]接口,以便接收您系统的数据。若要开始向Senfi发送数据,您需要执行以下操作: | ||
− | # | + | # 在内容管理系统中创建integration key |
− | # | + | # 在内容管理系统中设计和创建测量 |
− | # | + | # 编写程序以从您的系统中读取数据并将其发送到Senfi的消息队列遥测传输端点 |
=== Create integration key === | === Create integration key === |
Revision as of 15:08, 4 November 2019
Senfi监视并存储您现有系统中的时间序列数据。目前,Senfi提供了消息队列遥测传输接口,以便接收您系统的数据。若要开始向Senfi发送数据,您需要执行以下操作:
- 在内容管理系统中创建integration key
- 在内容管理系统中设计和创建测量
- 编写程序以从您的系统中读取数据并将其发送到Senfi的消息队列遥测传输端点
Contents
Create integration key
- Login to the CMS
- Go to the Developer > Integration tab
- Click the + button to add a new integration key/secret pair
- Note down the values of the Key (your integration key) and Secret (your integration secret)
Design/create measurement
The key to a successful integration is to have a well-designed measurement. So if you are not familiar with the concept of measurement/metric/tag, please read this section first.
- When you are designing a measurement to represent your system, note down the metrics you want to capture.
- Decide on a set of tags to use. Make sure that there is a combination of tags that will uniquely identify the unit/device/equipment that outputs those metrics.
- Login to the CMS.
- Go to the Measurement tab.
- Click the + button to add a new measurement.
- Give the measurement a descriptive name. This will be shown to users of the dashboard.
- Specify a measurement code.
- Add tags.
- Add metrics and specify the type of each metric.
- Save when done.
Publish to MQTT
A typical integration follows this pattern:
External system --> Your application --> Senfi MQTT endpoint
Either the external system you are monitoring pushes to your application, or your application polls the external system for its current values. Either way, once your application has the values of its measurement, you can prepare to send it to Senfi's MQTT endpoint.
MQTT Endpoint
- Host
- mqtt.senfi.io
- Port
- 1883
- Username
- <Your integration key>
- Password
- <Your integration secret>
- MQTT topic
- ingestor/1/0/live/text/array/ems/<your integration key>/<your measurement code>
Message Format
The message body should be in valid JSON format.
Single measurement
{ "data": [ { "tm_source": xxxxxxxxxx, "site_id" xxxxxxxx, "tag1": "xxxxxxxx", "tag2": "xxxxxxxx", "metric1": xxxxxxxxx, "metric2": xxxxxxxxx ... } }
Multiple measurements
{ "data": [ { "tm_source": xxxxxxxxxx, "site_id" xxxxxxxx, "tag1": "xxxxxxxx", "tag2": "xxxxxxxx", "metric1": xxxxxxxxx, "metric2": xxxxxxxxx ... }, { "tm_source": xxxxxxxxxx, "site_id" xxxxxxxx, "tag1": "xxxxxxxx", "tag2": "xxxxxxxx", "metric1": xxxxxxxxx, "metric2": xxxxxxxxx, ... } ] }
You must indicate which Site the measurement is meant for. Hence, you need to include the site ID (site_id) in your MQTT message. If your measurement has other tags, you must send them in the message as well.
Metric Data Types
Senfi supports the following data types
- Float
- Integer
- Boolean
- String
- Float
- Only valid JSON Number is accepted.
- 0
- 0.1
- 1.0e+10
- Invalid examples:
- 1.0.0
- "1.0"
- Integer
- Only valid JSON Number is accepted. Decimal values are truncated.
- 0
- -15
- 1e10
- Invalid examples:
- Same as Float
- Boolean
- Only JSON Boolean is accepted.
- true
- false
- Invalid examples:
- "true"
- "FALSE"
- 0
- "1"
- String
- Any valid JSON String is accepted.
Sample Application
You can take a look at this GitHub repository for a sample application to send data to Senfi's MQTT endpoint.
Publishing Strategy
You can either choose to publish data to Senfi regularly (eg. every second), or only do so upon change in the metrics. In practice, it is recommended that you publish regularly. This is so that the system is able to tell when data has stopped coming in.
In addition, you can choose to batch the sending of measurements to Senfi. For example, collect 50 measurements and then publish it in a single message. This may be useful if you have fast changing metrics. However, note that tm_source should represent when the measurement is sampled and not when it is sent. Next: Adding a rule