rs485串口服务器转以太网设置说明(USBRS485串口UDP转MQTT网络通信协议对接方案)
rs485串口服务器转以太网设置说明(USBRS485串口UDP转MQTT网络通信协议对接方案)client = mqtt.Client()print(‘local IP :’ myaddr)myaddr = socket.gethostbyname(myname)serverSocket = socket.socket(socket.AF_INET socket.SOCK_DGRAM)serverSocket.bind((myaddr UDPserverPort))
try:
# 获取本机名称
myname = socket.getfqdn(socket.gethostname())
# 获取本机ip
myaddr = socket.gethostbyname(myname)
serverSocket = socket.socket(socket.AF_INET socket.SOCK_DGRAM)
serverSocket.bind((myaddr UDPserverPort))
print(‘local IP :’ myaddr)
client = mqtt.Client()
#client.username_pw_set(‘MQTT’ ‘MQTTPW’)
client.on_connect = on_connect
client.on_message = on_message
client.connect(MQTThost MQTTport 600) # 600为keepalive的时间间隔
except Exception as e:
print(e)