python, сюжетно, raspberry pi - онлайн стриминг не работает - PullRequest
0 голосов
/ 28 мая 2020

Привет, в течение нескольких лет я плотно использовал функцию онлайн-трансляции. Без каких-либо изменений кода он перестал работать, потому что RPi устарел (SSL). Затем я загрузил новый raspbian и плотно из пакета python -plotly debian.

Теперь я вижу несколько предупреждений об устаревших вызовах.

/usr/lib/python2.7/dist-packages/plotly/graph_objs/_deprecations.py:504: DeprecationWarning:                                                                                          

plotly.graph_objs.Stream is deprecated.                                                    
Please replace it with one of the following more specific types                            
  - plotly.graph_objs.scatter.Stream                                                       
  - plotly.graph_objs.area.Stream                                                          


/usr/lib/python2.7/dist-packages/plotly/graph_objs/_deprecations.py:372: DeprecationWarning:

plotly.graph_objs.Line is deprecated.
Please replace it with one of the following more specific types
  - plotly.graph_objs.scatter.Line
  - plotly.graph_objs.layout.shape.Line
  - etc.


/usr/lib/python2.7/dist-packages/plotly/graph_objs/_deprecations.py:531: DeprecationWarning:

plotly.graph_objs.XAxis is deprecated.
Please replace it with one of the following more specific types
  - plotly.graph_objs.layout.XAxis
  - plotly.graph_objs.layout.scene.XAxis


/usr/lib/python2.7/dist-packages/plotly/graph_objs/_deprecations.py:558: DeprecationWarning:

plotly.graph_objs.YAxis is deprecated.
Please replace it with one of the following more specific types
  - plotly.graph_objs.layout.YAxis
  - plotly.graph_objs.layout.scene.YAxis


/usr/lib/python2.7/dist-packages/plotly/graph_objs/_deprecations.py:39: DeprecationWarning:

plotly.graph_objs.Data is deprecated.
Please replace it with a list or tuple of instances of the following types
  - plotly.graph_objs.Scatter
  - plotly.graph_objs.Bar
  - plotly.graph_objs.Area
  - plotly.graph_objs.Histogram
  - etc.

Я попытался устранить эти предупреждения и также использовал последние примеры потоковой передачи, но проблема та же.

Здесь висит код:

py.plot(fig, filename='My Plot')

после вызова он сидит там неограниченное время по неизвестной причине. Я не знаю, как отладить это или выяснить, почему это происходит.

Я также пробовал py.iplot() с тем же результатом

Не могли бы вы мне помочь? Как заставить его снова работать. Я использую Python 2.7.

Вот мой исходный код:

    import plotly.plotly as py
    from plotly.graph_objs import Scatter, Layout, Figure, Data, Stream, XAxis, YAxis, Legend, Line

    while True:
        if plotly_running == 0:
            break
        else:
            time.sleep(1)
            print "Waiting for plotly thread to end.."

    with open('./config.json') as config_file:
        plotly_user_config = json.load(config_file)

    trace_a = Scatter(
        x=[],
        y=[],
        stream=Stream(
            token=plotly_user_config['plotly_streaming_tokens'][0],
            maxpoints=1000
        ),
        yaxis='y',
        name='A',
        line=Line(
            color="blue"
        ),
    )

    trace_b = Scatter(
        x=[],
        y=[],
        stream=Stream(
            token=plotly_user_config['plotly_streaming_tokens'][1],
            maxpoints=1000
        ),
        xaxis='x2',
        yaxis='y2',
        name='B',
        line=Line(
            color="rgb(212, 189, 74)"
        ),
    )

    trace_e = Scatter(
        x=[],
        y=[],
        stream=Stream(
            token=plotly_user_config['plotly_streaming_tokens'][4],
            maxpoints=1000
        ),
        yaxis='y',
        name='C',
        line=Line(
            color="green"
        ),
    )

    trace_c = Scatter(
        x=[],
        y=[],
        stream=Stream(
            token=plotly_user_config['plotly_streaming_tokens'][3],
            maxpoints=1000
        ),
        yaxis='y',
        name='D',
        line=Line(
            color="red"
        ),
    )

    trace_d = Scatter(
        x=[],
        y=[],
        stream=Stream(
            token=plotly_user_config['plotly_streaming_tokens'][2],
            maxpoints=1000
        ),
        xaxis='x2',
        yaxis='y2',
        name='F',
        line=Line(
            color="orange"
        ),
    )

    trace_f = Scatter(
        x=[],
        y=[],
        stream=Stream(
            token=plotly_user_config['plotly_streaming_tokens'][5],
            maxpoints=500
        ),
        xaxis='x2',
        yaxis='y2',
        name='G',
        line=Line(
            color="purple"
        ),
    )

    layout = Layout(
        title='My Plot Data',
        showlegend=True,
        width=600,
        height=600,
        autosize=True,

        xaxis=XAxis(
            anchor='y'
        ),
        xaxis2=XAxis(
            anchor='y2'
        ),
        yaxis=YAxis(
            title='Temp [C]',
            domain=[0.6, 1]
        ),
        yaxis2=YAxis(
            title='Common',
            range=[0, 100.0],
            domain=[0, 0.4]
        )
    )

    data = Data([trace_a, trace_b, trace_c, trace_d, trace_e, trace_f])
    fig = Figure(data=data, layout=layout)

    py.sign_in(plotly_user_config["plotly_username"], plotly_user_config["plotly_api_key"])

    print py.plot(fig, filename='My Plot')


    stream_a = py.Stream(plotly_user_config['plotly_streaming_tokens'][0])
    stream_a.open()

    stream_b = py.Stream(plotly_user_config['plotly_streaming_tokens'][1])
    stream_b.open()

    stream_c = py.Stream(plotly_user_config['plotly_streaming_tokens'][4])
    stream_c.open()

    stream_d = py.Stream(plotly_user_config['plotly_streaming_tokens'][3])
    stream_d.open()

    stream_e = py.Stream(plotly_user_config['plotly_streaming_tokens'][2])
    stream_e.open()

    stream_f = py.Stream(plotly_user_config['plotly_streaming_tokens'][5])
    stream_f.open()

    while True:
        time.sleep(1)

        # write the data to plotly
        try:
            stream_a.write({'x': datetime.datetime.now(), 'y': "%.2f" % a})
            stream_b.write({'x': datetime.datetime.now(), 'y': "%.2f" % b})
            stream_d.write({'x': datetime.datetime.now(), 'y': "%.2f" % c})
            stream_e.write({'x': datetime.datetime.now(), 'y': "%.3f" % d})
            stream_c.write({'x': datetime.datetime.now(), 'y': "%.2f" % e})
            stream_f.write({'x': datetime.datetime.now(), 'y': "%.2f" % f})
        except Exception, e:
            print "> Plotly - " + str(e)
...