mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-04 23:04:09 +02:00
Correct mqtt @UlrichThiess
https://github.com/alexbelgium/hassio-addons/issues/1515
This commit is contained in:
@@ -27,12 +27,11 @@ settings_dict = dict(conf)
|
|||||||
mqtt_server = "%%mqtt_server%%"
|
mqtt_server = "%%mqtt_server%%"
|
||||||
mqtt_user = "%%mqtt_user%%"
|
mqtt_user = "%%mqtt_user%%"
|
||||||
mqtt_pass = "%%mqtt_pass%%"
|
mqtt_pass = "%%mqtt_pass%%"
|
||||||
mqtt_port = "%%mqtt_port%%"
|
mqtt_port = %%mqtt_port%%
|
||||||
mqtt_topic = 'birdnet'
|
mqtt_topic = 'birdnet'
|
||||||
|
|
||||||
bird_lookup_url_base = 'http://en.wikipedia.org/wiki/'
|
bird_lookup_url_base = 'http://en.wikipedia.org/wiki/'
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, rc, properties=None):
|
def on_connect(client, userdata, flags, rc ): #, properties=None):
|
||||||
""" Callback for when the client receives a CONNACK response from the server. """
|
""" Callback for when the client receives a CONNACK response from the server. """
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
log.info("Connected to MQTT Broker!")
|
log.info("Connected to MQTT Broker!")
|
||||||
@@ -50,9 +49,7 @@ def get_bird_code(scientific_name):
|
|||||||
|
|
||||||
return bird_dict.get(scientific_name)
|
return bird_dict.get(scientific_name)
|
||||||
|
|
||||||
def automatic_mqtt_publish(file, detections):
|
def automatic_mqtt_publish(file, detection, path):
|
||||||
path = ""
|
|
||||||
for detection in detections:
|
|
||||||
bird = {}
|
bird = {}
|
||||||
bird['Date'] = file.date
|
bird['Date'] = file.date
|
||||||
bird['Time'] = file.time
|
bird['Time'] = file.time
|
||||||
@@ -61,7 +58,7 @@ def automatic_mqtt_publish(file, detections):
|
|||||||
bird['Confidence'] = detection.confidence
|
bird['Confidence'] = detection.confidence
|
||||||
bird['SpeciesCode'] = get_bird_code(detection.scientific_name)
|
bird['SpeciesCode'] = get_bird_code(detection.scientific_name)
|
||||||
bird['ClipName'] = path
|
bird['ClipName'] = path
|
||||||
bird['url'] = bird_lookup_url_base + detection.scientific_name
|
bird['url'] = bird_lookup_url_base + detection.scientific_name.replace(' ', '_')
|
||||||
|
|
||||||
# Flickimage
|
# Flickimage
|
||||||
image_url = ""
|
image_url = ""
|
||||||
@@ -84,9 +81,11 @@ def automatic_mqtt_publish(file, detections):
|
|||||||
image_url = ""
|
image_url = ""
|
||||||
else:
|
else:
|
||||||
image_url = flickr_images[common_name]
|
image_url = flickr_images[common_name]
|
||||||
bird['Flickrimage'] = image_url
|
|
||||||
|
bird['FlickrImage'] = image_url
|
||||||
|
|
||||||
json_bird = json.dumps(bird)
|
json_bird = json.dumps(bird)
|
||||||
|
mqttc.reconnect()
|
||||||
mqttc.publish(mqtt_topic, json_bird, 1)
|
mqttc.publish(mqtt_topic, json_bird, 1)
|
||||||
log.info("Posted to MQTT: ok")
|
log.info("Posted to MQTT: ok")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user