プロットの例に従って、 DHT22センサーを使用してストリーミング温度グラフを正常に作成しました。センサーは、プロットしたい湿度も提供します。
なんとなく可能ですか?次のコードは私が試しているものですが、例外がスローされます:データがグラフにプロットされていません (以下を参照)。plotly.exceptions.PlotlyAccountError: Uh oh, an error occured on the server.
with open('./plotly.conf') as config_file:
plotly_user_config = json.load(config_file)
py.sign_in(plotly_user_config["plotly_username"], plotly_user_config["plotly_api_key"])
streamObj = Stream(token=plotly_user_config['plotly_streaming_tokens'][0], maxpoints=4032)
trace1 = Scatter(x=[],y=[],stream=streamObj,name='Temperature')
trace2 = Scatter(x=[],y=[],yaxis='y2',stream=streamObj,name='Humidity')
data = Data([trace1,trace2])
layout = Layout(
title='Temperature and Humidity from DHT22 on RaspberryPI',
yaxis=YAxis(
title='Celcius'),
yaxis2=YAxis(
title='%',
titlefont=Font(color='rgb(148, 103, 189)'),
tickfont=Font(color='rgb(148, 103, 189)'),
overlaying='y',
side='right'))
fig = Figure(data=data, layout=layout)
url = py.plot(fig, filename='raspberry-temp-humi-stream')
dataStream = py.Stream(plotly_user_config['plotly_streaming_tokens'][0])
dataStream.open()
#MY SENSOR READING LOOP HERE
dataStream.write({'x': datetime.datetime.now(), 'y':s.temperature()})
dataStream.write({'x': datetime.datetime.now(), 'y':s.humidity()})
#END OF MY LOOP
更新 1:
コードを修正したところ、エラーはスローされなくなりました。しかし、まだデータはグラフにプロットされていません。私が得るのは軸だけです: