问题
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