feat(wits): 添加WITS TCP发送功能和配置重构
- 新增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文档说明项目需求
This commit is contained in:
47
README.md
47
README.md
@@ -1,4 +1,4 @@
|
||||
# MQTT Mock Service
|
||||
# MQTT Mock Service
|
||||
|
||||
Simulates a service that:
|
||||
- Subscribes to the ingest topic (server -> broker)
|
||||
@@ -10,6 +10,7 @@ Simulates a service that:
|
||||
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
|
||||
```
|
||||
@@ -23,11 +24,6 @@ pip install -r requirements.txt
|
||||
python mqtt_mock.py --config config.yaml --mode listen
|
||||
```
|
||||
|
||||
When TDengine config exists in `config.yaml`, each message on `pub-topic` is inserted into:
|
||||
- Super table: `drilling_realtime_st`
|
||||
- Sub table: auto-generated as `drilling_realtime_<device_code>`
|
||||
- Tag value: fixed `device_code` from config (`GJ-304-0088`)
|
||||
|
||||
## Run (also publish test data)
|
||||
```
|
||||
python mqtt_mock.py --config config.yaml --mode both --interval 2
|
||||
@@ -43,6 +39,22 @@ python mqtt_sender.py --config config.yaml --interval 3
|
||||
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)
|
||||
```
|
||||
{
|
||||
@@ -102,12 +114,15 @@ python mqtt_subscriber.py --config config.yaml
|
||||
```
|
||||
|
||||
## Config
|
||||
- `pub-topic`: ingest topic from server
|
||||
- `sub-topic`: forward topic for other services to subscribe
|
||||
- `ack-topic`: optional ack topic
|
||||
- `data-file`: local append-only file (JSON Lines)
|
||||
- `equipment-sn`: default equipment_sn for simulated payloads
|
||||
- `test-id`: default test_id for simulated payloads
|
||||
- `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
|
||||
@@ -115,7 +130,7 @@ python mqtt_subscriber.py --config config.yaml
|
||||
- `tdengine.stable`: default `drilling_realtime_st`
|
||||
|
||||
## Options
|
||||
- `--mode`: publish | listen | both
|
||||
- `--interval`: publish interval seconds
|
||||
- `--count`: publish count (0 = forever)
|
||||
- `--data-file`: override data-file in config
|
||||
- `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`
|
||||
|
||||
Reference in New Issue
Block a user