这个输出代表什么?

时间:2014-05-14 01:57:22

标签: python module xively

我试图让我的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)

2 个答案:

答案 0 :(得分:1)

xively模块期待环境变量&#34; 736915202&#34;要设置。它不是,所以它会抛出异常。

但这似乎是一个非常奇怪的环境变量。 /home/pi/xively/xively.py是第三方模块,还是你写的?如果您编写了该文件,但是您希望调用import xively来导入第三方模块,则应将/home/pi/xively/xively.py重命名为其他内容,这可能会解决您的问题。

答案 1 :(得分:0)

public class AnimalPrinter

{

public void printDog()

{

System.out.println("dog");

}

 

public void printCat()

{

System.out.println("cat");

}

/* constructors not shown */

}