Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 向xively发送树莓Pi数据流_Python_Raspberry Pi_Xively - Fatal编程技术网

Python 向xively发送树莓Pi数据流

Python 向xively发送树莓Pi数据流,python,raspberry-pi,xively,Python,Raspberry Pi,Xively,我让我的rpi通过RS232连接到数字秤,MAX3232串行端口/ttl模块连接到GPIO。使用此代码成功地从磅秤流式收集重量数据(数据以20块为单位,重量为11-14)。这会在终端本地打印出来: import serial import time ser = serial.Serial("/dev/ttyAMA0") read = ser.read(20) def get_num(read): return float(''.join(ele for ele in read if

我让我的rpi通过RS232连接到数字秤,MAX3232串行端口/ttl模块连接到GPIO。使用此代码成功地从磅秤流式收集重量数据(数据以20块为单位,重量为11-14)。这会在终端本地打印出来:

import serial
import time

ser = serial.Serial("/dev/ttyAMA0")
read = ser.read(20)

def get_num(read):
    return float(''.join(ele for ele in read if ele.isdigit() or ele == '.'))

while True:
    print(get_num(read))
    time.sleep(2)
这很好,但我的python代码将数据流发送到xively并不太好

def get_num(read):
    return float(''.join(ele for ele in read if ele.isdigit() or ele == '.'))

# 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("(get_num(read))")
        return datastream
    except:
        datastream = feed.datastreams.create("(get_num(read))", tags = "weight")
        return datastream
def run():
    feed = api.feeds.get(FEED_ID)
    datastream = get_datastream(feed)
    datastream.max_value = None
    datastream.min_value = None

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

        time.sleep(5)

run()
它在空闲状态下检查为OK,但在运行时会产生如下错误:

Traceback (most recent call last):
File "xivelycodescales.py", line 51, in <module>
run()
File "xivelycodescales.py", line 36, in run
datastream = get_datastream(feed)
File "xivelycodescales.py", line 32, in get_datastream
datastream = feed.datastreams.create("(get_num(read))")
File "/usr/local/lib/python2.7/dist-packages/xively/managers.py", line 416, in create
response.raise_for_status()
File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 773, in     raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 422 Client Error:
回溯(最近一次呼叫最后一次):
文件“xivelycodescales.py”,第51行,在
运行()
文件“xivelycodescales.py”,第36行,正在运行
数据流=获取数据流(提要)
get_数据流中第32行的文件“xivelycodescales.py”
datastream=feed.datastreams.create(“(get_num(read))”)
文件“/usr/local/lib/python2.7/dist packages/xively/managers.py”,第416行,在create中
响应。针对_状态()提出_
文件“/usr/local/lib/python2.7/dist packages/requests/models.py”,第773行,处于raise_for_状态
引发HTTPError(http\u error\u msg,response=self)
requests.exceptions.HTTPError:422客户端错误:
我可以看到错误类型是什么-并且在RPI论坛上得到了很好的帮助。但我不知道我哪里出了错

非常感谢