thin-edge.io
thin-edge.io copied to clipboard
Document programmatic example for sending telemetry data from thin-edge
Is your documentation request related to a problem? Please describe.
Our current documentation only contains examples using the tedge mqtt
commadline tool to send data from thin-edge. Having a programmatic example written in C/C++ would be helpful for many developers.
Describe the improvement you'd like
A minimal programatic example that showcases how to connect to the local broker and send a simple measurement like temperature measurement using Thin Edge JSON in C/C++. This example should be published in our public documentation, linked from the existing doc that showcases the tedge mqtt pub
based samples.
Adding an additional Python example would also help. We can expand this set in future with Rust, Go and Java examples as well, if there's interest.
I have a Python example to publish JSON. You might be able to use this.
import json
import paho.mqtt.publish as publish
temperature = 10.0
humidity = 45.0
raw = {
"temperature": temperature,
"humidity": humidity
}
data_json = json.dumps(raw)
publish.single("tedge/measurements", data_json, hostname="localhost")
AC:
Extend the document
- Add the simple code example above (Python) on the doc that publishes measurements to localhost.
- Link to the example code written in C from the example repo. https://github.com/thin-edge/thin-edge.io_examples/tree/main/bme280
Needs to be considered (out of scope of this issue)
- MQTT explanation
- We use those examples in our test