This is an automated email from the ASF dual-hosted git repository.
HTHou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 54db6e7c0d9 Docs: add a Python MQTT publishing example (#19351)
54db6e7c0d9 is described below
commit 54db6e7c0d998173fad48f6356031e628bee9d33
Author: kayokoi Zhang <[email protected]>
AuthorDate: Thu Nov 26 22:17:29 2026 -0800
Docs: add a Python MQTT publishing example (#19351)
* Docs: add a Python MQTT publishing example
* Verify the MQTT reading by its published timestamp
Print the payload timestamp, filter the verification query by it, and
document the WRITE_DATA permission and storage confirmation.
---
example/mqtt/README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/example/mqtt/README.md b/example/mqtt/README.md
index 421dcd8b726..40b4d3affb9 100644
--- a/example/mqtt/README.md
+++ b/example/mqtt/README.md
@@ -31,3 +31,57 @@ The example is to show how to send data to IoTDB from a mqtt
client.
* Launch the IoTDB server.
* Setup database `CREATE DATABASE root.sg` and create time timeseries `CREATE
TIMESERIES root.sg.d1.s1 WITH DATATYPE=DOUBLE, ENCODING=PLAIN`.
* Run `org.apache.iotdb.mqtt.MQTTClient` to run the mqtt client and send
events to server.
+
+## Python client (tree model)
+
+Set `enable_mqtt_service=true` and `mqtt_payload_formatter=json` in
+`conf/iotdb-system.properties`, then start the local IoTDB instance.
+
+Create the destination in an IoTDB CLI session using the tree SQL dialect.
+
+```sql
+CREATE DATABASE root.sg;
+CREATE TIMESERIES root.sg.d1.s1 WITH DATATYPE=DOUBLE, ENCODING=PLAIN;
+```
+
+Install the MQTT client with `python -m pip install paho-mqtt`. Publish a
+reading to the local MQTT port. Set `IOTDB_USER` and `IOTDB_PASSWORD` in
+your shell to the credentials you use in the IoTDB CLI. Keep the MQTT client ID
+non-empty. The MQTT account needs `WRITE_DATA` on `root.sg.d1.s1`.
+
+```python
+import json
+import time
+from os import environ
+from uuid import uuid4
+
+from paho.mqtt.publish import single
+
+reading = {
+ "device": "root.sg.d1",
+ "timestamp": time.time_ns() // 1_000_000,
+ "measurements": ["s1"],
+ "values": [37.5],
+}
+print(reading["timestamp"])
+
+single(
+ "root.sg.d1.s1",
+ payload=json.dumps(reading),
+ hostname="127.0.0.1",
+ port=1883,
+ client_id=f"iotdb-{uuid4().hex[:12]}",
+ qos=1,
+ auth={"username": environ["IOTDB_USER"], "password":
environ["IOTDB_PASSWORD"]},
+)
+```
+
+Replace `<timestamp>` with the printed timestamp, then run this CLI query:
+
+```sql
+SELECT s1 FROM root.sg.d1 WHERE time = <timestamp>;
+```
+
+Check that this row contains `37.5`. If IoTDB is still processing the message,
+run the same query again. Returning from `single()` does not confirm that IoTDB
+stored the reading; filtering by timestamp avoids reading an earlier value.