1234567891011121314151617181920212223242526272829303132333435 |
- import paho.mqtt.client as mqtt
- import time
- import json
- client = mqtt.Client()
- client.connect(host='10.10.61.229', port=41883)
- def test_bg_log():
- """
- mqtt消息注释:
- {
- "1": "2024-12-12 01:01:21", # 发送时间
- "2": 6000, # 方向值
- "3": 6000, # 手油门值
- "4": 6000, # 脚油门值
- "5": 6000 # 刹车值
- }
- """
- data = {
- 1: '2024-12-12 01:01:21', # 发送时间
- 2: 6000, # 方向值
- 3: 6000, # 油门值
- 4: 6000, # 刹车值
- }
- results = client.publish('bg/log', json.dumps(data))
- result_code, message_id = results
- print(f"#result_code: {result_code}, #message_id: {message_id}")
- if __name__ == '__main__':
- # --- test ---
- while True:
- test_bg_log()
- time.sleep(10)
|