fix: runtime errors
This commit is contained in:
parent
d5c7d62507
commit
c37017d291
@ -1,7 +1,9 @@
|
||||
import sys
|
||||
import json
|
||||
import uuid
|
||||
import asyncio
|
||||
import datetime
|
||||
import traceback
|
||||
|
||||
import cv2
|
||||
import requests
|
||||
@ -76,7 +78,7 @@ def on_message_received(topic, payload, dup, qos, retain, **kwargs):
|
||||
|
||||
|
||||
def parse_led_payload(payload):
|
||||
data = json.loads(payload)
|
||||
data = json.loads(payload.decode())
|
||||
if data.get("faces"):
|
||||
led_control(True)
|
||||
else:
|
||||
@ -91,7 +93,7 @@ def led_control(light):
|
||||
|
||||
|
||||
def parse_s3_url_payload(payload):
|
||||
data = json.dumps(payload)
|
||||
data = json.loads(payload.decode())
|
||||
|
||||
put_presigned_s3_url(data["url"], take_picture())
|
||||
|
||||
@ -136,6 +138,7 @@ async def main():
|
||||
)
|
||||
|
||||
subscribe_result = subscribe_future.result()
|
||||
print(subscribe_result)
|
||||
print(f"Subscribed to {LED_TOPIC}")
|
||||
|
||||
subscribe_future, packet_id = mqtt_connection.subscribe(
|
||||
@ -145,7 +148,8 @@ async def main():
|
||||
)
|
||||
|
||||
subscribe_result = subscribe_future.result()
|
||||
print(f"Subscribed to {LED_TOPIC}")
|
||||
print(subscribe_result)
|
||||
print(f"Subscribed to {S3_URL_TOPIC}")
|
||||
|
||||
while True:
|
||||
command = input("> ")
|
||||
@ -154,17 +158,28 @@ async def main():
|
||||
filename = datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d-%H-%M-%S") + "." + FORMAT
|
||||
publish_future, packet_id = mqtt_connection.publish(
|
||||
topic=S3_UPLOAD_TOPIC,
|
||||
qos=1,
|
||||
payload=json.dumps({ "filename": filename })
|
||||
payload=json.dumps({ "filename": filename }),
|
||||
qos=mqtt.QoS.AT_LEAST_ONCE
|
||||
)
|
||||
publish_result = publish_future.result()
|
||||
print(publish_result)
|
||||
print(f"Upload request {filename} sent!")
|
||||
elif command == "q":
|
||||
break
|
||||
|
||||
|
||||
def handler(loop, context):
|
||||
e = context['exception']
|
||||
print(*traceback.format_exception(None, e, e.__traceback__), file=sys.stderr, flush=True)
|
||||
if not DEBUG:
|
||||
GPIO.cleanup()
|
||||
|
||||
loop.stop()
|
||||
|
||||
# run
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.set_exception_handler(lambda loop, context: [print(context['message']), GPIO.cleanup()])
|
||||
loop.set_exception_handler(handler)
|
||||
|
||||
loop.create_task(main())
|
||||
|
||||
loop.run_forever()
|
||||
loop.run_forever()
|
||||
|
Loading…
x
Reference in New Issue
Block a user