Okay, here are my scripts:
- The script is for automatic video recording when the Pi starts. The name file is associated with the time so that the files do not overwrite. The time is only 10s for testing. At the end it is something like 3h, but this doesn`t matter at the moment.
from picamera import PiCamera
from time import sleep
import datetime
dateipfad = "/home/pi"
dateiname = datetime.datetime.now().strftime('%Y.%m.%d-%H%M')
videodatei = f"{dateiname}.h264"
print(videodatei)
camera = PiCamera()
camera.start_preview()
camera.start_recording(videodatei)
sleep(10)
camera.stop_recording()
camera.stop_preview()
- Then after getting the connection in Node-Red, I took this script for testing. Here you can always see that the two values (in this case X coordinate: 3 and Y: 10) are constantly transmitted every second in the payload.
import paho.mqtt.client as mqtt
def on_connect (client, userdata, flags, rc):
print("connected with result code" + str(rc))
client.subscribe("positions/#")
def on_message(client, userdata, msg):
print(msg.payload)
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("localhost", 1883, 10)
client.loop_forever()
Is it better to load the coordinates in different payloads so that you can distinguish them?
Does the payload actually overwrite itself, meaning that only the later value is still there? or can both values be in the payload?
At the moment node-red is like that:
So now I've tried the script above. Not even a video recording is started here
Here is the first try.
from picamera import PiCamera
from time import sleep
import datetime
import paho.mqtt.client as mqtt
dateipfad = "/home/pi"
dateiname = datetime.datetime.now().strftime('%Y.%m.%d-%H%M')
videodatei = f"{dateiname}.h264"
print(videodatei)
camera = PiCamera()
def on_connect (client, userdata, flags, rc):
print("connected with result code" + str(rc))
client.subscribe("positions/#")
def on_message(client, userdata, msg):
global camera
global videodatei
print(msg.payload)
camera.annotate_text = str(msg.payload)
camera.start_preview()
camera.start_recording(videodatei)
sleep(15)
camera.stop_recording()
camera.stop_preview()
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("localhost", 1883, 10)
As the above is an example just to test if it is working, I think there might be some more logic needed. Suppose the recording is already ongoing and you receive a new message (with updated text). What should happen? Maybe the text gets updated? Should the recording stop and then restart?To be able to check if the recording is already ongoing some more stuff needs to be added. But try the above example first so we can verify if that part works or not
The updated text (X/Y-coordinates) should be constantly updated in the video
I am happy for any help!
We want to test it tomorrow. I think today will be a long night.