I’d seen Rachel Rayns tweet about using plot.ly for graphing the temperature output of her Chef’s HAT sous vide cooker. I know Rachel loves “human readable instructions”, as do I. So I thought there was a good chance the plotly documentation was good. I decided to give them a shot.

Sign Up For An Account

The first thing you have to do is sign up for an account. After that, you get some special keys and passwords that you can use in your Python scripts to authenticate with the Plot.ly Applications Programming Interface (API).

After installing plotly, you can ‘register’ your Pi (more specifically, your SD card) with Plotly with the following. You should be able to cut and paste this code with your API keys already in it from the Plotly getting started page…

On the Raspberry Pi, this seems to work beautifully. When I’d got my script working on the Pi, I put it on my web server and it failed intermittently until I put the plotly credentials in the script itself, near the top, like this…

The above code will create a graph on the Plot.ly server under your account. The graph will be called basic-line. You can view it by going to plot.ly, logging into your account and clicking on workspace. You shoud then see a list of graphs (well, only one if you’re just starting out). In this list should be basic-line

If you click on basic-line it should show you a graph.

Graph of basic-line

In the top right of the page, is a blue button called “share”…

If you click the share button it gives you various sharing options, links, twitter links, embed codes for websites/blogs etc.

Plotly Sharing Options

To get an interactive graph on this blog page, I clicked embed…

Embed code for plot.ly graph

And if you actually embed that code on the page, you get this interactive graph. If you ‘mouse over’ any of the points, it gives you the data…

Basics Done, Now Let’s Use It

It took me a couple of days’ worth of ‘messing about’ time to work up the following Python script whichs reads data from the log file created by the ks4.py tracker script, extract the relevant data, and generate a Plot.ly graph. This is the output of the kslog-raspio.py script…

I’m running this script on my server (as a ‘cron job’) to refresh the graph every 10 minutes or so. The nice thing is that, because the server is a Linux machine, I was abe to prototype the whole thing on the Pi and then upload it to the server with minimal changes (cron is fussy about full file paths). It’s now sitting there doing its job of graphing the RasPiO Duino KickStarter campaign.

RasPiO Duino – click photo to go and have a look

Here’s the Code

You will need to insert your own plotly API keys, unless you’ve done the authentication described above (in which case comment out line 5).

[…] Alex Eames has been experimenting with the API of an online service called Plot.ly which allows you to send it a packet full of data which it then plots into a graph. He’s written some sample code and instructions for you to do it yourself. Read it here. […]