Skip to content

Commit

Permalink
Merge pull request #36 from drcrimzon/patch-1
Browse files Browse the repository at this point in the history
Add MQTT connection error handling
  • Loading branch information
blakeblackshear authored May 15, 2019
2 parents e791d66 + 2c2f004 commit 8c92489
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion detect_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ def main():
# connect to mqtt and setup last will
def on_connect(client, userdata, flags, rc):
print("On connect called")
if rc != 0:
if rc == 3:
print ("MQTT Server unavailable")
elif rc == 4:
print ("MQTT Bad username or password")
elif rc == 5:
print ("MQTT Not authorized")
else:
print ("Unable to connect to MQTT: Connection refused. Error code: " + str(rc))
# publish a message to signal that the service is running
client.publish(MQTT_TOPIC_PREFIX+'/available', 'online', retain=True)
client = mqtt.Client()
Expand Down Expand Up @@ -87,4 +96,4 @@ def imagestream(camera_name):
camera.join()

if __name__ == '__main__':
main()
main()

0 comments on commit 8c92489

Please sign in to comment.