I want to design a web based application for showing sound sensor readings, collected from an Arduino based setup (and also show some analysis results). For making my arduino setup work I had developed a python program named 'ard_sensor_project.py' which collects readings and store in .csv file and create a graph.
Now I want to display the readings generated in a django website. For that I have imported 'ard_sensor_project.py' in views.py of my django site and called a method to print the sensor reading at real time.
But on running the program, it seems that though the reading collecting module has started, the site has not started yet and I can neither see the web page nor any reading.
Is there any way such that I can show the readings on the django site?
Here is my ard_sensor_project.py
import matplotlib.pyplot as plt
from datetime import datetime
#necessary declarations
sr = serial.Serial("COM6",9600)
#self declared methods
def getsensordata():
st = list(str(sr.readline(),'utf-8'))
return int(str(''.join(st[:])))
def storedata(fname,val1,val2):
#stores data in a .csv file, will update if required
def plotgraph():
#method for plotting data in a matplotlib graph, will update if required
#codes as part of main execution + function calls
print("------Reading collection starts now------")
while True:
try:
timeNow = datetime.now().strftime("%d-%m-%Y %H:%M:%S")
storedata('op.csv', timeNow, getsensordata())
#plotgraph()
except KeyboardInterrupt:
break
sr.close()
print("------Reading collection ends successfully------")
Here is views.py of my django site
from django.shortcuts import render
# Create your views here.
from django.template.loader import get_template
from django.http import HttpResponse
from . import ard_sensor_project as ard
def index(request):
return render(request,'start.html',{'noise_level':ard.getsenordata})
So it seems that the server is not at all running. When I replace ard.getsensordata
by 0 (also removing ard
import), I get :
Now instead of 0, I want the reading. How should I proceed?