Introduction: PcDuino As Networked Device to Feed Data to Xively (Internet of Things)
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.
Step 1: Parts List
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
Step 2: Wire Diagram
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:
Step 3: Install Software Package
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
Step 4: Register at Xively
We need to register at xively.com for a free Developer account.
Step 5: Pyhton Code
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
from adc import analog_read
from requests import HTTPError
print "read channel ADC0 value ,the V-REF = 3.3V"
value = analog_read(5)
temp = value*(3.3/4096*100)
print ("value = %4d"%value)
print ("temperature = %4.3f V" %temp)
feed.datastreams=[ xively.Datastream(id='office_temp', current_value=temp, at=now)
print "Value pushed to Xively: " + str(temp)
except HTTPError as e:
print "Error connecting to Xively: " + str (e)
To run the code:
We can see the data posted at xively.com webpage:
We have a be nice policy.
Please be positive and constructive.