Difference between revisions of "V2/Integrate/Others/MQTT"
From Senfi Docs
Elysia.Tan (talk | contribs) (Created page with "<h1 class="main-heading">Publish to MQTT</h1> To start sending data to Senfi, you need to do the following: # Create an V2/CMS_Tutorial/Developer_Tools/Integration/Key|inte...") |
m (A missing "]" is added to the "Single measurement" example.) |
||
(5 intermediate revisions by 4 users not shown) | |||
Line 8: | Line 8: | ||
A typical integration follows this pattern: | A typical integration follows this pattern: | ||
− | External system | + | 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. | 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. | ||
Line 17: | Line 17: | ||
; Username: ''<Your integration key>'' | ; Username: ''<Your integration key>'' | ||
; Password: ''<Your integration secret>'' | ; Password: ''<Your integration secret>'' | ||
− | ; MQTT topic: ingestor/ | + | ; MQTT topic: ingestor/2/0/live/text/array/''<your integration key>/<your measurement code>'' |
=== Message Format === | === Message Format === | ||
Line 27: | Line 27: | ||
{ | { | ||
"tm_source": xxxxxxxxxx, | "tm_source": xxxxxxxxxx, | ||
− | |||
"tag1": "xxxxxxxx", | "tag1": "xxxxxxxx", | ||
"tag2": "xxxxxxxx", | "tag2": "xxxxxxxx", | ||
Line 34: | Line 33: | ||
... | ... | ||
} | } | ||
+ | ] | ||
} | } | ||
Line 41: | Line 41: | ||
{ | { | ||
"tm_source": xxxxxxxxxx, | "tm_source": xxxxxxxxxx, | ||
− | |||
"tag1": "xxxxxxxx", | "tag1": "xxxxxxxx", | ||
"tag2": "xxxxxxxx", | "tag2": "xxxxxxxx", | ||
Line 49: | Line 48: | ||
}, | }, | ||
{ | { | ||
− | "tm_source": xxxxxxxxxx | + | "tm_source": xxxxxxxxxx |
− | |||
"tag1": "xxxxxxxx", | "tag1": "xxxxxxxx", | ||
"tag2": "xxxxxxxx", | "tag2": "xxxxxxxx", | ||
Line 60: | Line 58: | ||
} | } | ||
− | You must | + | You must send Tags of the measurement in the message. |
<div class="important">Note: '''All''' tags and metrics must be sent in your message body, or they will be treated as invalid data and discarded.</div> | <div class="important">Note: '''All''' tags and metrics must be sent in your message body, or they will be treated as invalid data and discarded.</div> | ||
=== Sample Application === | === Sample Application === | ||
− | You can take a look at [https://github.com/gelement-com/mqtt-ingestor-sample | + | You can take a look at this [https://github.com/gelement-com/mqtt-ingestor-sample GitHub repository] for a sample application to send data to Senfi's MQTT endpoint. |
Latest revision as of 08:46, 31 March 2022
Publish to MQTT
To start sending data to Senfi, you need to do the following:
- Create an integration key/secret pair in the CMS.
- Design and create a measurement in the CMS.
- Write a program to read from your system and send it to Senfi's MQTT Endpoint.
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/2/0/live/text/array/<your integration key>/<your measurement code>
Message Format
The message body should be in valid JSON format.
Single measurement
{ "data": [ { "tm_source": xxxxxxxxxx, "tag1": "xxxxxxxx", "tag2": "xxxxxxxx", "metric1": xxxxxxxxx, "metric2": xxxxxxxxx ... } ] }
Multiple measurements
{ "data": [ { "tm_source": xxxxxxxxxx, "tag1": "xxxxxxxx", "tag2": "xxxxxxxx", "metric1": xxxxxxxxx, "metric2": xxxxxxxxx ... }, { "tm_source": xxxxxxxxxx "tag1": "xxxxxxxx", "tag2": "xxxxxxxx", "metric1": xxxxxxxxx, "metric2": xxxxxxxxx, ... } ] }
You must send Tags of the measurement in the message.
Note: All tags and metrics must be sent in your message body, or they will be treated as invalid data and discarded.
Sample Application
You can take a look at this GitHub repository for a sample application to send data to Senfi's MQTT endpoint.