0
我試圖讓我的RPi向Xively發送臨時數據,而且我有一段糟糕的時間讓我的代碼工作。這是最新的效應初探當我運行python腳本我得到...這個輸出代表什麼?
Traceback (most recent call last):
File "xively1.py", line 11, in <module>
import xively # for Xively
File "/home/pi/xively/xively.py", line 11, in <module>
FEED_ID = os.environ["736915202"]
File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: '736915202'
有人能向我解釋這是什麼意思,什麼我需要做的正確的嗎?謝謝。
#!/usr/bin/env python
# This program reads two DS18B20 1-wire temperature sensors and sends the values to
# Xively https://xively.com/feeds/360495937
# tempF[0] is the reading from the outdoor tempersture sensor '28-0000059f6ece'
# tempF[1] is the reading from the indoor temperature sensor '28-0000059fa9ce'
outdoor = 0
indoor = 1
import xively # for Xively
import time
import datetime
import os # for 1-wire
import glob # for 1-wire
def read_temp_raw(): #a function that grabs the raw temperatures data from the sensors
f_1 = open(device_file[0], 'r') # first DS18B20
lines_1 = f_1.readlines()
f_1.close()
f_2 = open(device_file[1], 'r') # second DS18B20
lines_2 = f_2.readlines()
f_2.close()
return lines_1 + lines_2
def read_temp(): #a function that checks that the connections were good
lines = read_temp_raw()
while lines[0].strip()[-3:] != 'YES' or lines[2].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = read_temp_raw()
equals_pos = lines[1].find('t='), lines[3].find('t=')
tempC = float(lines[1][equals_pos[0]+2:])/1000, float(lines[3] [equals_pos[1]+2:])/1000
tempF = round(tempC[0] * 9.0/5.0 + 32.0,1), round(tempC[1] * 9.0/5.0 + 32.0,1)
return tempF
def send_to_Xively(TempF):
XIVELY_FEED_ID = "736915202"
XIVELY_API_KEY = "QA6mqStQIqCFLOXtA4tzxiFpv8cqHNaYr1MFjRZdrphGwxYN"
#def send_to_Xively(TempF):
now = datetime.datetime.utcnow()
try:
print "Sending to Xively...",
xivelyapi = xively.XivelyAPIClient(XIVELY_API_KEY)
xivelyfeed = xivelyapi.feeds.get(XIVELY_FEED_ID)
xivelyfeed.datastreams = [
xively.Datastream(id='temp0', current_value=round(TempF[outdoor],1), at=now),
xively.Datastream(id='temp1', current_value=round(TempF[indoor],1), at=now)
]
xivelyfeed.update()
print "OK"
except requests.HTTPError as e:
print "HTTPError({0}): {1}".format(e.errno, e.strerror)
# this part for the 1-wire DS18S20
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
#set up the locations of the sensors in the system
device_folder = glob.glob('/sys/bus/w1/devices/28*')
device_file = [device_folder[0] + '/w1_slave', device_folder[1] + '/w1_slave']
# main program
TempF = read_temp()
send_to_Xively(TempF)
看起來他們試圖將FEED_ID設置爲給定的值,但混合了什麼是關鍵和值是什麼... – errordeveloper
如何設置鍵和設置值?謝謝。 – user3609926