12345678910111213141516171819202122232425262728293031 |
- import paho.mqtt.client as mqtt
- import time
- import json
- client = mqtt.Client()
- client.connect(host='192.168.131.23', port=41883)
- def test(topic="hs/vehicle/state"):
- data = {
- "address": "192.168.131.180", # 车辆ip
- "state": 2, # 车辆状态 1 离线 2 在线空闲 3 人工驾驶中 4 远程驾驶中 5 自动驾驶中
- "direction": 12, # 车头方向(场地坐标偏转角度)
- }
- return topic, client.publish(topic, json.dumps(data))
- # def test(topic="hs/pot/data"):
- # data = {
- # "address": "192.168.131.180", # 车辆ip
- # "state": 2, # 车辆状态 1 离线 2 在线空闲 3 人工驾驶中 4 远程驾驶中 5 自动驾驶中
- # "direction": 12, # 车头方向(场地坐标偏转角度)
- # }
- # return topic, client.publish(topic, json.dumps(data))
- if __name__ == '__main__':
- # --- test ---
- while True:
- topic, results = test()
- result_code, message_id = results
- print(f"#topic: {topic}, #result_code: {result_code}, #message_id: {message_id}")
- time.sleep(3)
|