Robert Cudmore    archive    tags    search    software


Raspberry Pi video controller

This is a video server running on a raspberry Pi Linux computer. It provides a web interface to stream and record video.

What it does

Interface

How it works

The server is pure python running on the Pi. It uses the web framework Flask. Once the web page is loaded by a client browser(you), any objects within the webpage can be updated in real-time using flask-socket-io. This can be done without refreshing the entire webpage. The layout and interface objects are using Bootstrap.

Required Hardware

Installation:

Running the server

sudo python iosserver.py

This will tell you the IP adress you use to login to the server.

Connecting to the server

Just point any browser to the server address.

http://192.168.1.60:5000

Extra Details

The internet of things

Python code running on any other internet-connected device can ‘inject’ values into the iosserver and they will show up in real-time inside all client browsers. Here is example code on another Pi that has its own temperature and humidity sensor.

# send to iosserver
import requests
try:
	payload = {'timestamp': thisTimestamp, 'insideTemp': temp, 'insideHum': hum, 'outsideTemp' : outsidetemp, 'outsideHum' : outsidehumidity}
	r=requests.get('http://192.168.1.60:5000/_add_numbers', params=payload)
	print 'sent to 192.168.1.60 !!!'
	print payload
except:
	print '-------- error sending to iosserver ---------'

The iosserver receives this GET request with a little function decorator.

@app.route('/_add_numbers')
def add_numbers():
    timestamp = request.args.get('timestamp', '') # defaults to ''
    insideTemp = request.args.get('insideTemp', '')
    insideHum = request.args.get('insideHum', '')
    outsideTemp = request.args.get('outsideTemp', '')
    outsideHum = request.args.get('outsideHum', '')
    print 'timestamp=', timestamp
    # myVideo is another python class that handles all runtime
    # it is not detailed in this example
    myVideo.insideTemp = timestamp + ' ' + insideTemp
    myVideo.insideHum = insideHum
    myVideo.outsideTemp = outsideTemp
    myVideo.outsideHum = outsideHum
    print 'add_nummbers() received ', timestamp, ' ', insideTemp, ' ', insideHum, ' ', outsideTemp, ' ', outsideHum
    return ''

There are a few more steps including some javascript and html. This is not a Flask or Socket-IO tutorial. Have a look a socket-io for Flask.

Tags: raspberry pi, data acquisition

©2020. Robert Cudmore.