This project will show how we can use the IoT to create cheap and smart remote classrooms for rural areas using Raspberry Pi and its camera module. If a teacher teaches in a distant city, that session can be streamed live to rural areas. By such applications, children from rural areas can get quality education from a remote place by paying a small fee.
Such applications are already available in the market, but they are costly, so we need a cheap solution that those childrens’ families can afford.
Required tools and libraries
Tools
- Python IDE 3.0
- VNC viewer
- Any Web Browser for client
Python libraries
- Socketserver – link
- Picamera – can be installed by following commands in terminal
$ sudo apt-get install python-picamera python3-picamera
Technical Insights
Our device can be implanted anywhere, and it will record and stream live on its address. This application works on the client-server model using TCP/HTTP as a communications protocol. Therefore, the stream can be accessed from anywhere (If the firewall allows) on a web browser.
We will use Raspberry Pi for processing and as a server which will stream the incoming media data from the camera on a particular IP address of the Raspberry Pi. For internet connectivity, we can use Wi-Fi or any internet modem.
We will write a Python script that will handle all the technical processes such as enabling networking and setting the Raspberry Pi as a media streaming server.
Block Diagram / Algorithm
Raspberry pi is directly connected to the camera model using its cable connector, and the modem provides the raspberry pi a valid IP address with internet connectivity. A TCP/HTTP connection is sharing all the media data between the Raspberry Pi and the modem.
Clients access the Raspberry Pi (streaming server) using internet-enabled devices such as cellphones and laptops. Raspberry Pi has a good web browser because the stream is an HTTP stream.
How it works
When all the connections are in place and working, we start our script which will stream on the IP address of the Raspberry Pi. To understand this, follow the points giving below.
- The camera starts to record and save pictures in an “mjpg” file when the script is on.
- The camera is continually replacing the stream inside only one file.
- A server is created inside the system using a function, and that image file is passed inside that function. The server also opens a port in the system so clients can access the server through the network.
- An HTML code/page is written to handle the image file on web pages. This HTML page displays that image and keeps refreshing to show that changes in images can be seen as videos.
- Now, if a client gets to connect to the server, it is welcomed with that HTML page, and thus, the client can see the image as a video.
- If multiple clients are connected, then multithreading is used, and a fresh new page is opened for each client.
- When a client gets disconnected, the stream for that particular client is stopped.
- The server always listens for the client on the port which it opened.
Understanding the source code
Let’s understand the source code and its essential functions.
There are three handler functions, one primary function, and an HTML page template in our code.
HTML page template
The title tag shows the main title on the page when a client is connected.
<title>picamera MJPEG streaming demo</title>
The tag <h1> is a heading in our main page.
<h1>PiCamera MJPEG Streaming Demo</h1>
“<img src” line handles the streaming file and displays inside a 640 X 460-pixel size window on the main page.
<img src=”stream.mjpg” width=”640″ height=”480″ />
StreamingOutput(object)
This function creates enough data buffer to save the stream file. It also provides a new frame on client connection.
return self.buffer.write(buf)
StreamingHandler(server.BaseHTTPRequestHandler)
This function handles the clients on HTTP requests. It writes the main header with the following information.
If a client is trying to access the server by its address only, it shows the complete page to the client.
self.send_header(‘Location’, ‘/index.html’)
If the index.html page is accessed, it writes the page with the content and displays what was written in the page part.
It also specifies the content type on the main page so clients (browsers) can understand the type of the content and act accordingly.
self.send_header(‘Content-Type’, ‘multipart/x-mixed-replace; boundary=FRAME’)
This stream is a frame-type stream with multipart (multimedia) content.
StreamingServer(socketserver.ThreadingMixIn, server.HTTPServer)
This server function deals with the networking part and creates a new socket for each client. It also enables multiple client connections by using multithreading.
Main Function
The main function script is the code for recording the stream and passing it to the above functions.
camera.start_recording(output, format=’mjpeg’)
The camera starts recording and writes it to the mjpeg format file.
The address is the object which passes the server port and the IP address which means that it will support the availability of the server on every IP address the system is assigned to.
address = (”, 8000)
The server is binding itself to the object address and the content, which is the “StreamingHandler” function
server = StreamingServer(address, StreamingHandler)
This line tells the server to keep serving the service until the script is not terminated.
server.serve_forever()
So this is how we can find a cheap and easy solution for smart remote classrooms for rural areas.
You may also like:
Filed Under: Electronic Projects