Difference between revisions of "Sending data to Senfi/zh-cn"
(Created page with "==== 讯息格式 ==== 消息正文应采用有效的[https://www.json.org/ JSON] 格式。") |
|||
Line 43: | Line 43: | ||
==== 讯息格式 ==== | ==== 讯息格式 ==== | ||
− | 消息正文应采用有效的[https://www.json.org/ JSON] 格式。 | + | 消息正文应采用有效的[https://www.json.org/ JSON]格式。 |
Single measurement | Single measurement |
Revision as of 16:05, 4 November 2019
Senfi监视并存储您现有系统中的时间序列数据。目前,Senfi提供了消息队列遥测传输接口,以便接收您系统的数据。若要开始向Senfi发送数据,您需要执行以下操作:
- 在内容管理系统中创建integration key
- 在内容管理系统中设计和创建测量
- 编写程序以从您的系统中读取数据并将其发送到Senfi的消息队列遥测传输端点
Contents
创建integration key
- 登录内容管理系统。
- 转到开发人员>集成选项卡
- 单击 + 按钮添加一对新的integration key/secret。
- 记下integration key和secret的值
设计/创建测量
成功集成的关键是拥有精心设计的测量。 因此,如果您不熟悉测量/参数/标签的概念,请先阅读本节。
- 在设计代表系统的测量时,请记下要捕获的参数。
- 确定要使用的一组标签。确保有一个标签组合,可以唯一地标识输出这些参数的单元/仪器/设备。
- 登录内容管理系统。
- 转到测量选项卡。
- 单击 + 按钮添加新测量。
- 给测量起一个描述性的名字。这将显示给仪表板的用户。
- 指定。测量码.
- 添加标签。
- 添加参数并指定每个参数的类型。
- 完成后保存。
发布到消息队列遥测传输
典型的集成遵循此模式:
外部系统 --> 您的应用程式 --> Senfi 消息队列遥测传输端点
您可以让正在监视的外部系统将当前值推送到您的应用程序,或者您的应用程序可以轮询外部系统的当前值。无论哪种方式,一旦您的应用程序有了其测量值,就可以准备将其发送到Senfi的消息队列遥测传输端点。
消息队列遥测传输端点
- 主机
- mqtt.senfi.io
- 接口
- 1883
- 用户名
- <您的integration key>
- 密码
- <您的integration secret>
- 消息队列遥测传输主题
- ingestor/1/0/live/text/array/ems/<您的integration key>/<您的测量码>
讯息格式
消息正文应采用有效的JSON格式。
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