2014-07-24 6 views
3

Xively의 피드에 일부 임시 데이터를 업로드하려고하지만 수명이 다되어서 작동하지 않습니다! 데이터는 RP1에 의해 읽히고 인쇄되지만 아무 데이터도 Xively에 푸시되지 않습니다. 튜토리얼 코드를 사용했고 푸시 데이터를 가질 수 있었지만 자체 코드로 복제 할 수는 없습니다. 나는 오류가 없다.Xively로 데이터를 게시 할 수 없습니다

#!/usr/bin/env python 

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

# extract feed_id and api_key from environment variables 
FEED_ID = 1374874100 
API_KEY = 'ONdefUJlt3d5cifAvTYocqvOPm824F3P1QnT99OtdKQpL7ZD' 
DEBUG = 'TRUE' 


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

os.system('modprobe w1-gpio') 
os.system('modprobe w1-therm') 

# My temp probe details 
base_dir = '/sys/bus/w1/devices/' 
device1_folder = glob.glob(base_dir + '28-00000503b862')[0] 
device1_file = device1_folder + '/w1_slave' 

# Function to read temp sensor 
def read_temp_raw(): 
    f = open(device1_file, 'r') 
    lines = f.readlines() 
    f.close() 
    return lines 

def read_temp(): 
     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:] 
       temp_c = float(temp_string) /1000 
       return temp_c 

while True: 
     print("Temp is currently...", read_temp()) 
     time.sleep(5) 


# 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("FermTemp") 
    if DEBUG: 
     print "Found existing datastream" 
    return datastream 
    except: 
    if DEBUG: 
     print "Creating new datastream" 
    datastream = feed.datastreams.create("FermTemp", tags="temp_01") 
    return datastream 


# main program entry point - runs continuously updating our datastream with the 
# current temps 
def run(): 
    print "Getting Fermentation Temps" 

    feed = api.feeds.get(FEED_ID) 

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

    while True: 
    FermentationTemp = read_temp() 
    datastream.current_value = FermentationTemp 
    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() 

이 최대한 빨리 임시 데이터를 정의하는 비트를 걸릴 것처럼, 그 다음 관련 Xively 채널에 연결 행복 보인다.

답변

1

'FermentationTemp'변수의 반환 유형을 확인하십시오. 문자열에 'FermentationTemp'을 입력하고 시도해보십시오.