Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion plotly-raspi-stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)