Raspberry Pi server collecting data from a DHT22 sensor(humidity and temperature) and streaming video. Can handle up to 100 connections, but due to hardware limitations can only handle 5 simultaneous streams at 1080p 24fps. Stream quality can be dropped to increase viewer count. To prevent blocking the server implements coroutines using Gevent instead of a multithreading solution.
The raspberry pi runs a python script regularly polling the sensor for information. This information is inserted into a SQLite database. When a connection is established the Flask server sends a query to the database. If no specific time period is requested, Flask will use a predetermined default. This is sent through a query string in the URL. There are also a number of interface options for quickly selecting a time period. click here for a demo.
The server also has a camera attached and upon receiving a request, it will start up the camera and create a video feed using motion-jpeg. This raised issues of blocking. After trying both multithreading and coroutines I landed on using coroutines for it's superior performance. The Gevent event loop solved the blocking issues and allowed to have up to 5 viewers at the same time without any slowdown. click here for a demo of concurrency.
- Python 3.7
- Flask
- uWSGI
- NGINX
- SQLite3
- Skeleton (CSS Boostrap)
- streaming live video feed
- streaming live sensor readings
- plotting historic temperature & humidity
- Google Charts
- jQuery for datetime widget
- Raspberry Pi 3b +
- DHT22 AM2302 Sensor
- Raspberry Pi Camera Module v2