Installing Sparkfun’s Phant on a Raspberry Pi

phanttelnetLast 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

phant

(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

phanttelnet
Type help to get the menu

phanttelnet1

and type create to start the stream creation process

phanttelnet2

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

http://192.168.0.6:8080/input/PUBLIC_KEY?private_key=PRIVATE_KEY&FIELD1=VALUE1&=FIELD2=VALUE2

so to push data to the stream I created above i’d use

http://192.168.0.6:8080/input/QLOqmMdQkBh1lpaZ1KZNFGqaALm?private_key=3036rwX5l2HrKnP3rE3pUYnmZ02&testdata=aardviarkian

Which if I have got both keys & the fieldname correct will give you a webpage (in browser) similar to

phantweb1

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.

http://192.168.0.6:8080/output/PUBLIC_KEY.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

http://192.168.0.6:8080/output/QLOqmMdQkBh1lpaZ1KZNFGqaALm.json

for the json version of the data giving

 [{"testdata":"aardviarkian","timestamp":"2015-01-11T19:35:20.090Z"}]

or for csv

http://192.168.0.6:8080/output/QLOqmMdQkBh1lpaZ1KZNFGqaALm.csv

giving

testdata,timestamp
aardviarkian,2015-01-11T19:35:20.090Z

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.

As I said earlier the version of Phant in that github repo is slightly crippled (for possibly good reasons) and although it does work well when scanning the documentations i noticed that there seemed to be things you could do on data.sparkfun.com that you can’t do with this version and i got a bit jealous so had a dig around in the javascript source and gave up quite quickly as I know sweet f.a. about javascript and was about to just accept that all the shineys were not for self-hosted Phant and go to sleep (it was 2am) when I noticed that not only was there an interestingly named repo phant-manager-http but also an interesting page on sparkfun’s version. https://data.sparkfun.com/config oooooer what does that do? and can we use it on the Raspberry Pi?

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.

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

 

russelldavis.org © 2014 Frontier Theme