十四、不接受货到付款

2024-04-23 19:42:21 发布

您现在位置:Python中文网/ 问答频道 /正文

全部

我一直在为我的RPi开发一个温度读取器,并成功地将我的RPi编程为读取温度。我现在想把数据发送到Xively,但我一直收到一条错误消息。。。你知道吗

回溯(最近一次呼叫): “文件”十四.py“,第75行,in pac.put公司() 文件“/usr/local/lib/python2.7/dist-packages/Python\EEML-0.1-py2.7.egg/EEML/数据流.py“,第66行输入 引发异常(责任理由) 例外:未经授权你知道吗

这是我的密码。。。你知道吗

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

有人能帮帮我吗?谢谢。你知道吗


Tags: inimportapiforreadosdevicetemp