问题描述
我通过 paho 库发布和订阅我能够连接和发送和接收 mqtt 消息,但是当我从代理(rabbitmq)向我的设备发送消息时,它有时会给我一个错误:
您会在下面找到错误日志,我已经搜索了解决方案,但没有成功 =/
freqTRmessage = "JJ"
def subscribe(client: mqtt_client):
def on_message(client,userdata,msg):
#variable
global TIOtvariable
global RSvariable
global RSSvariable
global update_time
global bat_cons
global freqTRmessage
#print message received
print("\n message received = ",str(msg.payload.decode("utf-8")))
#technology change
if str(msg.payload.decode("utf-8")) == "LTE-M" and msg.topic == topic_modif:
print("\n Update requested : TECHNOLOGIE_IOT ==> RSLE")
config_M1_MODE()
elif str(msg.payload.decode("utf-8")) == "2G" and msg.topic == topic_modif:
print("\n Update requested : TECHNOLOGIE_IOT ==> RS2G")
config_GSM_MODE()
elif str(msg.payload.decode("utf-8")) == "nb-iot" and msg.topic == topic_modif:
print("\n Update requested : TECHNOLOGIE_IOT ==> RSNB_IOT")
config_NB1_MODE()
#CAS_USAGE
if str(msg.payload.decode("utf-8")) == "MM" and msg.topic == topic_modif:
print("\n Update requested : 1 uplink messages/day")
update_time_telemetry = 30
update_time_battery = 0
freqTRmessage = "MM"
elif str(msg.payload.decode("utf-8")) == "JJ" and msg.topic == topic_modif:
print("\n Update requested : 3 uplink messages/day")
update_time_telemetry = 20
update_time_battery = 2
freqTRmessage = "JJ"
elif str(msg.payload.decode("utf-8")) == "alerte" and msg.topic == topic_modif:
print("\n Update requested : battery consumption = 12% ")
bat_cons=12
elif str(msg.payload.decode("utf-8")) == "100" and msg.topic == topic_modif:
print("\n Update requested : battery consumption = 100% ")
bat_cons=100
client.subscribe([(topic_service,1),(topic_telemetry,(topic_diagnostic,(topic_modif,1)])
client.on_message = on_message
client.on_log = on_log
Caught exception in on_message: [Errno 9] Bad file descriptor
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py",line 917,in _bootstrap_inner
self.run()
File "/usr/lib/python3.7/threading.py",line 865,in run
self._target(*self._args,**self._kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py",line 3452,in _thread_main
self.loop_forever(retry_first_connection=True)
File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py",line 1779,in loop_forever
rc = self.loop(timeout,max_packets)
File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py",line 1181,in loop
rc = self.loop_read(max_packets)
File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py",line 1572,in loop_read
rc = self._packet_read()
File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py",line 2310,in _packet_read
rc = self._packet_handle()
File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py",line 2936,in _packet_handle
return self._handle_publish()
File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py",line 3216,in _handle_publish
self._handle_on_message(message)
File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py",line 3444,in _handle_on_message
self.on_message(self,self._userdata,message)
File "Demo.py",line 168,in on_message
config_GSM_MODE()
File "Demo.py",line 28,in config_GSM_MODE
node.setMode(node.GSM_MODE)
File "/usr/local/lib/python3.7/dist-packages/sixfab_cellulariot-1.2.0-py3.7.egg/cellulariot/cellulariot.py",line 310,in setMode
self.sendATComm("AT+QCFG=\"nwscanseq\",01,1","OK\r\n")
File "/usr/local/lib/python3.7/dist-packages/sixfab_cellulariot-1.2.0-py3.7.egg/cellulariot/cellulariot.py",line 212,in sendATComm
while(ser.inWaiting()):
File "/home/pi/.local/lib/python3.7/site-packages/serial/serialutil.py",line 594,in inWaiting
return self.in_waiting
File "/home/pi/.local/lib/python3.7/site-packages/serial/serialposix.py",line 549,in in_waiting
s = fcntl.ioctl(self.fd,TIOCINQ,TIOCM_zero_str)
OSError: [Errno 9] Bad file descriptor
node = cellulariot.CellularIoT()
node.setupGPIO()
node.disable()
sleep(1)
node.enable()
sleep(1)
node.powerUp()
node.setMode(node.GSM_MODE)
for i in range(1,7):
sleep(10)
Cellulariot 是来自 Sixfab 的图书馆,事实上我向我的设备发送了一条消息以更改网络模式,有时没有问题,有时在我的设备上收到消息时会出现此问题
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)