I'm sending data from a python script for two channels: Average_CPU_load and Average_temp. According to debugger I can see that information is received for both datastreams but it seems that only one graphic is working (average_CPU_load) while the other (Average_Temp) does not display data. Is it a bug from xively or it's something I'm doing wrong?
Thank you!
You may view the feed here: https://xively.com/feeds/1006340696 And the python script is below:
#!/usr/bin/env python
import os
import xively
import subprocess
import time
import datetime
import requests
import serial
# extract feed_id and api_key from environment variables
FEED_ID = os.environ["FEED_ID"]
API_KEY = os.environ["API_KEY"]
DEBUG = os.environ["DEBUG"]
# initialize api client
api = xively.XivelyAPIClient(API_KEY)
# function to read 1 minute load average from system uptime command
def read_loadavg():
# if DEBUG:
# print "Reading load average"
return subprocess.check_output(["awk '{print $1}' /proc/loadavg"], shell=True)
#stty -F /dev/ttyUSB0 cs8 9600 raw ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iext$
ser = serial.Serial('/dev/ttyUSB1',9600,timeout=1)
#ser.flush()
# function to return a datastream object. This either creates a new datastream,
# or returns an existing one
def temp_dstream(feed):
try:
datastream = feed.datastreams.get("Average_temp")
if DEBUG:
print "Found existing datastream"
return datastream
except:
if DEBUG:
print "Creating new datastream"
datastream = feed.datastreams.create("Average_temp", tags="temp_01")
return datastream
def load_dstream(feed):
try:
datastream = feed.datastreams.get("Average_CPU_load")
if DEBUG:
print "Found existing datastream"
return datastream
except:
if DEBUG:
print "Creating new datastream"
datastream = feed.datastreams.create("Average_CPU_load", tags="load_01")
return datastream
# main program entry point - runs continuously updating our datastream with the
# current 1 minute load average
def run():
# print "Starting Xively tutorial script"
feed = api.feeds.get(FEED_ID)
temp_datastream = temp_dstream(feed)
temp_datastream.max_value = None
temp_datastream.min_value = None
load_datastream = load_dstream(feed)
load_datastream.max_value = None
load_datastream.min_value = None
buffer = ''
temperature = ''
while True:
load_avg = read_loadavg()
buffer = buffer + ser.read(ser.inWaiting())
if '\n' in buffer:
lines = buffer.split('\n')
temperature = lines[-2]
buffer = lines [-1]
# if DEBUG:
# print "Updating Xively feed with value: %s" % temperature
temp_datastream.current_value = temperature
temp_datastream.at = datetime.datetime.utcnow()
try:
temp_datastream.update()
except requests.HTTPError as e:
print "HTTPError({0}): {1}".format(e.errno, e.strerror)
load_datastream.current_value = load_avg
load_datastream.at = datetime.datetime.utcnow()
try:
load_datastream.update()
except requests.HTTPError as e:
print "HTTPError({0}): {1}".format(e.errno, e.strerror)
time.sleep(30)
run()