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

updated code

parent 508598b6
# test_connect.py
import paho.mqtt.client as mqtt
import paho.mqtt.client as mqtt
from picamera import PiCamera
from time import sleep
camera = PiCamera()
# The callback function. It will be triggered when trying to connect to the MQTT broker
# client is the client instance connected this time
# userdata is users' information, usually empty. If it is needed, you can set it through user_data_set function.
# flags save the dictionary of broker response flag.
# rc is the response code.
# Generally, we only need to pay attention to whether the response code is 0.
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected successfully to MQTT broker")
client.subscribe("birdie/rxtx")
client.subscribe("birdie/rxtx")
else:
print(f"Connecting to MQTT broker failed with code {rc}")
# the callback function, it will be triggered when receiving messages
def on_message(client, userdata, msg):
print(f"{msg.topic} {msg.payload}")
if msq.payload == 'TAKE_PHOTO':
camera.start_preview()
sleep(5)
camera.capture('/home/pi/Desktop/image.jpg')
camera.stop_preview()
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("roker.emqx.io"", 1883, 60)
client.connect("broker.hivemq.com", 1883, 60)
client.loop_forever()
\ No newline at end of file
Markdown is supported
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