- 新增WitsConfig数据类用于WITS配置管理 - 在AppConfig中集成wits配置选项 - 重命名dependencies.py为config.py并重构配置加载逻辑 - 移除db/config.py文件中的TDengine配置相关代码 - 创建新的model.py文件定义MqttConfig、TmsConfig和TdengineConfig模型 - 更新MQTT模块导入路径从config.dependencies到config.config - 添加WITS发送器脚本wits_sender.py实现TCP数据包发送 - 在README.md中添加WITS发送器使用说明和配置选项 - 添加WITS样本数据文件data/wits_sample.txt - 添加requirements.md文档说明项目需求
137 lines
3.2 KiB
Markdown
137 lines
3.2 KiB
Markdown
# 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 settings
|
|
- `tms.device-code`: default device code for generated data
|
|
- `tms.server-ip`: WITS target host fallback
|
|
- `tms.server-port`: WITS target port fallback
|
|
- `tms.timeout`: WITS socket timeout fallback
|
|
- `wits.host`: optional explicit WITS target host
|
|
- `wits.port`: optional explicit WITS target port
|
|
- `wits.timeout`: optional explicit WITS socket timeout
|
|
- `wits.source-file`: optional default WITS packet file path
|
|
- `tdengine.url`: e.g. `jdbc:TAOS-RS://192.168.1.87:6041/tms`
|
|
- `tdengine.username`: DB user
|
|
- `tdengine.password`: DB password
|
|
- `tdengine.database`: DB name (optional if URL already has `/tms`)
|
|
- `tdengine.stable`: default `drilling_realtime_st`
|
|
|
|
## Options
|
|
- `mqtt_mock.py`: `--mode` `--interval` `--count` `--data-file`
|
|
- `mqtt_sender.py`: `--interval` `--count`
|
|
- `mqtt_subscriber.py`: `--topic`
|
|
- `wits_sender.py`: `--host` `--port` `--timeout` `--source-file` `--interval` `--count`
|