2014-05-14 3 views
0

임시 데이터를 Xive로 보내는 RPi를 얻으려고 노력하고 있으며 코드를 작동시키는 데 끔찍한 시간을 보내고 있습니다. 이 이 출력은 무엇을 나타 냅니까?

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' 

사람이 무엇을 의미하는지 내가 해결해야 할 일을 나에게 설명 할 수 ... 내가 파이썬 스크립트를 실행할 때 내가 얻을 최신 reponse입니까? 감사.

#!/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) 

답변

1

xively 모듈에는 환경 변수 "736915202"가 설정 될 것으로 예상됩니다. 그것은 아닙니다, 그래서 그것은 예외를 던지고 있습니다.

설정이 매우 이상한 환경 변수처럼 보입니다. /home/pi/xively/xively.py 타사 모듈입니까, 아니면 작성 했습니까? 해당 파일을 작성했지만 import xively에 타사 모듈을 가져 오기를 기대하는 경우 /home/pi/xively/xively.py의 이름을 다른 것으로 변경해야 문제가 해결 될 것입니다.

+0

그들은 'FEED_ID'를 주어진 값으로 설정하려하지만 키와 값이 섞여있는 것 같습니다 ... – errordeveloper

+0

어떻게 키를 설정하고 값을 설정합니까? 감사. – user3609926

관련 문제