How I built Live Still Life

Behind the scenes -Tech

“Do what you love and you will not realize how much fun learning really is.”

If you did not understand the heading, this is what I was referring to. I remember how it all started. I got a random email from my friend Sharat connecting me to two Dutch artists who were traveling to Bangalore(if that offends you, let me call it Bengaluru? :)) wanted to know how to go about a project they were planning to do for their Art Collective. Well you all know how that turned out.
They came with a decent amount of research on how they wanted to go about it. Raspberry Pi model B with a Pi camera was the tool of their choice. Justus and Mingus had done their part of research on the setup of the entire project.
We finally decided to start prototyping with the Pi. My language of choice for integration of the setup on Pi was python. The documentation on Pi Camera from the organization by itself is amazing. Made our lives easy. Within a few steps, this is where we were.

import picamera
def captureImage(initialImage,finalImage,timeInterval):
camera.capture(initialName+'.jpg')
time.sleep(timeInterval)
fileName(initialName+'.jpg',finalName) #Add the extension
print "clicked"
#Put your code here
First crack at the Pi Camera, you can also see the frame these brilliant artists came up with!

The next challenge was to create Live Stream. There are obviously many ways and numerous blogs on how to create a live stream from an IP camera. From Pi Camera though? Not a lot, not really. Once we figured out how the mechanics of the camera capture are going to work out, we zeroed in on more important aspect of the project and here is what we wanted:

1. The stream should(*HAD*) be data efficient.
2. The stream should be visible to anyone who visits the link, no matter what time or place. So it *HAD* to be scale-able
3. Get the image composition right.

The asks look pretty easy right? But you have no idea how many calculations were done to get the image size just right. Finally we got it right. Thanks to the careful calculations done by Mingus.
For the sake to data efficiency, we chose to post a picture a minute to the server. The picture was essentially a multipart POST request which was being made every minute by the python code running on the Pi. Oh and it tweets the image every 6 hours as well. Once the base code was ready, adding twitter functionality to it wasn’t a uphill task. Meanwhile Justus and Mingus built out the housing and the stage for the project with hands and lots of hand tools from Workbench Projects.

Server was written using a module called Exprestify written on top of Express Js to facilitate easier RESTful functionalities.
Wanna try it?

$sudo npm install exprestify --save

It was written by my colleague and friend Ajith N N . The server handles all the POST requests made by the Raspberry Pi and the GET Requests made by the client (webpage/app).

I initially used the good old flags and crap on the server to make sure all the images were loading smooth. But soon I realized it wasn’t the way to go. There were issues loading the images, all the time, because of the browser’s caching.

That is when I put two hacks together:
First one, append time stamps to all the image urls so that caching issues could be handled.
Second one, integrate socket-io functionality to push the images on to the client every time there was a change in the base image on the server’s folder. That is, just in time when Ajith was finishing adding the socket-io integration on to his module.
Well there it was then, with a little tweaking I could test the functionality on the server.

This amazing moment when the same day I deployed the code on Heroku and found out it works like a charm! Still remember celebrating it with Gulab Jamuns with the artists:)

Here is the proof of the Gulab Jamuns . Look at that smile!!

Well so that was it, a few weeks of working at Workbench Projects (after work) with these two amazing people, we were able to get the stream up and running.

The key here is with the most accessible tools, a not-so-complicated logic on the server and the power of Heroku, we were able to get the project up and running within a few weeks for testing. It is now installed at Workbench Proejcts. Oh and it hasn’t failed for 2 months now! (Fingers Crossed)

Moral of the story? When an old friend writes to you, have a look at that message, there are little pockets of happiness in every phone/email and every conversation. Oh and artists are super amazing to work with, they see the world from the eyes of a curious , excited and happy child.
All I could see and feel was creativity and happiness, everywhere!

Wanna read more about the project ? Read here .
Would you like to have a look at the Module? Read here .
Want to know more about the code? Drop me a message I am cleaning up all the code right now, could make it open faster if you need to have a look.

Rishi Gaurav Bhatnagar

Written by

Forbes 30 under 30 | Author | Intel Software Innovator | Product Guy | Storyteller

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade