Introduction: PcDuino As Networked Device to Feed Data to Xively (Internet of Things)

Picture of 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

Picture of 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

Picture of Register at Xively

We need to register at xively.com for a free Developer account.

Step 5: Pyhton Code

Picture of 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
# 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:

Comments

About This Instructable

2,461views

24favorites

License:

More by jingfeng:pcDuino as Networked Device to feed data to Xively (Internet of Things)SDR on pcDuinoA Piano with Banana as Keyboard powered by pcDuino
Add instructable to: