0

我可以使用以下代码提取数据流的最新值,但问题是,如果我在 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
4

1 回答 1

1

问题是您get_datastream()在循环外调用。

于 2013-09-18T10:42:53.617 回答