- 将server-ip从192.168.1.41更改为192.168.1.5 - 移除WitsData模型中的actod_label字段 - 修改wits_sender.py中的actcod值为随机生成(1-34范围内) - 更新WITS数据包构建逻辑以使用动态actcod值 - 优化代码格式和错误消息显示 - 移除不必要的空行和导入语句
MQTT Mock Service
Simulates a service that:
- Subscribes to the ingest topic (server -> broker)
- Writes received messages to a local file (JSONL)
- Writes received messages to TDengine (super table)
- Forwards messages to another topic for downstream subscribers
- Optionally sends ack messages
Also includes:
- A random data sender (every 3 seconds by default)
- A simple subscriber that prints incoming payloads
- A WITS TCP sender for the Java TCP receiver
Setup
python -m venv .venv
.\.venv\Scripts\activate
pip install -r requirements.txt
Run (service mode)
python mqtt_mock.py --config config.yaml --mode listen
Run (also publish test data)
python mqtt_mock.py --config config.yaml --mode both --interval 2
Run random sender (3s interval)
python mqtt_sender.py --config config.yaml --interval 3
Run subscriber
python mqtt_subscriber.py --config config.yaml
Run WITS sender
Send one generated WITS packet to wits.host/wits.port or fallback tms.server-ip/tms.server-port:
python wits_sender.py --config config.yaml
Send packets continuously every 2 seconds:
python wits_sender.py --config config.yaml --interval 2 --count 0
Send a raw packet from file:
python wits_sender.py --config config.yaml --source-file data/wits_sample.txt
Payload format (server -> broker)
{
"meta": {
"test_id": "550e8400e29b41d4a716446655440000",
"equipment_sn": "GJ-304-0088"
},
"data": {
"record_time": 1751964764000,
"wellid": "",
"stknum": 0,
"recid": 0,
"seqid": 0,
"actual_date": 0,
"actual_time": 0,
"actcod": 0,
"deptbitm": 0,
"deptbitv": 0,
"deptmeas": 0,
"deptvert": 0,
"blkpos": 0,
"ropa": 0,
"hkla": 0,
"hklx": 0,
"woba": 0,
"wobx": 0,
"torqa": 0,
"torqx": 0,
"rpma": 0,
"sppa": 0,
"chkp": 0,
"spm1": 0,
"spm2": 0,
"spm3": 0,
"tvolact": 0,
"tvolcact": 0,
"mfop": 0,
"mfoa": 0,
"mfia": 0,
"mdoa": 0,
"mdia": 0,
"mtoa": 0,
"mtia": 0,
"mcoa": 0,
"mcia": 0,
"stkc": 0,
"lagstks": 0,
"deptretm": 0,
"gasa": 0,
"space1": 0,
"space2": 0,
"space3": 0,
"space4": 0,
"space5": 0
}
}
Config
mqtt.*: MQTT broker and topic settingstms.device-code: default device code for generated datatms.server-ip: WITS target host fallbacktms.server-port: WITS target port fallbacktms.timeout: WITS socket timeout fallbackwits.host: optional explicit WITS target hostwits.port: optional explicit WITS target portwits.timeout: optional explicit WITS socket timeoutwits.source-file: optional default WITS packet file pathtdengine.url: e.g.jdbc:TAOS-RS://192.168.1.87:6041/tmstdengine.username: DB usertdengine.password: DB passwordtdengine.database: DB name (optional if URL already has/tms)tdengine.stable: defaultdrilling_realtime_st
Options
mqtt_mock.py:--mode--interval--count--data-filemqtt_sender.py:--interval--countmqtt_subscriber.py:--topicwits_sender.py:--host--port--timeout--source-file--interval--count
Description
Languages
Python
100%