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

updated code

parent 2b71d952
import paho.mqtt.client as mqtt
from picamera import PiCamera
from time import sleep
camera = PiCamera()
import picamera
import time
import io
import base64
def on_connect(client, userdata, flags, rc):
if rc == 0:
......@@ -12,13 +12,18 @@ def on_connect(client, userdata, flags, rc):
print(f"Connecting to MQTT broker failed with code {rc}")
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()
#print(f"{msg.topic} {msg.payload}")
if str(msg.payload.decode("utf-8")) == 'TAKE_PHOTO':
print('taking photo!')
photo = open('/tmp/photo.jpg', 'wb')
with picamera.PiCamera() as camera:
camera.resolution = (640, 480)
camera.start_preview()
time.sleep(2)
camera.capture(photo)
photo.close()
print('took photo!')
print(photo.read())
client = mqtt.Client()
client.on_connect = on_connect
......
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