Raspberry Pi Baby Monitor project

Raspberry Pi Baby Monitor is a University project I have completed together with Nikolai Sannikov and Katherine Griffin for Operation Systems CS370 class. Everyone has been given tasks and were working as a team. Instructor is Shrideep Pallickara. GTAs: Regina Basnet and Nikhila Chireddy.

Hope you will find it interesting, it might also help save time on research for your own projects needs.

What we will need is the Raspberry Pi version 3, RaspiCam, Motion Sensor and all other associated components and wiring necessary for performance.


Baby monitor would be effective help to the parents or babysitter to continue perform household activity while baby is sleeping, get notified when child is awake and have the ability to monitor the child’s state in the same premises remotely. In order to implement the functionality, we will need to provide the live feed and the notification capability.
The team was given the Raspberry Pi project for CS370 Operating Systems class and to satisfy the agenda requirements and functionality we have made (1) the Raspberry Pi the key enabler for the project, and (2e) involved at least 3 components: Raspberry Pi and 2 sensors. One sensor is the PiCam, and second is the Infrared Motion Detection sensor.

Problem characterization

Project implementation success requires all components to work as a whole and complete product and in order to do that we will need to connect 5 main pieces together: hardware, kernel, software, user and the object. The Figure 1 below illustrates the conceptual workflow of the project for its full operation. The hardware is the Raspberry Pi version 3, RaspiCam, Motion Sensor and all other associated components and wiring necessary for performance.

Figure 1. Main components

There are the key requirements for the Baby Monitor projects to be satisfied:

1. Accessibility. The mobility of the I/O mechanism or the product itself
2. Universality. Should be able to adapt to almost any environment
3. Easiness to install and setup, that would not require special skills from users
4. Security practices, that would be sufficient to protect privacy
5. Ability for upgrades and future development

Technical implementation

We can easily satisfy the key requirements mentioned above. The accessibility / mobility of the product is achieved by its relatively small sizing and all components are available in the market. Having the user interface of the messaging system and video stream on mobile phone and /or any desktop via iPhone/Google app and any Web browser choice for the video feed will make this pretty universal. No special skills for a user with some computer knowledge will be required to start up the system, because its components get set up on the boot once the Pie is connected to power source. The security is achieved by having the I/O on the private network and authorization process in messaging bot. Product is at its development stage and there is a lot of room for upgrades and improvements.
We need all the physical components, to have the Operating System installed, wired up sensors and cables, and to have wireless Internet connection. For having the convenient working environment and proper interface, the Morgan Library rooms with public WiFi (CSU-Guest network) and HDTV Monitors were a perfect solution. We can also use SSH connection while working on the Pie remotely from personal laptops. So once the basic step was arranged (the progress is documented in the previous paper TP-D2), we needed to work on both critical components of the project: notification system and video streaming.

Notification system

One of the key requirements was an ability to support streaming and notifications on a wide range of platforms, especially smartphones. Resources for this project eliminated an option to develop custom software, and a currently existing solution has had to be found. After thoroughly analyzing the market, a few candidates were found. Their comparative characteristics are provided in the table below.

Table 1. Messaging application comparison 

As it can be clearly seen from the table, Telegram has comparative advantage in most of the fields. Therefore, this messaging service was chosen as a core for notification system for this project. 
Telegram not only provides a convenient API for messaging bots, but also supports frameworks for most of the languages. Therefore, the messaging feature did not impose any restrictions on future choice of tools. 
According to the project specifications, messaging bot is supposed to send a message to a user every time an object triggers the motion sensor. Since the project has had no external financial support, the cheapest motion sensor available in the market was chosen. This was HC-SR501. According to the HC-SR501 documentation, while attached to the electric chain it generates HIGH output signal on one of its ins when the motion is detected, and LOW in all other cases. 
 HC-SR501 was attached to the pin 04 on raspberry PI. Messaging bot considers HIGH input on the pin as the motion sign. In order to avoid unreasonably often repeating signals it ignores all other signals within the preset time. The time has to be adjusted based on focus group UX analysis, which is impossible with the current resources.
GPIO (general-purpose i/o) programming frameworks have significantly limited the technologies that could have been used to develop messaging bot. For the purposes of this project, Java was chosen as a core language and PI4J as the framework for GPIO support.
Telegram bots are publically available, and anyone could have subscribed to the notification unless the user authorization practices are introduced. To meet the basic requirement of reasonable security measures the following user interaction scheme was implemented:
1. User initiates dialogue with the bot using the telegram search
2. Bot requires user to type the password that can be found in user’s manual
3. User’s credentials (telegram username and chat ID) are saved in a local file
4. User is added to the mailing list on the notifications
After the first successful authorization the user does not have to type the password again if his credentials match the ones from a local file. On receiving the motion signal from HC-SR501 bot sends user warning message with a link to a streaming video.

Video Streaming
Existing streaming software or solutions that satisfies the needs of the project were not all suitable. For instance, there was a solution based on VLC Player which supposed to provide the continues video feed, with almost no delay, however it would not be universal, as it would require installing this software on every device, desktop or smartphone. To match Telegram’s multiplatform support, the solution was to develop it in a form of a web application. So that it could be accessed and used in any popular browser via custom link provided.
In order to make the user experience less dependent on browser plugins, prevent lags, and save traffic, the decision was made to implement not the pure video streaming via the Real Time Transport Protocol (RTP) family, but to send the single images with an adjustable 1-5 seconds time gap between them via the HTTP. So after the research the team decided to implement the js.node and http platform solution to develop this feature (Raspberry Pi, Camera and Node.js) with some adjustments. To make it less dependent on internet, we have saved Bootstrap CSS (http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css), jQuery (http://code.jquery.com/jquery.js) and Bootstrap javaScript (http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js) libraries locally and gave the links beginning with root folder instead in the html page code to access them. Since the needed libraries were stored locally, they have had to be send to user by the server. Therefore, the two folders were included: <include> that contains needed libraries, and <stream> that contains the most recent image from the camera.
app.use('/', express.static(path.join(__dirname, 'stream')));
app.use('/', express.static(path.join(__dirname, 'include')));
So we used Node.js for the backend part of this module for the easiness of development and maintenance. Frontend part relies on jQuery, which is supposed to update an image on a webpage upon the updated photo in a root folder. This is sufficient for the prototype version and can be easily modified basing on customer’s demands. The functionality of the backend part is very basic and does not require more advanced technologies or extra framework support. Its main purpose is to invoke native command to capture the photo from the picam feed and place it to the same file in a special folder. And then we keep sending the same image to the client as it changes every time. Again, this is not the best solution but gets the job done. The team is still looking for alternatives that would provide low latency video feed, be reliable and less dependent.
The link provided to watch the video feed, is constructed on the following principle: http://XXX.XX.X.X:3000, where Xs are the the raspberry Pi’s IP, which will be automatically retrieved by the Telegram messaging bot (or manually via ifconfig command on linux terminal) and 3000 is an assigned port concatenated. 

Product Setup

All the modules described above are loading on the boot and do not require special actions from user. Messaging bot will require user to authorize in order to receive notifications, but this procedure does not require any operations with the device. 
The messaging part of the product requires internet access for its features to operate. Therefore, the user is assumed to connect Raspberry Pi to the local wifi hotspot in order to get the IP address.
For video feed to be working we will need to execute the command node index.js on the terminal. It starts listening on port 3000. So once the user clicks on the link the pages opens up with a Start button. When start - the image by image refreshes on the page and user can see the feed.
The phone where the telegram is installed and operated requires an internet connection, so the Telegram bot can send a message to the user, once the motion sensor is triggered, with a unique IP address with a port number. 
The video presentation of the working unit is available via this link: https://goo.gl/5SRU4j if you can't see the window below:

Solution structure

Table 2. Solution structure


Raspberry Pi is definitely not the most reliable and agile hardware. Definitely, it is unreasonable to compare Raspberry Pi with a normal PC due to a completely different price category and purposes. 
Most of the issues arise from the weak hardware that is unable to run a normal OS with a tolerable throughput. Therefore, RasPi can be only used to deploy some applications if they are compatible with the native OS.
We were also dealing with the security restrictions on the CSU Guest WiFi network on campus, which often placed our raspberry Pie and laptops on different subnets, so we didn’t have a chance to access the Pi directly through its IP address, including SSH and HTTP protocols. In order to avoid this problem on the campus, we emulated home wifi network by using mobile hotspot. So the standard home wifi network would be proper environment for Baby Monitor. 
This project could have been easily implemented by using only a desktop (or remote server) and a wifi-supporting sensors. Working with RasPi was definitely an interesting experience, but given the the availability of various peripherals, RasPi is a feasible tool only in a few situations.
Despite all the hardships that arise from the software limitations, prototype was successfully developed. It fully satisfies all the stated requirements and demanded functionality.

Ideas for future improvements

1. Change state from Motion Sensor from Inactive (No Signal) -> Active (Signal) to Active (No Signal) -> Inactive (Signal), so parents will be notified if a baby goes to sleep.
2. 3D print the case for all components to be as one piece product. Similar to a picture below:

Figure 2. Raspberry Case Example. Source 

3. Provide clear Step-by-Step instructions Manual for the user to set up and operate the unit
4. Simplify the product boot process for an user, modify boot process to keep user from starting the necessary scripts manually.
5.  Can install and run multiple Baby Monitors, e.g. at the nursery homes or kindergartens


1. Telegram Bot Java Library:  https://github.com/rubenlagus/TelegramBots
2. The PI4J Project: https://pi4j.com
3. Raspberry Pi, Camera and Node.js: http://thejackalofjavascript.com/rpi-live-streaming 
4. Streaming Video Using VLC Player: http://www.raspberry-projects.com/pi/pi-hardware/raspberry-pi-camera/streaming-video-using-vlc-player 
5. Telegram API documentation: https://core.telegram.org


I am passionate about creating stuff and want to change the world.

No comments:

Post a Comment