Catch socket.gairerror
This commit is contained in:
parent
b8859717c5
commit
a921c3b88f
13
get_data.py
13
get_data.py
|
@ -3,6 +3,7 @@ Read Xiaomi LYWSD03MMC advertised packets and send them to MQTT
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from socket import gaierror
|
||||||
|
|
||||||
import bluetooth._bluetooth as bluez
|
import bluetooth._bluetooth as bluez
|
||||||
import paho.mqtt.publish as publish
|
import paho.mqtt.publish as publish
|
||||||
|
@ -37,7 +38,12 @@ def send_to_mqtt(data: dict):
|
||||||
publish.multiple(msgs, hostname=os.environ.get('MQTT_HOST', 'mqtt'))
|
publish.multiple(msgs, hostname=os.environ.get('MQTT_HOST', 'mqtt'))
|
||||||
|
|
||||||
|
|
||||||
def le_advertise_packet_handler(mac: str, adv_type: int, data: bytes, rssi: int):
|
def le_advertise_packet_handler(
|
||||||
|
mac: str,
|
||||||
|
adv_type: int, # pylint: disable=unused-argument
|
||||||
|
data: bytes,
|
||||||
|
rssi: int, # pylint: disable=unused-argument
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Handle new Xiaomi LYWSD03MMC BTLE advertise packet
|
Handle new Xiaomi LYWSD03MMC BTLE advertise packet
|
||||||
"""
|
"""
|
||||||
|
@ -54,7 +60,10 @@ def le_advertise_packet_handler(mac: str, adv_type: int, data: bytes, rssi: int)
|
||||||
'humidity': hum,
|
'humidity': hum,
|
||||||
'battery': batt,
|
'battery': batt,
|
||||||
}
|
}
|
||||||
send_to_mqtt(mqtt_data)
|
try:
|
||||||
|
send_to_mqtt(mqtt_data)
|
||||||
|
except gaierror as error:
|
||||||
|
print(f'[ERROR] {error}')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue