jueves, 29 de mayo de 2014

Lab 7.1 Uploading sensor data to Visualization Platforms

Realizado por Vanessa Alcaraz & Sergi Martín.

En este laboratorio hemos utilizado la plataforma xively.com para poder almacenar y visualizar en una gráfica los datos que va recibiendo la Xbee coordinator API (conectada al ordenador).
Los datos que recibe son enviados desde la Xbee router AT, en la que hay conectados un sensor de luminosidad y un sensor de temperatura.

El material usado para este laboratorio:



El esquema del circuito:



El código:

import commands
import json
import serial
import time
import os
from serial import SerialException
from xbee import ZigBee

print 'Asynchronously printing data from remote XBee'

serial_port = serial.Serial('/dev/ttyUSB0', 9600)

def print_data(data):
      """
      This method is called whenever data is received.
      Its only argument is the data within the frame.
      """
      # Create a JSON file and fill it with the received samples
      json_data = {}
      json_data['version'] = '0.2'
      json_data['datastreams'] = ()
      json_data['datastreams'] = json_data['datastreams'] + ({'id': 'Lightness', 'current_value':                             str(data['samples'][0].values()[0])},)
      json_data['datastreams'] = json_data['datastreams'] + ({'id': 'Temperature', 'current_value':                         str(data['samples'][0].values()[1])},)
      # Add more datastreams if needed
      with open('Xbee2Xively.json', mode='w') as f:
          json.dump(json_data, f, indent = 4)
      # Upload information to Xively. Use your own Api Key and feed identifier
      os.popen('curl --request PUT --data-binary @Xbee2Xively.json --header "X-                                           ApiKey:AfO5drfGQGxJypnpbqZeq62HRgk78eNq3ZFJdU9WOi0uTAHq" --verbose                             https://api.xively.com/v2/feeds/211887731')

zigbee = ZigBee(serial_port, escaped = True, callback = print_data)

time.sleep(200)

zigbee.halt();
serial_port.close()


Vídeo con la demostración del resultado al ejecutar el código:


No hay comentarios:

Publicar un comentario