首先,对不起我的英语不好
我试图在Linux下运行的python 2.7中创建一个MQTT程序。我是不程序员,而是汽车修理工。所以对我来说这很简单:)这只是一个爱好
目前我正在使用适用于Python的PAHO-MQTT 1.2.3软件包。我遇到了一个恼人的错误,我无法找到我做错的事情。
以下是一些代码
def on_connect(client, userdata, flags, rc):
printLine()
printMsg("Connected to server")
printMsg("Address:\t ] %s" % (sServer))
printMsg("Port:\t\t ] %s" % (sPort))
printMsg("Username:\t ] %s" % (sUsername))
#client.subscribe("order/"+sLocation+"/mem")
#client.subscribe("order/"+sLocation+"/in")
printLine()
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.username_pw_set(sUsername,sPassword)
printMsg("marker 1")
time.sleep( 0.3 )
client.connect(sServer, sPort, 60)
time.sleep( 0.3 )
printMsg("marker 2")
client.loop_start()
time.sleep( 0.3 )
printMsg("marker 3")
7 out 10 is ok(print @ linux terminal)
[========================================
[ Booting.....
[ marker 1
[ marker 2
[========================================
[ Connected to server
[ Address: ] *******
[ Port: ] 8883
[ Username: ] *********
[========================================
[ marker 3
[ send
3 out 10我在linux终端中收到下一个错误
[========================================
[ Booting.....
[ marker 1
[ marker 2
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2630, in _thread_main
self.loop_forever(retry_first_connection=True)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1410, in loop_forever
rc = self.loop(timeout, max_packets)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 926, in loop
rc = self.loop_read(max_packets)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1209, in loop_read
rc = self._packet_read()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1802, in _packet_read
rc = self._packet_handle()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2278, in _packet_handle
return self._handle_publish()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2430, in _handle_publish
(topic, packet) = struct.unpack(pack_format, packet)
error: bad char in struct format
[ marker 3
[ send
有人能指出我正确的方向来解决我的错误。