Python wrote the client side in paho, but what might be the reason why you can't connect to apollo,?

python Code

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:
                    -sharpprint(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()
    -sharp 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))

 -sharp 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()

    -sharpwhile True:
    WaikFiles(rootdir, client)

    -sharpwhile True:
    -sharp    time.sleep(1)
    -sharp   client.publish(topic="message", payload="hello")

apollo occasionally reports an error

clipboard.png

connector

clipboard.png

but, on the other pc, there is no problem. There is connector: (

.

Thank you in advance!

Mar.05,2021
Menu