Unable to control raspberry pi camera remotely using MQTT

谁说我不能喝 提交于 2020-03-06 11:06:29

问题


I am trying to start and stop the recording of camera attached to a Raspberry Pi Zero W (client) using MQTT. Below is the specific part of the code which I am trying to use to achieve this:

    continueRecording = 1
    def shopRecording():
        global shop_record_flag_start, camera, continueRecording
        print("Starting Recording")
        while 1:
            print(shop_record_flag_start)
            with picamera.PiCamera() as camera:
                camera.resolution = (640, 480)
                camera.framerate = 20
                camera.start_recording("/home/pi/camera-recording/shop/shoprecording.h264")
                print("Recording")
                time.sleep(0.5)
                while continueRecording == 1:
                    camera.wait_recording(.01)
                    if not shop_record_flag_start:
                        print("Stop Recording")
                        camera.stop_recording()
                        continueRecording = 0
  def on_message(client, userdata, msg):
    global message_topic, message
    global, shop_record_flag
    global continueRecording
    message = str(msg.payload.decode("utf-8"))
    if message_start == "shop":
        shopRecording()
    elif message="OK":
        shop_record_flag_start = False

I am able to send the messages to Pi Zero using MQTT. However, when I am sending the start command the the camera starts but immediately stops. More specifically the the While loop (continueRecording ==1) is not getting executed as none of the print statements under it are displayed. I am unable to figure out where I am going wrong. Please note that no errors are displayed for the rest of the code and hence I have not posted it here. Thanks for your time and help in advance.

来源:https://stackoverflow.com/questions/60515693/unable-to-control-raspberry-pi-camera-remotely-using-mqtt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!