python用paho写了client端,可是连接不到apollo,可能有什么原因?
python代码
import os
import os.path
import time
import paho.mqtt.client as mqtt
import csv
import json
def ParsFile(filename):
file_object = open(filename)
try:
if os.path.splitext(filename)[1]==".txt":
for line in file_object:
print(line)
client.publish(topic="message", payload=line)
time.sleep(1)
else:
with open(filename) as csvfile:
reader = csv.DictReader(csvfile)
line = {}
for row in reader:
#print(row)
line['Time'] = row['Time']
line['Sno'] = row['Sno']
line['UpRate'] = row['UpRate']
line['Lng'] = row['Lng']
line['Lat'] = row['Lat']
line['Alt'] = row['Alt']
line['Nsize'] = row['Nsize']
line['Lac'] = row['Lac']
line['CID'] = row['CID']
line['RSRP0'] = row['RSRP0']
line['SINR0'] = row['SINR0']
line['RSRQ0'] = row['RSRQ0']
line['RSSI0'] = row['RSSI0']
Nsize = int(line['Nsize'])
for i in range(1, Nsize+1):
line['RSRP'+str(i)] = row['RSRP'+str(i)]
print(line)
client.publish(topic="message", payload=json.dumps(line))
line.clear()
time.sleep(1)
finally:
file_object.close()
# this folder is custom
rootdir="C:\VLAB-1"
def WaikFiles(rootdir, client):
for parent,dirnames,filenames in os.walk(rootdir):
for filename in filenames:
print("parent folder is:" + parent)
print("filename with full path:"+ os.path.join(parent,filename))
ParsFile(os.path.join(parent,filename))
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
print("Connected with result code " + str(rc))
if __name__ == "__main__":
client = mqtt.Client()
client.username_pw_set(username="admin",password="password")
client.on_connect = on_connect
client.connect("127.0.0.1", 61613, 60)
client.loop_start()
#while True:
WaikFiles(rootdir, client)
#while True:
# time.sleep(1)
# client.publish(topic="message", payload="hello")
apollo偶尔报错
没有connector
可是啊,在另一台pc上是没问题有connector :(
提前谢过!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论