2014-09-10 5 views
2

ds18b20 온도 센서에서 라즈베리 파이를 사용하여 데이터를 읽고 xively로 푸시합니다.파이썬 : 라즈베리 파이가있는 센서 데이터를 잠깐 동안 푸시하는 동안 오류가 발생했습니다. TypeError : __init __()

몇 가지 전제 조건의 실행 및 파이썬 콘솔에서 파일을

Traceback (most recent call last): 
    File "xively_ds18b20.py", line 59, in <module> 
    run() 
    File "xively_ds18b20.py", line 42, in run 
    feed = api.feeds.get(FEED_ID) 
    File "/home/pi/xively_tutorial/.envs/venv/local/lib/python2.7/site-packages/xively/managers.py", line 266, in get 
    feed = self._coerce_feed(data) 
    File "/home/pi/xively_tutorial/.envs/venv/local/lib/python2.7/site-packages/xively/managers.py", line 289, in _coerce_feed 
    feed = Feed(**feed_data) 
TypeError: __init__() got an unexpected keyword argument 'email' 

어떻게 내가이 오류를 해결할 수 있습니다 :이 후

sudo modprobe w1-gpio && sudo modprobe w1_therm 
source .envs/venv/bin/activate 
FEED_ID=244127069 API_KEY=Nqeje SENSOR_ID=28-00000539324e python xively_ds18b20.py 

, 다음과 같은 오류가있어? 그것은 재미 있지만, 다른 라즈베리 파이에 여기

내 코드 (xively_ds18b20.py)의 ... 작동하고 다음에서 이메일 주소를 제거하여

#!/usr/bin/env python 

import os 
import xively 
import subprocess 
import time 
import datetime 
import requests 


FEED_ID = os.environ["FEED_ID"] 
API_KEY = os.environ["API_KEY"] 
SENSOR_ID_PRE = os.environ["SENSOR_ID"] 
SENSOR_ID = SENSOR_ID_PRE[-7:] 

# initialize api client 
api = xively.XivelyAPIClient(API_KEY) 

# function to read the temperature from ds18b20 temperature sensor on i2c 
def read_temperature(): 
    tempfile = open("/sys/bus/w1/devices/"+SENSOR_ID_PRE+"/w1_slave") 
    thetext = tempfile.read() 
    tempfile.close() 
    tempdata = thetext.split("\n")[1].split(" ")[9] 
    temperature = float(tempdata[2:]) 
    temperature = temperature/1000 
    return temperature 

# function to return a datastream object. This either creates a new datastream, 
# or returns an existing one 
def get_datastream(feed): 
    try: 
    datastream = feed.datastreams.get("PiTemperature"+SENSOR_ID) 
    return datastream 
    except: 
    datastream = feed.datastreams.create("PiTemperature"+SENSOR_ID, tags="temperature") 
    return datastream 

# main program entry point - runs continuously updating our datastream with the 
# latest temperature reading 
def run(): 
    feed = api.feeds.get(FEED_ID) 

    datastream = get_datastream(feed) 
    datastream.max_value = None 
    datastream.min_value = None 

    while True: 
    degreesCelcius = read_temperature() 
    datastream.current_value = degreesCelcius 
    datastream.at = datetime.datetime.utcnow() 
    try: 
     datastream.update() 
    except requests.HTTPError as e: 
     print "HTTPError({0}): {1}".format(e.errno, e.strerror) 

    time.sleep(10) 

run() 
+2

작동하지 않는 코드를 제공해 주시겠습니까? – Nilesh

+1

안녕하세요, 코드는 xively_ds18b20.py 파일에 있습니다.이 파일은 제 질문에 게시했습니다. – mcknight

+3

글쎄, 피드처럼 보입니다. 244127069 피드 개체가 예상치 못한 이메일이 있습니다 ... 피드를 검사하고 그 내용을 알려주십시오. – user3012759

답변

3

this bug report에 따르면, 당신은이 문제를 해결할 수 있습니다 공급 메타 : 나는 latest source code on github 볼 때

When I removed my e-mail address from the Feed Metadata (through the workbench) and re-ran api.feeds.get(FEED_ID) it worked just fine.

는, 나는 email가 지원되는지 확인할 수 있습니다

,
class Feed(Base): 
    """Xively Feed, which can contain a number of Datastreams. 
    :param title: A descriptive name for the feed 
    :param description: A longer text description of the feed 
    :param website: The URL of a website which is relevant to this feed e.g. 
    home page 
    :param email: A public contact email address for the provider of this feed 
    :param tags: Tagged metadata about the environment (characters ' " and 
    commas will be stripped out) 
    :param location: :class:`.Location` object for this feed 
    :param private: Whether the environment is private or not. 
    :type private: bool 
    Usage:: 
    >>> import xively 
    >>> xively.Feed(title="Xively Office environment") 
    <xively.Feed(None)> 
    """ 
    VERSION = "1.0.0" 
    # Set id and feed directly as they aren't part of state. By setting them on 
    # the class they won't get entered into _data and will be set on the 
    # instance itself. 
    id = None 
    feed = None 
    _datastreams_manager = None 
    def __init__(self, title, description=None, website=None, email=None, 
    tags=None, location=None, private=None, datastreams=None): 

It seems this bug was only fixed recently (June 27th). github에서 xively-python의 최신 버전을 제거하고 사용중인 현재 버전 대신 사용할 수 있습니까?

+1

필자는'pip install xively-python --upgrade'를 사용하여 최신 버전을 설치했습니다 ... 그러나'요구 사항은 이미 최신 버전입니다 : xively-python in ./.envs/venv/lib/python2. 7/site-packages 요구 사항이 이미 업데이트되었습니다. 요청> = 1.1.0 ./envs/venv/lib/python2.7/site-packages (xively-python에서) 정리 중 ... ' . 그 후, 나는 이전과 같은 오류가 나타납니다 – mcknight

+2

@ mcknight 나는이 변경 사항이 포함 된 새 버전이 공식적으로 아직 출시되지 않았다고 생각하지 않습니다. 수동으로 패치를 적용하거나 git을 사용하여 최신 코드를 풀고 소스에서 설치해야합니다. – dano

+2

@mcknight git에서 설치하는 것은'git clone https://github.com/xively/xively-python.git; cd xively-python; sudo python setup.py install'을 실행하십시오. 당신은 아마 당신이 이미 가지고있는 xively의 버전을 제거해야합니다. – dano