Last year during the “Black Friday” weekend Pimoroni held their 2nd annual Cyber weekend competition and one of the challenges they set was “what data would you use https://data.sparkfun.com/ for?” At the time I took a quick look at it, decided the challenge was not for me and went and made a cup of coffee and a syrup sandwich instead. However, yesterday while looking for something else on github I stumbled across the sparkfun’s github page (https://github.com/sparkfun/ ) & saw that they had released the software for data.sparkfun.com and called it phant so that it is possible to self-host your own version.
As the node.js that is in the raspbian wheezy repos was last considered the “latest” sometime around the Cretaceous the 1st thing we need to do is install a more recent node.js.
To install a newer (latest) node.js & npm (node package manager) if you haven’t already done so follow Darryl’s very easy instructions on http://revryl.com/2014/01/04/nodejs-raspberry-pi/ or the very terse instructions on http://node-arm.herokuapp.com/ (which Darryl fleshes out a bit). Once you have installed node.js you can install Phant in about 4 minutes by using the command
sudo npm install -g phant
[sudo because we want to install into a system directory so all users can run phant so we need root privs temporarily, npm to execute the node package manager (as root), -g to install it globally (see reasons earlier re: why sudo) phant the actual software]
Once Phant has been installed you can start it using the command
(because you installed it globally a symlink has been created in /usr/local/bin to run the phant start up script.
ls -al /usr/local/bin/phant lrwxrwxrwx 1 root staff 36 Jan 10 21:59 /usr/local/bin/phant -> ../lib/node_modules/phant/.bin/serve
After a little while you'll see something similar to [email protected] ~/custphant $ phant phant http server running on port 8080 phant telnet server running on port 8081
The version of Phant that is available in that github repo is slightly crippled compared to the version running on data.sparkfun.com however, the reason that has been given is perfectly reasonable. The reasons i found while googling for info on Phant is “The web UI is kind of resource heavy for use on things like the Beaglebone and Raspberry pi”. This means that using Phant on your Raspberry Pi is a little different to what your are used to if you have previously used data.sparkfun.com. To create a stream you telnet into the Raspberry Pi
and type create to start the stream creation process
Something along the lines of the above screenshot. Make a note of the Public, Private & Delete keys & put them somewhere safe as you can never get them back if you forget them & you’ll need at least the Public and Private keys to do anything with the stream.
Now that a stream is created you’ll want to push data to it and retrieve data from it. To do this you use the http server part of Phant.
e.g. in my case with Phant running on 192.168.0.6:8080 (you could use something like raspberrypi.local if you’ve set that up) i’d use
so to push data to the stream I created above i’d use
Which if I have got both keys & the fieldname correct will give you a webpage (in browser) similar to
Of course you don’t have to use a webbrowser to push data to Phant. You could use curl or any method to push data to an http server that you want. for more info see http://phant.io/docs/input/http/
Now that you have some data stored in Phant eventually you will want to retrieve it. To extract your data stream you again use a url but with a slightly different format.
This time instead of /input/….. you use just need your public key & you append the format you’d like the data in. In the version we have installed you have two choices, CSV & JSON. So you d/l the data for the stream we created and push to i’d use the url
for the json version of the data giving
or for csv
Again as with inputting data you can use curl or any other method you want to retrieve the data you’ve pushed. see http://phant.io/docs/output/http/ for more details.
I have to go and make something to eat (reheat the neverending red soup that will still be with us for another week at least ) for the kid & wife so i’ll write up how to install & use Phant with a Web UI on the Raspberry Pi a little later.