[vc_row][vc_column width=”1/1″][vc_column_text]Xively (formerly Cosm and before that Pachube (pronounced Patch bay)) is an on-line database service allowing developers to connect sensor-derived data (e.g. energy and environment data from objects, devices & buildings) to the Web and to build their own applications based on that data. It was created in 2007 by architect Usman Haque. Following the nuclear accidents in Japan in 2011, Xively was used by volunteers to interlink Geiger counters across the country to monitor the fallout.
In this post, we will show how to network pcDuino to Xively and feed data to it.
[/vc_column_text][vc_tour][vc_tab title=”Parts List” tab_id=”1393212981-1-35″][vc_column_text]In this tutorial, we use the following parts:
- 1 x pcDuino v2
- 1 x Analog temperature sensor LM35 (part of Advanced Learning Kit for Arduino)
- Several Jumper Wires
- 1 x Plastic mounting plate for pcDuino/Arduino w rubber feet
- 1 x Breadboard
[/vc_column_text][/vc_tab][vc_tab title=”Wire Diagram” tab_id=”1393212981-2-97″][vc_column_text]We wire the analog temperature sensor according to the following way:
- VCC of LM35 -> 3.3V of pcDuino
- GND of LM35 -> Ground of pcDuino
- Output of LM35 -> A5 of pcDuino
The whole setup is shown below:
[/vc_column_text][/vc_tab][vc_tab title=”Install Software Package” tab_id=”1393214380379-2-8″][vc_column_text]We will use Python to develop the project. First, we will need to install the tools:
1. Install Python
$ sudo apt-get install python-dev
2. Install python-pip (python-pip is a package that can be used to install and manage python software)
$ sudo apt-get install python-pippip
3. Install xively extension:
$sudo pip install xively-python
The Python library for pcDuino can be downloaded from github at: https://github.com/pcduino/python-pcduino using the following command:
$git clone https://github.com/pcduino/python-pcduino
[/vc_column_text][/vc_tab][vc_tab title=”Register at xively” tab_id=”1393214814382-3-9″][vc_column_text]We need to register at xively.com for a free Developer account.
After we opened the account, we move forward to register the device and create a channel named ‘office_temp’. Write down the API key and feed ID.[/vc_column_text][/vc_tab][vc_tab title=”Python Code” tab_id=”1393215556869-4-8″][vc_column_text]The python code can be downloaded at: https://github.com/pcduino/python-pcduino/blob/master/Samples/adc_test/xively-temp.py
# part of the python code is copied from page 82 of Getting Started with BeagleBone, by Matt Richardson # Jingfeng Liu # LinkSprite.com/pcDuino.com from adc import analog_read import time import datetime import xively from requests import HTTPError api =xively.XivelyAPIClient("APIKEY") feed=api.feeds.get(FEEDID) def delay(ms): time.sleep(1.0*ms/1000) def setup(): print "read channel ADC0 value ,the V-REF = 3.3V" delay(3000) def loop(): while True: value = analog_read(5) temp = value*(3.3/4096*100) print ("value = %4d"%value) print ("temperature = %4.3f V" %temp) now=datetime.datetime.utcnow() feed.datastreams=[ xively.Datastream(id='office_temp', current_value=temp, at=now) ] try: feed.update() print "Value pushed to Xively: " + str(temp) except HTTPError as e: print "Error connecting to Xively: " + str (e) time.sleep(20) def main(): setup() loop() main()
To run the code:
$python sively-temp.py
We can see the data posted at xively.com webpage:
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.