In this task, we will build a simple web server that can be used to maintain critical health parameters. Let's consider a scenario where a person is diagnosed with high blood pressure. The doctor asks the patient to record his/her vital health parameters such as pulse, oxygen level, or blood pressure. For this situation, we will build a simple web page that records the data and stores it in a CSV
file.
We will be using the Flask framework (http://Flask.pocoo.org/) to deploy the web server on Raspberry Pi. We made use of the Flask framework in Project 4, Christmas Light Sequencer. Just in case you skipped through Project 4, Christmas Light Sequencer, a Python package manager such as pip
or easy_install
is required to install the Flask framework:
sudo apt-get install python-pip
After the installation of the Python package manager is complete, the Flask framework may be installed as follows:
sudo pip install Flask
form_submit.html
file where we can enter the blood pressure, oxygen saturation levels, and pulse data. The landing page will look like the one shown in the following figure (when opened in a browser):CSV
file along with a timestamp:@app.route('/', methods=['POST']) def record(): #record all the data from the form bloodPressure=request.form['BloodPressure'] SpO2=request.form['SpO2'] pulse=request.form['pulse'] #before writing to a csv file, log time stamps date = datetime.today().strftime('%Y-%m-%d') time = datetime.now().strftime('%H:%M:%S') logfile = open('static\comments.csv', 'a') logfile.write(",".join([date,time,bloodPressure, SpO2, pulse,' '])) logfile.close() return render_template('form_action.html',date=date,time=time,bloodPressure=bloodPressure, SpO2=SpO2,pulse=pulse
CSV
file, we redirect the submitted form to a page that displays the recorded values along with the timestamp (as shown in the following figure):CSV
file. We leave this for you to figure out (look at this book's website for the answer).18.191.253.62