After 38946 gifs and 24660 jpgs my Raspberry pi has stopped taking photos.

I am not sure why but it stopped recognising the camera module. I’ve decided to give that a rest while keeping the pi going as a server for other things. I’ve also moved it from the windowsill to a better position on my local network.

It is still running my River5 which I wrote about Raspberry River and a basic web-server: john’s pi server.

I’ve now added Dave Winer’s blogging software 1999.io: johnjohnston which has been running for nearly a week. Setup notes: 1999 set up on my pi

This has given me a chance to play (a little) with all the pieces, node, git, the pi and a new blogging system.

1999.io is quite opinionated software and has some differences from systems I am more familiar with. I’ve written some notes 9 Thoughts on 1999.io (archive.org link) & Comments, Rivers and Glossaries (Archive.org). It is helping me think a bit about how software affects us.

I’ve also bought a Pi NoIR camera which I’ve used on my other pi, grabbing photos every minute of the bin outside our window in the hope of catching some foxes. It is not posting to the web, but over the network to my mac. My poor craft skills mean it was balanced on some cardboard and slowly slipped through the night. No foxes were photographed on the first try. I’ll be getting a better mount and trying again.

I’d like that, second, pi to be portable with a few buttons to do different things, start timelapse, grab and post a gif, etc. I’ll need to learn a bit more.

Last week I spent some time with a chromebook. It was the cheapest one on the Scottish procurement. I was surprised how responsive it was, quick to start up, reasonable trackpad and OK keyboard.

It seemed to be that if you were mostly using the web or if your needs were met by web browser applications that it would do quite a lot. I was reminded of Clarence Fisher talking about using a raspberry pi and finding it could meet a lot of his needs.

Personally I’ll stick to my MacBook for as long as I can afford to. I’ve got a lot of muscle memory, customisation and spent a fair bit on applications over the years. Along with the long life of Apple computers I don’t think I pay too much for what I get. I was interested in exploring how to do some things with a chromebook and the raspberry pi connection got me googling.

It seems you can connect to a raspberry pi in the same way I do from Mac and iOS devices, via ssh.

According to various sites and posts I found there is a built in terminal in the chrome browser that supports ssh.

So I hit control-alt-t to open the wheel and typed in ssh username@pi.johnj.info
At that point I got a message saying that the built in tool was no longer there and I needed to install an app. This I did.
secure she'll app

I’ve now got the secure shell app. This lets me easily connect to and work/play on the pi in the same way I already do from Mac or iOS.
top on the pi

For a dabbler like myself this is a pretty nice setup. Especially at less than £200.

I am just kicking tyres on the pi without any depth of knowledge but it already is running:

Quite a lot for such a wee box and there are tons of other things I could add given a bit of reading.

I think this points to the possibilitys of two small cheap devices adding value to each other and opening up some possibilities.

I’ve been following the work of Dave Winer for a while now. His pioneering work with RSS, blogging and podcasting is central to my use of the web. I’ve even dipped my toes into and blogged about Fargo his outliner tool a few times, I tried myword.io a couple too.

The product I am most interested in was the Rivers project. This is a take on RSS readers, where you view collections of RSS in a stream, rather than a folder structure.

In the past I set up River3 and River4. These products really need a server that goes a bit further than web hosting. I had some working locally but this was not ideal. The instructions for using the previous version of River tended to involve Amazon Web Services and a server elsewhere.

River5

River5 changes all of this, it is designed to keep everything in the same place, one server. The only difficulty is that it requires a server running node.

This is pretty simple to set up locally on a mac. You need to use the terminal. You install node. Then you follow the instructions on the River5 github page and you are away.

What is very nice indeed is that you can add feeds you want to read in several different formats opml (handy for export from other RSS readers), json and plain text. There is a set of example feeds provided that will let you see everything is working.

I wanted to be able to have the rivers running all the time and be accessible from other computers. For that I need a server that I could install and run node on. Turns out I have one, john’s pi server. That sits on my window sill mostly taking pictures of the sky. It was running a twitter bot but that is broken at the moment.

Setting up River5 on a Raspberry Pi

I do most things on my pi via the terminal on a mac or iPad, suing ssh to logon.

I had installed node on the pi a while back.

Download the latest:
wget http://node-arm.herokuapp.com/node_latest_armhf.deb

then install:

sudo dpkg -i node_latest_armhf.deb

I seem to have done that a while back when I was failing to get something else up and running.

All I need to do to get River5 installed was to download the files from github and upload them to the pi with scp.
I then unzipped them went into the folder and ran these two commands:

npm install

node river5.js

This set everything up, a plie of stuff streams by in the terminal and all looked ok. (I had problems the first time I tried but an update came out immediately that fixed things for Linux servers. I got a very quick response on the River5 Forum).

My Pi already has a sub domain so I visited http://pi.johnj.info:1337 and could see the rivers flowing with Dave’s Feeds.

I’ve now removed the original ones and replace them with lists of feeds of my own.

Rivers Forever

After that I went to bed, next morning I tried the link and it was down. The problem is I need to keep the application up and running even when I am not logged onto the server. I recalled reading on Dave’s blog about Forever. As usual google found the instructions to install and use: Keep a node.js server up with Forever.

This is pretty simple you install Forever with:

sudo npm install forever

npm is a package manager for JavaScript so it installs stuff.

After it is installed we can start up the river5 with:
forever start river5.js and it keeps going.

Mine has been running for a few days now on the pi without any problems.I’ve been enjoying an alternative view of some of my RSS feeds. My next steps are probably to move things around a bit so that I don’t relay on the built in node server, and can pull the river json over to here.

I am pretty amazed by the ease of doing this. The software has been made to be very easy to install and the Raspberry Pi turns out to be a very capable wee box.

My raspberry pi, was having problems. For a while it had sat on the windowsill happily posting images to tumblr day and night on skypi and broomhill sky’s, it served up a small website itself too.

At some point it stopped working. I rebooted the device a few times, turned if off and on again, then left if for another day.

I had a bit of time on my hands on Thursday so decided to story it out. Since the device didn’t seem to be working at all, I could not connect to it via ssh and it was not serving the website I though I’d better just start from a clean install. So this is what I did.

  • bought a new SD card.
  • downloaded a new image from NOOBS for Raspberry Pi
  • wiped the card and copied the files over
  • moved the pi to the living room and hooked up the to and a keyboard
  • booted the pi and went through the initial setup
  • shut down the pi to prepare to move it back to the windowsill where I planned to connect via ssh and redo all the server and script stuff to get it working.

At that point, while the pi was still hooked to the tv I though I’d give the old card a final try. Of course it booted up straightaway!

I then took the pi with the old card back into the other room and connected to power and ethernet. Back to the Mac and tried to ssh on. Fail, check the website that sits on the pi, fail.

Finally I took the Ethernet cable out of the powering plug and put it back in again. Everything started working properly.

I do not know how many times I’ve repeated this sort of routine expecting the worst and skipping the obvious. I do hope I’ve learnt my lesson but somehow I doubt it.

Update 29-09-2016: the pi is no longer posting gifs and images. I’ve recycled it it. Also hat-tip to Oliver Quinlan for catching a mistake in the instructions, I’ve fixed it below (sudo pip install pytumblr). The archive of over 50,000 gifs is still there.

A couple of weeks ago I blogged about getting my Raspberry Pi to create gifs and server them to the web:Gif Cam.

This only keeps the most recent gif. A couple of days ago I tried to set it up to catch the blood moon, and store a series of gifs but my scripts failed to work. It did lead me to changing the position of the camera from the local cross roads to the sky.

I then noticed a couple of interesting images, so though about how I could do that. There is not enough room on the pi’s SD card to hold images for very long. I started by uploading the gifs to a website via ftp. But this was still not a long term solution. I then though about Tumblr and after a bit of googling I’ve got a working solution that posts a gif of the Glasgow Skies to Sky Pi.

Here are some notes to show how I did some of it. You need to be able to use the termianl and a command line file editor such as nano. I am very much a newbie with this stuff.

My pi is on my home network connected to the router via Ethernet and a powerline. It is set up as a webserver with a domain, http://pi.johnj.info. I have ssh access to the pi and do any editing from my mac via ssh. None of these things apart from the connection to the Internet.

The pi is running from an SD card with NOOBS installed.

I’ve run: sudo apt-get update
and
sudo apt-get upgrade
before starting to get the pi up to date.

Code like the above is run form the terminal, either on the pi with a monitor and keyboard or by logging on via ssh. I create scripts on the pi in the terminal with nano, which is an uncomplicated text editor that is used in the terminal.

Taking Pictures, making Gifs

The whole thing runs from a shell script, which started like this:


    #!/usr/bin/env bash
    for (( i = 0; i < 10; i++ )); do
        raspistill -h 486 -w 648 -a 1036 -vf -hf --encoding gif  -o /var/www/tempgifs/cam${i}.gif
    done
    gifsicle --delay=10 --colors 256  --loop /var/www/tempgifs/cam*  > /var/www/tempgifs/camd.gif
    mv /var/www/tempgifs/camd.gif /var/www/camd.gif
    raspistill -h 486 -w 648 -a 1036 -ae +25+25 -vf -hf -o /var/www/camd.jpg

When the script runs, it takes 10 still pictures with the raspistill program. I am not too sure if these are the best settings, but

  • -h 486 and -w 648 set the dimensions.
  • -a 1036 stamps the date and time.
  • -vf -hf flips the image and turns it upside down (to put it the right way up)
  • –encoding gif outputs as a gif
  • -o /var/www/tempgifs/cam${i}.gif set the file path for the export.

I saved this file to regulargif.sh and then made it run-able with chmod +x regulargif.sh.

I’ve installed gifsicle with sudo apt-get install gifsicle and use that to create the gif file. The last line creates a jpg too. You can see the current gif and jpg on Gif Cam.

I need the script to run regularly so I set up a cron job. To do this in the terminal type crontab -w and add

*/9 * * * * /path/to/regulargif.sh

to the bottom of the file. This will run the script every 9 minutes.

Tumbling Gifs

The next problem is to upload to tumblr. Tumblr has a well developed API and libraries for several languages. After a fair bit of googling for a simple solution I decided to just use one of Tumblr’s own. I though it sensible to use Python as that language seems to have a lot of support on the pi. I don’t know any python.

First you need to install the pytumblr python module. So in the terminal:

sudo pip install pytumblr

You also need to have various keys for the API: consumer_key, consumer_secret, oauth_token and oauth_secret. To get these you need to create an App on tumblr. Here is what I did. (Well this was a second run through to document, the first time got a bit messy;-))

register an application Click the button and fill in the fields.
This will give you the consumer_key and consumer_secret.

key-and-secret

If you click the Explore API you will get a dialog to allow your new app to post for you (This did not work for me in Safari, I had to switch to Chrome and go through a couple of times).

permit-app

This will lead to a place to fill in your key and secret. Then the console.

add-keys

The Console will let you test various bits of code but more important will let you copy a block of code with the consumer_key, consumer_secret, oauth_token and oauth_secret.

all-info

It is worth clicking on Example output on the console to make sure everything is working.

Moving back onto the pi and the terminal I edited a new file with:

nano pytumble.py

And edit the file:


import pytumblr

client = pytumblr.TumblrRestClient(
 'consumer_key',
  'consumer_secret',
  'oauth_token',
  'oauth_secret'
)

# Make the request
o=client.create_photo('raspskypi', state="published", data=["/var/www/camd.gif"] )

print o

With the keys, tokens and secrets filled in. raspskypi is the name of the tumblr blog.

Save the file and make it executable. (chmod +x ) pytumble.py.

then type:

python ./pytumble.py

After a minute, if all is set up right you should see an id for the post returned and checking the blog should show a post with the image from /var/www/camd.gif

If all is well you can add:

python /home/pi/pytumble.py

To the bottom of the script that makes the gif.

Now every time the script creates a new gif, it should post the image to your tumblr blog.

Currently my pi has uploaded over 200 gifs: Sky Pi: Archive.

I’ve got my raspberry pi working as a webcam posting gifs every 9 minutes and stills every 5. Gif Cam.

The pi has been sitting around for a while acting as a web server with a broken tweetbot. It took very little effort to get it taking photos from our window and showing them on the web. Little more to grab a bunch and gif them (Gifsicle again). A better view might be more interesting.

I’ve not spent as much time as I’d like playing with the pi but the potential for play, learning and work seems large.