Ejemplo n.º 1
0
def init_plotly_stream():
    # init credentials
    with open('./credentials.json') as credentials_file:
        plotly_user_config = json.load(credentials_file)

    # authenticate with provided credentials
    plot.sign_in(plotly_user_config["plotly_username"],
                 plotly_user_config["plotly_api_key"])

    # configure the plot
    url = plot.plot([{
        'x': [],
        'y': [],
        'type': 'scatter',
        'mode': 'lines+markers',
        'stream': {
            'token': plotly_user_config['plotly_streaming_tokens'][0],
            'maxpoints': 200
        },
    }],
                    filename='MS-Temperature')

    print("View your streaming graph here: ", url)

    # attach a stream to the plot
    stream = plot.Stream(plotly_user_config['plotly_streaming_tokens'][0])

    return stream
Ejemplo n.º 2
0
    def test_stream_unstreamable(self):

        # even though `name` isn't streamable, we don't validate it --> pass

        py.sign_in(un, ak)
        my_stream = py.Stream(tk)
        my_stream.open()
        my_stream.write(Scatter(x=[1], y=[10], name="nope"))
        my_stream.close()
Ejemplo n.º 3
0
 def test_stream_multiple_points(self):
     py.sign_in(un, ak)
     stream = Stream(token=tk, maxpoints=50)
     url = py.plot([Scatter(x=[], y=[], mode='markers', stream=stream)],
                   auto_open=False,
                   world_readable=True,
                   filename='stream-test')
     time.sleep(.5)
     my_stream = py.Stream(tk)
     my_stream.open()
     my_stream.write(Scatter(x=[1, 2, 3, 4], y=[2, 1, 2, 5]))
     time.sleep(.5)
     my_stream.close()
Ejemplo n.º 4
0
 def test_stream_single_points(self):
     py.sign_in(un, ak)
     stream = Stream(token=tk, maxpoints=50)
     res = py.plot(
         [Scatter(x=[], y=[], mode="markers", stream=stream)],
         auto_open=False,
         world_readable=True,
         filename="stream-test2",
     )
     time.sleep(0.5)
     my_stream = py.Stream(tk)
     my_stream.open()
     my_stream.write(Scatter(x=[1], y=[10]))
     time.sleep(0.5)
     my_stream.close()
Ejemplo n.º 5
0
 def test_stream_layout(self):
     py.sign_in(un, ak)
     stream = Stream(token=tk, maxpoints=50)
     url = py.plot([Scatter(x=[], y=[], mode='markers', stream=stream)],
                   auto_open=False,
                   world_readable=True,
                   filename='stream-test')
     time.sleep(.5)
     title_0 = "some title i picked first"
     title_1 = "this other title i picked second"
     my_stream = py.Stream(tk)
     my_stream.open()
     my_stream.write(Scatter(x=[1], y=[10]), layout=Layout(title=title_0))
     time.sleep(.5)
     my_stream.close()
     my_stream.open()
     my_stream.write(Scatter(x=[1], y=[10]), layout=Layout(title=title_1))
     my_stream.close()
Ejemplo n.º 6
0
    def test_stream_no_scheme(self):

        # If no scheme is used in the plotly_streaming_domain, port 80
        # should be used for streaming and ssl_enabled should be False

        py.sign_in(un, ak, **{"plotly_streaming_domain": "stream.plot.ly"})
        my_stream = py.Stream(tk)
        expected_streaming_specs = {
            "server": "stream.plot.ly",
            "port": 80,
            "ssl_enabled": False,
            "ssl_verification_enabled": False,
            "headers": {
                "Host": "stream.plot.ly",
                "plotly-streamtoken": tk
            },
        }
        actual_streaming_specs = my_stream.get_streaming_specs()
        self.assertEqual(expected_streaming_specs, actual_streaming_specs)
Ejemplo n.º 7
0
    def test_stream_no_scheme(self):

        # If no scheme is used in the plotly_streaming_domain, port 80
        # should be used for streaming and ssl_enabled should be False

        py.sign_in(un, ak, **{'plotly_streaming_domain': 'stream.plot.ly'})
        my_stream = py.Stream(tk)
        expected_streaming_specs = {
            'server': 'stream.plot.ly',
            'port': 80,
            'ssl_enabled': False,
            'ssl_verification_enabled': False,
            'headers': {
                'Host': 'stream.plot.ly',
                'plotly-streamtoken': tk
            }
        }
        actual_streaming_specs = my_stream.get_streaming_specs()
        self.assertEqual(expected_streaming_specs, actual_streaming_specs)
Ejemplo n.º 8
0
    def test_stream_https(self):

        # If the https scheme is used in the plotly_streaming_domain, port 443
        # should be used for streaming, ssl_enabled should be True,
        # and ssl_verification_enabled should equal plotly_ssl_verification

        ssl_stream_config = {
            "plotly_streaming_domain": "https://stream.plot.ly",
            "plotly_ssl_verification": True,
        }
        py.sign_in(un, ak, **ssl_stream_config)
        my_stream = py.Stream(tk)
        expected_streaming_specs = {
            "server": "stream.plot.ly",
            "port": 443,
            "ssl_enabled": True,
            "ssl_verification_enabled": True,
            "headers": {
                "Host": "stream.plot.ly",
                "plotly-streamtoken": tk
            },
        }
        actual_streaming_specs = my_stream.get_streaming_specs()
        self.assertEqual(expected_streaming_specs, actual_streaming_specs)
Ejemplo n.º 9
0
    def test_stream_https(self):

        # If the https scheme is used in the plotly_streaming_domain, port 443
        # should be used for streaming, ssl_enabled should be True,
        # and ssl_verification_enabled should equal plotly_ssl_verification

        ssl_stream_config = {
            'plotly_streaming_domain': 'https://stream.plot.ly',
            'plotly_ssl_verification': True
        }
        py.sign_in(un, ak, **ssl_stream_config)
        my_stream = py.Stream(tk)
        expected_streaming_specs = {
            'server': 'stream.plot.ly',
            'port': 443,
            'ssl_enabled': True,
            'ssl_verification_enabled': True,
            'headers': {
                'Host': 'stream.plot.ly',
                'plotly-streamtoken': tk
            }
        }
        actual_streaming_specs = my_stream.get_streaming_specs()
        self.assertEqual(expected_streaming_specs, actual_streaming_specs)
Ejemplo n.º 10
0
    'y': [],
    'type': 'scatter',
    'stream': {
        'token': plotly_user_config['plotly_streaming_tokens'][0],
        'maxpoints': 200
    }
}],
              filename='Raspberry Pi Streaming Example Values')

print("View your streaming graph here: ", url)

# temperature sensor middle pin connected channel 0 of mcp3008
sensor_pin = 1
readadc.initialize()

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

#the main sensor reading and plotting loop
while True:
    try:
        sensor_data = readadc.readadc(sensor_pin, readadc.PINS.SPICLK,
                                      readadc.PINS.SPIMOSI,
                                      readadc.PINS.SPIMISO, readadc.PINS.SPICS)

        millivolts = sensor_data * (3300.0 / 1024.0)
        # 10 mv per degree
        temp_C = ((millivolts - 100.0) / 10.0) - 40.0
        # convert celsius to fahrenheit
        temp_F = (temp_C * 9.0 / 5.0) + 32
        # remove decimal point from millivolts