Я пытаюсь следовать второй пример кода, показанный на estromsnes по адресу: How to create two y-axes streaming plotlyPython, Plotly и Raspberry Pi [Errno 13]
#!/usr/bin/python
import subprocess
import re
import sys
import time
import datetime
import plotly.plotly as py # plotly library
from plotly.graph_objs import Scatter, Layout, Figure, Data, Stream, YAxis
# Plot.ly credentials and stream tokens
username = 'plotly_username'
api_key = 'plotly_api_key'
stream_token_temperature = 'stream_token_1'
stream_token_humidity = 'stream_token_2'
py.sign_in(username, api_key)
trace_temperature = Scatter(
x=[],
y=[],
stream=Stream(
token=stream_token_temperature
),
yaxis='y'
)
trace_humidity = Scatter(
x=[],
y=[],
stream=Stream(
token=stream_token_humidity
),
yaxis='y2'
)
layout = Layout(
title='Raspberry Pi - Temperature and humidity',
yaxis=YAxis(
title='Celcius'
),
yaxis2=YAxis(
title='%',
side='right',
overlaying="y"
)
)
data = Data([trace_temperature, trace_humidity])
fig = Figure(data=data, layout=layout)
print py.plot(fig, filename='Raspberry Pi - Temperature and humidity')
stream_temperature = py.Stream(stream_token_temperature)
stream_temperature.open()
stream_humidity = py.Stream(stream_token_humidity)
stream_humidity.open()
while(True):
# Run the DHT program to get the humidity and temperature readings!
output = subprocess.check_output(["./Adafruit_DHT", "2302", "17"]);
print output
# search for temperature printout
matches = re.search("Temp =\s+([0-9.]+)", output)
if (not matches):
time.sleep(3)
continue
temp = float(matches.group(1))
# search for humidity printout
matches = re.search("Hum =\s+([0-9.]+)", output)
if (not matches):
time.sleep(3)
continue
humidity = float(matches.group(1))
print "Temperature: %.1f C" % temp
print "Humidity: %.1f %%" % humidity
# Append the data to the streams, including a timestamp
now = datetime.datetime.now()
stream_temperature.write({'x': now, 'y': temp })
stream_humidity.write({'x': now, 'y': humidity })
# Wait 30 seconds before continuing
time.sleep(30)
stream_temperature.close()
stream_humidity.close()
Я задаю новый вопрос, потому что я не мог сделать так далее оригинальный пост.
выход моего терминала из моих B + V1.2 состояний Raspberry Pi Model:
Traceback (самый последний вызов последнего):
File "plotly5.py", line 62, in <module>
output = subprocess.check_output(["./Adafruit_DHT", "2302", "17"]);
File "/usr/lib/python2.7/subprocess.py", line 566, in check output
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
OSError: [Errno 13] Permission denied
А есть ли разрешение настройки я должен изменить? Должен ли я изменить часть ./Adafruit_DHT из:
output = subprocess.check_output(["./Adafruit_DHT", "2302", "17"]);
Спасибо.
Что происходит, когда вы просто запустить эту программу из оболочки? Нужно ли разрешение sudo? –
Спасибо за ответ. Я попробовал это в оболочке Python 2.7.9. Он отвечает теми же сообщениями об ошибках. Я также запускал файл python из терминала с разрешением sudo и появлялись те же сообщения об ошибках. Python 3.4.2 Shell вернула ошибку «недопустимый синтаксис». –
Вы не можете запустить скрипт оболочки из интерпретатора python :) –