我有一个运行在raring BBBLack ubuntu映像上的python脚本,它有完美的wiFi工作,但是使用python脚本如下所示我看到脚本运行但是xively仪表板上的Request Log没有收到任何东西?!
是否有可以更新Feed的频率限制?
或者是我的应用程序?我认为它正在运行而不是下降。
这是代码:
#!/usr/bin/env python
import os
import xively
import subprocess
import time
import datetime
import requests
import serial
import re
import string
from select import select
#OS variables and other settings for UART transfer
os.system("sudo chmod 777 -R /sys/devices/bone_capemgr.8/slots")
os.system("sudo echo ttyO1_armhf.com > /sys/devices/bone_capemgr.8/slots")
serial = serial.Serial("/dev/ttyO1", baudrate=9600)
resp = ""
inData = ['']*14
started = False
ended = False
check_point = 0
check_point_listener = 0
# extract feed_id and api_key from environment variables
FEED_ID = "34534"
API_KEY = "blahhblahh"
DEBUG = "DEBUG" or false
DEBUG_listener = "DEBUG" or false
# initialize api client
api = xively.XivelyAPIClient(API_KEY)
# 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("Lock_Controller")
if DEBUG:
print "Found existing datastream"
return datastream
except:
if DEBUG:
print "Creating new datastream"
datastream = feed.datastreams.create("Lock_Controller", tags="ON/OFF")
return datastream
# function to return a datastream object. This either creates a new datastream,
# or returns an existing one
def get_datastream_listener(feed):
try:
datastream_listener = feed.datastreams.get("load_avg")
if DEBUG:
print "Found existing datastream"
return datastream_listener
except:
if DEBUG:
print "Creating new datastream"
datastream_listener = feed.datastreams.create("load_avg", tags="load_01")
return datastream_listener
# main program entry point - runs continuously updating our datastream with the
def run():
print "Script initiation"
#Initializing one channel
feed = api.feeds.get(FEED_ID)
datastream = get_datastream(feed)
datastream.max_value = None
datastream.min_value = None
#Initializing one channel
feed_listener = api.feeds.get(FEED_ID)
datastream_listener = get_datastream_listener(feed_listener)
datastream_listener.max_value = None
datastream_listener.min_value = None
while True:
while serial.inWaiting() > 0:
inChar = serial.read() # Read a character
if inChar =='<': # not sure what to put in if statement to run until end
global started
started = True
global ended
ended = False
index = 0
elif inChar =='>':
global ended
ended = True
if started == True:
inData[index] = inChar # Store it
index = index + 1 # Increment where to write next
#inData[index] = '\0' # Null terminate the string
if ended == True:
global ended
ended = False
index = 0
Data = inData #values of acclerometer like "545X" etc enter and stored in Data
print (Data)
values = "".join(str(v) for v in Data)
print (values)
strData = string.replace(values, "<", "")
strData = string.replace(strData, ">", "")
strData = string.replace(strData, " ", "")
strData = string.replace(strData, "\0", "")
print (strData)
if strData[0] == 's' and strData[1] == 't':
print "Nishant Here"
strData = string.replace(strData, "st", "")
strData = string.replace(strData, "\0", "")
strData = string.replace(strData, " ", "")
print strData
if strData == '1':
print "This is arrived at 1"
global check_point_listener
datastream_listener.current_value = str(check_point_listener) + "h"
datastream_listener.update()
#serial.write("<v0" + str(check_point) + ">") #serial write value
time.sleep(1)
datastream_listener.current_value = 0
datastream_listener.update()
elif strData == '0':
print "This is arrived at 0"
global check_point_listener
datastream_listener.current_value = str(check_point_listener) + "L"
datastream_listener.update()
time.sleep(1)
datastream_listener.current_value = 0
datastream_listener.update()
if DEBUG:
print "Updating Xively feed with value: %s"
global check_point
check_point = 0
datastream = get_datastream(feed)
global check_point
check_point = datastream.current_value
print "AAGYa: %s" % check_point
for x in range(1,61):
#print x
checking = int(check_point)
if x == checking:
print "Got it"
serial.write("<ch" + str(x) + ">")
datastream.current_value = 0
datastream.update()
if DEBUG_listener:
print "Query stuff: %s"
global check_point_listener
check_point_listener = 0
datastream_listener = get_datastream_listener(feed_listener)
global check_point_listener
check_point_listener = datastream_listener.current_value
print "AAGYa: %s" % check_point_listener
check_point_listener = string.replace(check_point_listener, "L", "")
check_point_listener = string.replace(check_point_listener, "h", "")
for x in range(1,61):
#print x
checking = int(check_point_listener)
if x == checking:
print "Got it Query"
serial.write("<Q" + str(x) + ">")
run()
答案 0 :(得分:0)
我的Raspberry pi遇到了同样的问题。
当我重新创建Feed并且不依赖它们时,问题有所改善。
在您的代码中,这意味着您必须移动:
feed = api.feeds.get(FEED_ID)
datastream = get_datastream(feed)
datastream.max_value = None
datastream.min_value = None
#Initializing one channel
feed_listener = api.feeds.get(FEED_ID)
datastream_listener = get_datastream_listener(feed_listener)
datastream_listener.max_value = None
datastream_listener.min_value = None
进入while True:
循环。
希望这对你也有帮助......