diff --git a/plotly-raspi-stream.py b/plotly-raspi-stream.py index 98b9cbe..7a66704 100644 --- a/plotly-raspi-stream.py +++ b/plotly-raspi-stream.py @@ -2,6 +2,7 @@ from plotly.graph_objs import Scatter, Layout, Figure import time import readadc +import socket username = 'your_plotly_username' api_key = 'your_api_key' @@ -37,7 +38,12 @@ #the main sensor reading loop while True: sensor_data = readadc.readadc(sensor_pin, readadc.PINS.SPICLK, readadc.PINS.SPIMOSI, readadc.PINS.SPIMISO, readadc.PINS.SPICS) - stream.write({'x': i, 'y': sensor_data}) + # try section prevents stopping due to internet reconnection + try: + stream.write({'x': i, 'y': sensor_data}) + except socket.error: + stream.open() + stream.write({'x': i, 'y': sensor_data}) i += 1 # delay between stream posts time.sleep(0.25)