Commit de264ecf authored by Daniel Kolibár's avatar Daniel Kolibár
Browse files


parent 36da1886
......@@ -7,11 +7,14 @@ import base64
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected successfully to MQTT broker")
print(f"Connecting to MQTT broker failed with code {rc}")
def on_message(client, userdata, msg):
def on_message(client, userdata, msg):
messagedecoded = str(msg.payload.decode("utf-8"))
x = json.loads(messagedecoded, object_hook=lambda d: SimpleNamespace(**d))
if str(msg.payload.decode("utf-8")) == 'TAKE_PHOTO':
print('taking photo!')
photo = io.BytesIO()
......@@ -22,8 +25,8 @@ def on_message(client, userdata, msg):
camera.capture(photo, 'jpeg')
print('took photo!')
base64_bytes = base64.b64encode(photo.getvalue())
base64_message = base64_bytes.decode('ascii')
client.publish('birdie/tx', payload=base64_message, qos=0, retain=False)
base64_message = base64_bytes.decode('ascii')
client.publish('birdie/rxtx/from/raspberry', payload=base64_message, qos=0, retain=False)
def on_publish(client,userdata,result):
print("published", result)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment