所有
我一直在为我的RPi工作温度读数器,并成功编写了我的RPi以读取温度。我现在想要将数据发送到Xively,但我不断收到错误消息......
追踪(最近一次通话): 文件" xively.py",第75行,in pac.put() 文件" /usr/local/lib/python2.7/dist-packages/Python_EEML-0.1-py2.7.egg/eeml/datastream.py" ;,第66行放入 提高异常(resp.reason) 例外:未经授权
这是我的代码......
#!/usr/bin/env python 2.7.3
import os
import glob
import time
import json
import subprocess
import eeml
import sys
import syslog
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
# add more sensor variables here based on your setup
temp_0 = 0
temp_1 = 0
for sensors in range (2): # change number of sensors based on your setup
base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[sensors]
device_file = device_folder + '/w1_slave'
print device_file
print sensors
def read_temp_raw(): # gets the temps one by one
f = open(device_file, 'r')
lines = f.readlines()
f.close()
return lines
def read_temp(): # checks the temp recieved for errors
lines = read_temp_raw()
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = read_temp_raw()
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
# set proper decimal place for C
temp = float(temp_string) / 1000.0
# Round temp to 2 decimal points
temp = round(temp, 1)
return temp
# ask for temps to be read and store each in a variable
if sensors == 0:
temp_0 = read_temp()
temp_1 = read_temp()
if sensors == 1:
temp_1 = read_temp()
print temp_0
print temp_1
# Log in data for Xively
API_KEY = 'MY API String'
FEED = My FEED ID
API_URL = '/v2/feeds/98727321.xml' .format(feednum = FEED)
# open up your feed
pac = eeml.Pachube(API_URL, API_KEY)
#compile data
pac.update([eeml.Data("Inne", temp_1, unit=eeml.Celsius())])
pac.update([eeml.Data("Ute", temp_0, unit=eeml.Celsius())])
# send data to cosm
pac.put()
任何人都可以帮助我吗?感谢。