Hello,
i have write a code in python to plot data from an ADC in realtime. there is only one problem the code run i get no errors but there is also no plot in web page that i created. can any one help me pleadse? thanks
ma code
#app work
app = dash.Dash(__name__)
#html layout
app.layout = html.Div(
[
dcc.Graph(id = 'live-graph',
animate = True),
dcc.Interval(
id = 'graph-update',
interval = 1*1000,
n_intervals = 0 ),])
#callback and def read func
@app.callback( Output('live-graph', 'figure'), [ Input('graph-update', 'n_intervals') ])
def main(interval):
ADC_Value = ADC.ADS1256_GetAll()
volt = [(ADC_Value[0]*5.0/0x7fffff)]
conn = sqlite3.connect(raspi)
curs = conn.cursor()
curs.execute("INSERT INTO raspi values(datetime('now'), (?))", (volt))
conn.commit()
conn = sqlite3.connect('/var/www/html/database/raspi.db')
curs = conn.cursor()
for row in curs.execute("SELECT * FROM 'raspi' ORDER BY timestamp DESC LIMIT 1 "):
w = numpy.asarray(list(str(row[0])))
volt = numpy.asarray(list(str(row[1])))
data = Scatter( x = w , y = volt , hoverinfo='text+name+y', name='Scatter', mode= 'lines+markers', )
layout = go.Layout(xaxis = dict(range=[min(w),max(w)]), yaxis = dict(range=[min(volt),max(volt)]))
figure = {'data' :data, 'layout' : layout}
return figure
return w, volt
con.close()
#main
if __name__ == '__main__':
app.run_server(host= '000.000.000.00', port = 8080 , debug=False)
hello, thank you for the replay. I have changed it as you advised me and those lines are not below the for loop but it still no live graph or no graph at all at web page.!
While we wait for OP to reply back to you and Jinny with some more info just an FYI if you’re still wondering the con.close() line would be for the SQL queries he opens before his for loop.
The con.close() would shutdown the connection to the SQLite Database for the end of the function.
The for loop is only pulling the last set of data and looping through one record. You could have skipped the query in that instance and just given a predefined time stamp to the database with the push.
thank u all for every advice
i had to change the cod little bit. i used pandas to import data from sqlite then used it as df to import data by dash
so thats the working code;
‘’’