Question

I'm able to extract the latest value of the datastream using the following code BUT the problem is that if I change the value or update the value at the Xively dashboard console then the code isn't able to capture the change but still remains displaying the old value!

# main program entry point - runs continuously updating our datastream with the
def run():
  print "Starting Xively tutorial script"

  feed = api.feeds.get(FEED_ID)

  datastream = get_datastream(feed)
  datastream.max_value = None
  datastream.min_value = None

  while True:

    if DEBUG:
      print "Updating Xively feed with value: %s" 
      datastream.at = datetime.datetime.utcnow()
      datastream.update() 
      check_point = datastream.current_value
      print "AAGYa: %s" % check_point
      if check_point == '50':
         outPin = file("/sys/class/gpio/gpio44/value", "w")
         outPin.write("1")
      elif check_point == '':
         outPin = file("/sys/class/gpio/gpio44/value", "w")
         outPin.write("1")
      elif check_point == '':
         outPin = file("/sys/class/gpio/gpio44/value", "w")
         outPin.write("1")

run()

Here's the get_datastream():

# function to return a datastream object. This either creates a new datastream,
# or returns an existing one
def get_datastream(feed):
  try:
    datastream = feed.datastreams.get("load_avg")
    if DEBUG:
      print "Found existing datastream"
    return datastream
  except:
    if DEBUG:
      print "Creating new datastream"
    datastream = feed.datastreams.create("load_avg", tags="load_01")
    return datastream
Was it helpful?

Solution

The problem is that you are calling get_datastream() outside the loop.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top