This is an old revision of the document!
Data Transmission to the Cloud
Data collected from the Wireless Sensor Nodes can be aggregated by the gateway and sent for processing and analysis to a Cloud platform. There is a large array of options for Cloud platforms, such as DeviceHub, ThingSpeak, SmartLiving, NimBits, Xively, etc.
In this tutorial we will use DeviceHub to aggregate data from multiple Sparrow nodes and use their API to also send commands back to the nodes.
DeviceHub
To gain access, you will need to first create an account on the platform. After registering and logging in, select Project > New Project, and give your project a name. Initially, your project will be assigned a Project ID and an API Key, which will serve to identify it on the platform.
Next, you need to add a new device to your project, by selecting Add Device. Name the device, select “Other” from “Device Type”, “Python” from “Programming Language” and “Ethernet” or “WiFi” from Connection Type. After creation, the device will gain a Device UUID. Each device can have multiple sensors and actuators, which can be added through the web interface.
For starters, attach a new sensor to your device using the Add Sensor button. Name it “Temperature”, sensor type should be “Analogic” and fill in “deg. C” in the “Measuring Unit” field.
DeviceHub uses an API through which multiple IoT platforms can connect directly to its cloud services. As the Sparrow nodes do not have WiFi or Ethernet connectivity, we will first use a PC as a DeviceHub client. The Sparrow node will send data through the serial port to the PC, and the PC will run a small Python script to parse incoming data and send them to DeviceHub.
You will need to install Python 2.7.x on your machine and also the devicehub library , which can be easily done from the command line using pip:
> pip install devicehub
Data Transmission
Next, we will write a small Python program to send data into our DeviceHub account. Use as a reference the code below and fill in the PROJECT_ID, DEVICE_UUID and API_KEY fields with your own values:
from devicehub import Sensor, Device, Project from time import sleep from random import randint PROJECT_ID = 'your project ID' DEVICE_UUID = 'your Device UUID' API_KEY = 'your API KEY' AN_SENSOR_NAME = 'Temperature' #make sure your sensor has the same name on DeviceHub! def analog_input(dev, sensor): value = randint(0, 1023) sensor.addValue(value) dev.send() print value return project = Project(PROJECT_ID, ssl_verify=False) device = Device(project, DEVICE_UUID, API_KEY) AN1 = Sensor(Sensor.ANALOG, AN_SENSOR_NAME) device.addSensor(AN1) while True: analog_input(device, AN1) sleep(5.0)
The code will send random data to your DeviceHub account, which you will be able to view in real-time.
Now, let's send some real sensor data! We will program the sensor nodes to send temperature values through the serial interface, which will be further parsed by the Python code and sent to DeviceHub.