Skip to content

Commit 5c449cc

Browse files
committed
Handle missing active stream on picam startup
1 parent fb1ee08 commit 5c449cc

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/ac_training_lab/picam/device.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
CAMERA_HFLIP,
99
CAMERA_VFLIP,
1010
LAMBDA_FUNCTION_URL,
11+
LAMBDA_TOKEN,
1112
PRIVACY_STATUS,
1213
WORKFLOW_NAME,
1314
)
@@ -124,7 +125,11 @@ def call_lambda(action, CAM_NAME, WORKFLOW_NAME, privacy_status="private"):
124125
print(f"Sending to Lambda: {payload}")
125126
try:
126127

127-
response = requests.post(LAMBDA_FUNCTION_URL, json=payload)
128+
response = requests.post(
129+
LAMBDA_FUNCTION_URL,
130+
json=payload,
131+
headers={"Authorization": f"Bearer {LAMBDA_TOKEN}"},
132+
)
128133
print(f"Status code: {response.status_code}")
129134
print(f"Response text: {response.text}")
130135
response.raise_for_status()
@@ -151,7 +156,13 @@ def call_lambda(action, CAM_NAME, WORKFLOW_NAME, privacy_status="private"):
151156

152157
if __name__ == "__main__":
153158
# End previous broadcast and start a new one via Lambda
154-
call_lambda("end", CAM_NAME, WORKFLOW_NAME)
159+
try:
160+
call_lambda("end", CAM_NAME, WORKFLOW_NAME)
161+
except RuntimeError as e:
162+
if "no active stream" not in str(e):
163+
raise
164+
print("No active stream to end; continuing")
165+
155166
raw_body = call_lambda(
156167
"create", CAM_NAME, WORKFLOW_NAME, privacy_status=PRIVACY_STATUS
157168
)

0 commit comments

Comments
 (0)