Created
March 11, 2019 22:22
-
-
Save SerbanVictor/3d4d46a7499eaac48ee31b06ed14acd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# !/usr/bin/python3 | |
import socket | |
import dash | |
import dash_daq as daq | |
import dash_html_components as html | |
import dash_core_components as dcc | |
import plotly | |
import plotly.graph_objs as go | |
from collections import deque | |
from dash.dependencies import Output, Input, State | |
import serial | |
from pyfirmata import Arduino, util | |
import time | |
import pymysql | |
import pandas | |
import mysql.connector | |
external_stylesheets = ['http://192.168.1.104/style.css', '/assets/w3css.css'] | |
app = dash.Dash(__name__, external_stylesheets=external_stylesheets) | |
device = '/dev/ttyACM0' # this will have to be changed to the serial port you are using | |
try: | |
print( "Trying...", device ) | |
arduino = serial.Serial( device, 115200, timeout=.1 ) | |
arduino.flush() | |
print( "Successfully connected on ", device ) | |
except: | |
print( "Failed to connect on", device ) | |
app.scripts.config.serve_locally = True | |
app.config['suppress_callback_exceptions'] = True | |
app.layout = html.Div(children=[ | |
daq.Gauge( | |
id='Nuts1', | |
label="Temp 1 - Top Tank Interior:", | |
color={"gradient": True, "ranges": {"green": [-20, 180], "yellow": [180, 220], "red": [220, 500]}}, | |
labelPosition="top", | |
units="Count", | |
value=0, | |
min=-20, | |
max=500, | |
showCurrentValue=True, | |
), | |
dcc.Interval( | |
id='interval-component', | |
interval=1*100, # in milliseconds | |
n_intervals=0 | |
) | |
], className='two columns', style={'margin-left': '15px'}) | |
@app.callback( | |
Output('Nuts1', 'value'), | |
[Input('interval-component', 'n_intervals')] | |
) | |
def clicks8(value): | |
i=8 | |
data = arduino.readline() | |
pieces = data.decode().split(",", 9) | |
value = pieces[8] | |
i=i+1 | |
print(value) | |
return | |
if __name__ == '__main__': | |
app.run_server(host= '0.0.0.0', debug=True, threaded=False, processes=False) | |
The errors that appear are the following: | |
Traceback (most recent call last): | |
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2309, in __call__ | |
return self.wsgi_app(environ, start_response) | |
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2295, in wsgi_app | |
response = self.handle_exception(e) | |
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1741, in handle_exception | |
reraise(exc_type, exc_value, tb) | |
File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise | |
raise value | |
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app | |
response = self.full_dispatch_request() | |
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request | |
rv = self.handle_user_exception(e) | |
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception | |
reraise(exc_type, exc_value, tb) | |
File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise | |
raise value | |
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request | |
rv = self.dispatch_request() | |
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request | |
return self.view_functions[rule.endpoint](**req.view_args) | |
File "/usr/local/lib/python3.7/site-packages/dash/dash.py", line 1073, in dispatch | |
response.set_data(self.callback_map[output]['callback'](*args)) | |
File "/usr/local/lib/python3.7/site-packages/dash/dash.py", line 969, in add_context | |
output_value = func(*args, **kwargs) | |
File "/var/www/html/Nuts.py", line 103, in clicks8 | |
value = pieces[8] | |
IndexError: list index out of range |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment