Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add code to enable streaming over https using self signed certificate #731

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/examples/web_streaming.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@

# this can run either as http or https
# to run as https using self signed certificates:
# create keyfile and certfile from command line using openssl:
# openssl req -nodes -new -x509 -keyout mykey.pem -out mycert.pem
# run this program with '--ssl' command line argument

import io
import picamera
import logging
import socketserver
import ssl,sys
from threading import Condition
from http import server

Expand Down Expand Up @@ -83,6 +91,15 @@ class StreamingServer(socketserver.ThreadingMixIn, server.HTTPServer):
try:
address = ('', 8000)
server = StreamingServer(address, StreamingHandler)
if '--ssl' in ' '.join(sys.argv):
server.socket = ssl.wrap_socket(
server.socket,
keyfile='mykey.pem',
certfile = 'mycert.pem',
server_side=True)
print('starting https')
else:
print('starting http')
server.serve_forever()
finally:
camera.stop_recording()