timjuni
Posts: 11
Joined: Tue Aug 27, 2013 7:02 pm

Python web interface for raspistill

Fri Oct 11, 2013 1:45 pm

I was new to python so i decided to tryout some web frameworks. As initial project i've decided to write a little web interface for raspistill using the pyramid framework.

I've implemented support for image size, image effects, exposure modes and awb modes for the Raspberry Pi Camera Kit. The missing options can be implemented without too much work.

The Source-Code and installation instructions can be found on github:

https://github.com/TimJuni/raspistillWeb

Feel free to post your ideas about it.

Best regards,
Tim


Preview image:
Image

User avatar
waveform80
Posts: 360
Joined: Mon Sep 23, 2013 1:28 pm
Location: Manchester, UK
Contact: Website Twitter

Re: Python web interface for raspistill

Fri Oct 11, 2013 10:05 pm

Looks very nice! I've been working on something similar (picroscopy) which rather obviously leans toward cameras attached to microscopes, but the functionality is basically similar (although yours is a lot prettier!). As part of that effort I wrote a python library for controlling the camera (without calling out to a raspistill subprocess) which is now integrated into picroscopy (not that I've done a proper release of the latter yet but you might find the code interesting).

For once, I eschewed using pyramid (which I generally use as my default web framework in python - it's a fantastic piece of kit), as I figured it's a single user app (there's only one camera after all), and it'd make a nice teaching example to stick the framework together "manually", so picroscopy relies on wheezy.routing for the router, webob for the request/response objects and chameleon for the templating.
Author of / contributor to a few pi related things (picamera, Sense HAT emulator, gpio-zero, piwheels, etc.), and currently a software engineer at Canonical responsible for Ubuntu Server and Core on the Raspberry Pi.

timjuni
Posts: 11
Joined: Tue Aug 27, 2013 7:02 pm

Re: Python web interface for raspistill

Sat Oct 12, 2013 6:56 am

waveform80 wrote:As part of that effort I wrote a python library for controlling the camera (without calling out to a raspistill subprocess)
This looks really interesting, i probably will use it in the next version, thanks!

You might already know, but if you want fancy layouts without spending too much time in designing, you really have to look at http://getbootstrap.com. There is no easier way to create good looking web pages, especially for mobile devices.

bighead85
Posts: 50
Joined: Tue Mar 26, 2013 9:37 am

Re: Python web interface for raspistill

Wed Nov 13, 2013 11:17 am

Excellent little app. Thank you so much. It is a great basis for what I am trying to do.
I am trying to create the exact same thing but in a Google Now style card, where the card is just the image and the Take Photo Button, if you click on more this exact style of page opens with all these options. This card will then be on a webpage view similar to g+ that can be used on a mobile device or desktop. (other cards I am trying to make are a Internet Radio streamer, piglow interface and Google query).

I have the background codes and was wondering where to start on a user interface. Thanks again.

timjuni
Posts: 11
Joined: Tue Aug 27, 2013 7:02 pm

Re: Python web interface for raspistill

Wed Nov 13, 2013 12:36 pm

Sounds interesting. Please fork my project on github or post a link to the source code so that we can follow your project ;)

bighead85
Posts: 50
Joined: Tue Mar 26, 2013 9:37 am

Re: Python web interface for raspistill

Wed Nov 13, 2013 1:07 pm

I will soon as i have something. Although familiar with the basics of HTML, python and these frameworks are completely new.
At minute just playing around to try and understand how files relate to each other.

Other than the CSS and HTML the rest of the build is a mystery to me, so learning from the ground up.

bighead85
Posts: 50
Joined: Tue Mar 26, 2013 9:37 am

Re: Python web interface for raspistill

Fri Nov 15, 2013 12:50 pm

Hi,
So i have downloaded and set up Google Coder, to try and make my application with.
Although there are lots of tutorials on the basics I wondered how you made it run the raspistill command?
I have it showing a page and I have created a toggle, but not clear on how to make the page interact with the rest of my pi. (already have a couple of bash and python scripts but want to trigger them from this new application)

Any help you can offer will be much appreciated.

phreack
Posts: 2
Joined: Wed Nov 27, 2013 4:12 pm

Re: Python web interface for raspistill

Wed Nov 27, 2013 4:18 pm

When I start raspistillWeb, I get the following messages after a few seconds:

Starting server in PID 2831.
serving on http://0.0.0.0:6543

Then, once I point a web browser at the raspi's IP address:6543, I get this message:

RaspiStill: Unknown exposure mode: off

After that, it just hangs. Nothing ever shows up in the browser before it times out.

It does, however create an image in the proper folder. The first time I tried it, it gave me an error message (sorry, didn't save it) about not being able to create the file. It was creating a file with the extension .jpg~ with 0 size, but it wouldn't make a good image. I tried deleting everything and following the instructions again, and this is where I'm at. I'd try the same again, but I'm out of time for today, so I figured I'd shoot you a message and see if you could provide any insight.

Thanks for doing this. It's exactly what I want.

phreack
Posts: 2
Joined: Wed Nov 27, 2013 4:12 pm

Re: Python web interface for raspistill

Sat Nov 30, 2013 2:42 am

I have some more information on what my pi is doing when trying to run your software. I started the server, waited for it to start up, and telnetted to port 6543 on the pi. I then did a "get /", to which there was no response. I waited a couple minutes, and nothing. I then checked for a response in chrome, which reported nothing, even after waiting a few minutes again. I then just pointed the browser at it again and left for a couple hours to let it churn and see if it'd do anything, and still had no luck.

When I got home later, I killed the server, and for the first time got some pretty verbose error messages that I thought I'd share. Here goes:

Code: Select all

pi@picam ~/Development/env/raspistillWeb $ ../bin/pserve development.ini
Starting server in PID 4818.
serving on http://0.0.0.0:6543
RaspiStill: Unknown exposure mode: off
RaspiStill: Unknown exposure mode: off
RaspiStill: Unknown exposure mode: off
^Cmmal: Aborting program

mmal: Aborting program

mmal: Aborting program

2013-11-29 20:09:51,103 ERROR [waitress][Dummy-1] Exception when serving /
Traceback (most recent call last):
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/waitress-0.8.7-py2.7.egg/waitress/channel.py", line 332, in service
    task.service()
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/waitress-0.8.7-py2.7.egg/waitress/task.py", line 173, in service
    self.execute()
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/waitress-0.8.7-py2.7.egg/waitress/task.py", line 388, in execute
    app_iter = self.channel.server.application(env, start_response)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/router.py", line 272, in __call__
    response = self.invoke_subrequest(request, use_tweens=True)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/router.py", line 247, in invoke_subrequest
    response = handle_request(request)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.9-py2.7.egg/pyramid_debugtoolbar/toolbar.py", line 141, in toolbar_tween
    return handler(request)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/tweens.py", line 21, in excview_tween
    response = handler(request)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/router.py", line 163, in handle_request
    response = view_callable(context, request)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/config/views.py", line 348, in rendered_view
    result = view(context, request)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/config/views.py", line 494, in _requestonly_view
    response = view(request)
  File "/home/pi/Development/env/raspistillWeb/raspistillweb/views.py", line 103, in home_view
    f = open(RASPISTILL_DIRECTORY + filename,'rb')
IOError: [Errno 2] No such file or directory: 'raspistillweb/pictures/2013-11-29.21.09.43.jpg'
2013-11-29 20:09:51,109 ERROR [waitress][Dummy-2] Exception when serving /
Traceback (most recent call last):
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/waitress-0.8.7-py2.7.egg/waitress/channel.py", line 332, in service
    task.service()
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/waitress-0.8.7-py2.7.egg/waitress/task.py", line 173, in service
    self.execute()
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/waitress-0.8.7-py2.7.egg/waitress/task.py", line 388, in execute
    app_iter = self.channel.server.application(env, start_response)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/router.py", line 272, in __call__
    response = self.invoke_subrequest(request, use_tweens=True)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/router.py", line 247, in invoke_subrequest
    response = handle_request(request)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.9-py2.7.egg/pyramid_debugtoolbar/toolbar.py", line 141, in toolbar_tween
    return handler(request)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/tweens.py", line 21, in excview_tween
    response = handler(request)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/router.py", line 163, in handle_request
    response = view_callable(context, request)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/config/views.py", line 348, in rendered_view
    result = view(context, request)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/config/views.py", line 494, in _requestonly_view
    response = view(request)
  File "/home/pi/Development/env/raspistillWeb/raspistillweb/views.py", line 103, in home_view
    f = open(RASPISTILL_DIRECTORY + filename,'rb')
IOError: [Errno 2] No such file or directory: 'raspistillweb/pictures/2013-11-29.21.08.29.jpg'
2013-11-29 20:09:51,113 ERROR [waitress][Dummy-3] Exception when serving /
Traceback (most recent call last):
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/waitress-0.8.7-py2.7.egg/waitress/channel.py", line 332, in service
    task.service()
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/waitress-0.8.7-py2.7.egg/waitress/task.py", line 173, in service
    self.execute()
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/waitress-0.8.7-py2.7.egg/waitress/task.py", line 388, in execute
    app_iter = self.channel.server.application(env, start_response)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/router.py", line 272, in __call__
    response = self.invoke_subrequest(request, use_tweens=True)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/router.py", line 247, in invoke_subrequest
    response = handle_request(request)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.9-py2.7.egg/pyramid_debugtoolbar/toolbar.py", line 141, in toolbar_tween
    return handler(request)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/tweens.py", line 21, in excview_tween
    response = handler(request)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/router.py", line 163, in handle_request
    response = view_callable(context, request)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/config/views.py", line 348, in rendered_view
    result = view(context, request)
  File "/home/pi/Development/env/local/lib/python2.7/site-packages/pyramid-1.5a2-py2.7.egg/pyramid/config/views.py", line 494, in _requestonly_view
    response = view(request)
  File "/home/pi/Development/env/raspistillWeb/raspistillweb/views.py", line 103, in home_view
    f = open(RASPISTILL_DIRECTORY + filename,'rb')
IOError: [Errno 2] No such file or directory: 'raspistillweb/pictures/2013-11-29.21.09.07.jpg'
pi@picam ~/Development/env/raspistillWeb $ ls raspistillweb/pictures/
2013-10-07.06.26.36.jpg  2013-11-29.20.55.05.jpg  2013-11-29.21.01.50.jpg  2013-11-29.21.04.02.jpg  2013-11-29.21.07.09.jpg  2013-11-29.21.07.09.jpg~  preview.jpg
I also included a listing of files in the pictures directory. If you'll notice, the names of the images are significantly differently timestamped from the files it gives an error in looking for. Any idea why it would be doing this, or how to fix it?

Also, after some more fiddling, it seems I've figured out how to get it to throw the error messages. If I just put the server up, try to connect to it, and kill it after one attempt, it doesn't tell me anything. If I stop the browser and try to refresh, it will either immediately fail out and give me a similar error to the one above, or it will keep running, but give the above error when I ctrl+c to kill it.

If it matters, mine is an early B board, before they doubled the ram.

edit: another thing I just noticed...I had caught that the timestamps were different, but not that they were actually wrong. It appears to be stamping them in GMT instead of local time. I'm in USA CST, and all of those times are +6 hours from my local time. That shouldn't affect functionality, but it's something I'd like to change once I get it running.

timjuni
Posts: 11
Joined: Tue Aug 27, 2013 7:02 pm

Re: Python web interface for raspistill

Sun Dec 15, 2013 8:44 pm

phreack wrote:When I start raspistillWeb, I get the following messages after a few seconds:
Then, once I point a web browser at the raspi's IP address:6543, I get this message:

RaspiStill: Unknown exposure mode: off
i have not followed the project for a while now, maybe there is a new version of RaspiStill so my app is not working properly. I will check that during next week. Thanks for your feedback.

Cheers, Tim

timjuni
Posts: 11
Joined: Tue Aug 27, 2013 7:02 pm

Re: Python web interface for raspistill

Sun Dec 15, 2013 9:06 pm

phreack wrote: I also included a listing of files in the pictures directory. If you'll notice, the names of the images are significantly differently timestamped from the files it gives an error in looking for. Any idea why it would be doing this, or how to fix it?
You are right, i'am using GMT timestamps to identify the photos, thats why i put the GMT into the filename. The application (in the browser) should show you the correct (local) time, right? I'am using the following command to extract the local time from the file/os itself:

Code: Select all

time.asctime(time.localtime(st[ST_MTIME]))
I thought that using GMT is a good idea, so i won't create any collisions while storing the photos. Basically the timestamp in the filename is nothing more than an unique identifier. I can try to use the local time as identifier - it shouldn't make any difference (as long you're not changing the time zone) :)

phreack wrote: If it matters, mine is an early B board, before they doubled the ram.
I also have an early B board and the application works fine. What os do you use?

Regards,
Tim

timjuni
Posts: 11
Joined: Tue Aug 27, 2013 7:02 pm

Re: Python web interface for raspistill

Mon Dec 16, 2013 7:37 pm

timjuni wrote: i have not followed the project for a while now, maybe there is a new version of RaspiStill so my app is not working properly. I will check that during next week. Thanks for your feedback.
Actually there is a new version of raspistill which does not allow to set the timer for a photo to zero. I've changed the delay to 200ms and i expect the application to work fine now.

I will check if i can use the local time for the timestamps. If you're interested in solving this issue you can try to modify the views.py at line 101+
https://github.com/TimJuni/raspistillWe ... b/views.py

Cheers, Tim

chorlton2080
Posts: 128
Joined: Sun Dec 23, 2012 9:44 pm

Re: Python web interface for raspistill

Mon Dec 16, 2013 10:47 pm

I had been wondering why following a recent update my motion detection routine no longer functioned: I had set 't 0' in the parameters for raspistill.

If I hadn't stumbled across the above post I'm sure my Raspberry would be sharing a tip with a hard drive full of bitcoins.

How could I have realised this myself? There isn't even a 'man' page for raspistill. No error is presented of 't 0' is used.

coolcow
Posts: 4
Joined: Mon Jul 22, 2013 1:41 pm

Re: Python web interface for raspistill

Sun Jan 26, 2014 4:04 pm

Very nice project ! :)

Is there a way to choose where the thumbnails and the pictures are stored ?
Another point: it would be nice if the preview picture could be overwriden, instead of generating a new picture each time i refresh the page.

timjuni
Posts: 11
Joined: Tue Aug 27, 2013 7:02 pm

Re: Python web interface for raspistill

Sun Jan 26, 2014 4:20 pm

Hey coolcow,

both things you mentioned are on my TODO list. I will implement that tonight (probably) :)

Cheers
Tim

timjuni
Posts: 11
Joined: Tue Aug 27, 2013 7:02 pm

Re: Python web interface for raspistill

Sun Jan 26, 2014 10:01 pm

Good news,
coolcow wrote: Another point: it would be nice if the preview picture could be overwriden, instead of generating a new picture each time i refresh the page.
i finally fixed that, so that new photos are only taken after hitting the "Take Photo" button (except for the first picture). In addition i've added "delete markers" to the archive so that you can delete a photo from the archive. Note that the photo is only deleted in the archive view, the file still in the filesystem.
coolcow wrote: Is there a way to choose where the thumbnails and the pictures are stored ?
I will check that but it should be possible. Unfortunately i can't promise that the program won't do any "damage" to the destination (delete files etc), because attacks are always possible.

Cheers, Tim

timjuni
Posts: 11
Joined: Tue Aug 27, 2013 7:02 pm

Re: Python web interface for raspistill

Tue Jan 28, 2014 9:57 pm

coolcow wrote: Is there a way to choose where the thumbnails and the pictures are stored ?
I've added that today. You can now change the path in the file "views.py" to the directory you like.

Cheers, Tim

bighead85
Posts: 50
Joined: Tue Mar 26, 2013 9:37 am

Re: Python web interface for raspistill

Fri Feb 14, 2014 1:04 pm

This is an awesome project and i'm loving the developments since i last played.
One thing i cannot seem to get round is the rotation, it works perfectly on taking a picture but i cannot get it to work in time lapse.

I have changed the default from 0 to 270 (using a new PICE case, which rocks as makes my pi waterproof but requires this on camera)

In views.py i have added rotation to the timelapse def

Code: Select all

       call (
        ['raspistill'
        + ' -w ' + str(image_width)
        + ' -h ' + str(image_height)
        + ' -ex ' + exposure_mode
        + ' -awb ' + awb_mode
		  + ' -rot ' + image_rotation
        + ' -ifx ' + image_effect
        + ' -th ' + THUMBNAIL_SIZE
        + ' -tl ' + str(timelapse_interval)
        + ' -t ' + str(timelapse_time) 
        + ' -o ' + TIMELAPSE_DIRECTORY + filename + '/'
        + filename + '_%04d.jpg'], shell=True
        )    
    timelapsedata['image_effect'] = image_effect
    timelapsedata['exposure_mode'] = exposure_mode
    timelapsedata['awb_mode'] = awb_mode
    timelapsedata['image_rotation'] = image_rotation
    timelapsedata['timeEnd'] = str(asctime(localtime()))
I have also made it start on boot using a simple bash script

Code: Select all

#!/bin/bash
cd /home/pi/Documents/scripts/Development/env/raspistillWeb
../bin/pserve development.ini
and added @reboot /home/pi/script.sh
to the end of

Code: Select all

crontab -e
Once again thanks for all the great work this is really handy for me.

EDIT: I was able to sort myself, rookie mistake i had used "space bar" instead of "tab" to indent and must of got it wrong. works perfectly now.

timjuni
Posts: 11
Joined: Tue Aug 27, 2013 7:02 pm

Re: Python web interface for raspistill

Fri Feb 14, 2014 7:28 pm

Just amazing! :)

I simply forgot the rotation (and iso) settings for the timelapse pictures -.-

But i plan to rework the timelapse section so that you can stop the recording and see the latest thumbnails etc. This will hopefully happen in the next two weeks.

And thank you for the simple guide to autostart the application. If you agree i would put this into the readme section in github. It would be even better if you try to perform a pull request so that you are officially a contributor :)

Thank you again,
Tim

bighead85
Posts: 50
Joined: Tue Mar 26, 2013 9:37 am

Re: Python web interface for raspistill

Mon Feb 17, 2014 9:18 am

Hi Tim,
Please feel free to use anything from my reply, I do not have a Git hub account as so far nothing I have started has been finished. (I really should get on and finish at least 1 project i start).

This really is a very handy tool for me and i will keep an eye on your progress.
Thanks for all your on going work with this.

bighead85
Posts: 50
Joined: Tue Mar 26, 2013 9:37 am

Re: Python web interface for raspistill

Tue Feb 18, 2014 5:30 pm

Sorry to keep breaking things, I just tried setting time lapse for 3 days (259200000) and 30 second intervals (30000).
Yet when it ran it reverted to the default instead, i then tried it in the terminal on the machine and it started without a problem. Did you put in a limit somewhere? (was looking in views.py but no sign)

cheers

timjuni
Posts: 11
Joined: Tue Aug 27, 2013 7:02 pm

Re: Python web interface for raspistill

Mon May 25, 2015 7:25 pm

Good news, i released a new version of raspistillWeb. The settings and the pictures are now stored in a persistent database. The new version is available under:
https://github.com/TimJuni/raspistillWeb

Return to “Camera board”