Xively提取当前数据流值

时间:2013-09-17 16:49:42

标签: python python-2.7 xively

我可以使用以下代码提取数据流的最新值但是问题是如果我在Xively仪表板控制台上更改值或更新值,那么代码将无法捕获变化但仍然显示旧值!

# 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()

这是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

1 个答案:

答案 0 :(得分:1)

问题是你在循环之外调用get_datastream()