I recently purchased an EnvrioPlus sensor board and need help graphing the sensor data.
Iam wondering if any readers have experimented with graphing data from the sensors remotely? I do not wish to send the data to Luftdaten, because their website will not display any of the gas sensor data.
I want to be able to remotely view the sensor data as graphs, as a beginner to IoT and remote data display. I do not know the correct steps or best software to use to remotely view graphs of the data⌠If anyone can help please reply.
Greetings
You graphing project looks like it could work for me, and appears to display all the sensors nicely.
Since I am a beginner to IoT projects such as this I need more clarity on how to start and logical steps to follow. You mentioned you would post your project - does your software run directly on a raspberry Pi? So how do the pieces fit together- you also mentioned a Flask, I am not familiar with it, does it run on the same Raspberry Pi?
Further help would be greatly appreciated to help understand the process/ procedure in building the project.
Thanks in advance
Tom
Flask is a lightweight Python framework to build a web server. Yes it runs on the RPI 0 and serves web pages to my local network. At the moment I just start it from the command line, but eventually I will make it a service that auto starts.
If you want to serve pages to the WWW then you need to use a more heavy weight sever like, Apache, nginx or Tornado on top of Flask. I think I can get away with just Flask because I only serve it to my home network. I intend to access it away from home over a VPN.
The Python script has a background thread that reads all the sensors every second. It also averages 300 samples and adds them to a file very 5 minutes. It starts a new file each day.
The foreground thread runs the websever and that serves a template for the page that contains javascript. The JavaScript requests the data every second and draws the graphs.
I have never used Flask before or actually learned JavaScript. I just Google and cut and paste so it probably isnât the best example, but it seems to work.
Greetings:
If you would share your program for graphing the Enviroplus + particle sensor, it would greatly appreciated. It would help me to learn more about collecting and graphing sensor data. A question comes to mind - The program that you said you would post this week, is that a python program or is it a Flask program with a python program within it? Where would you post the program?
Thanks in advance, Looking forward to obtaining the program
Tom
It is a Python program that use the Flask Python library and some JavaScript. I will post it on GitHub with a GPL licence.
I keep re-scaling the particle data as I hit new maximums. Making a stir fry in a wok last night send it through the roof and it it isnât back to normal level this morning.
I can wait to see the program and try to understand how it all goes together. So, is sort of the web server/ wrapper around the python software?
On the particle data, itâs seams like the numbers should have decreased after many hours. Do you have a kitchen fan to remove the cooking smells/ particles? Does that mean the particles hand around for a long period.
I may have more questions after I see the software, if that is ok,as I am a beginner in these matters
Thanks again
Tom
I wouldnât describe it as wrapper. The Python program is a complete web server, it is just that nearly all of the web serving is done by the Flask library that is written in Python and makes it very easy. For example, to serve the main page all I needed to write is this:
from flask import Flask, render_template
@app.route('/')
def index():
return render_template('index.html')
app = Flask(__name__)
if __name__ == '__main__':
app.run(debug = True, host = '0.0.0.0', port = 5000, use_reloader = False)
The rest of my script is mainly reading the sensors and processing the results. It is only 167 lines of code ATM. Index.html that contains the JavaScript to draw the graph is 180 lines.
We do have a cooker hood and I did use it but apparently it doesnât work very well as the particle count still hasnât got back to normal. I could smell the cooking upstairs last night but I canât smell it now, so it must be a lot more sensitive than my nose.
Here is the week view I have just added, although I donât have a weekâs worth of data yet and each time I start and stop the program to develop it the gas sensors get disturbed.
The first big particle peak was frying courgettes in a normal pan. The peak on Monday was changing the bedding. The massive peak is the wok stir fry. The smaller peaks are all cooking events.
The solution seems to be to cook with the kitchen door closed. Still see an oxidising gas peak, which I think is NO2 produced by burning natural gas, but no particle increase at all.
Greetings
Will have to read up a bit on Flask to help me to understand it a bit. It appears a bit more critic than python. Do you plan on posting you program code on github or on Pimoroni forum? Please let me know if you post to github and where I might find it.
Thanks in advance
Tom
I assume you meanât âcrypticâ but it is just Python code, so I donât see how it can be more cryptic than Python!
What makes it so terse is the use of decorators, which perhaps could be considered cryptic. They are basically just functions that manipulate other functions. So @app.route() takes my index function and plumbs it into the web server. I have no idea how it does that exactly, all I needed to know is that it causes my code to be called when the top level URL is requested. See Primer on Python Decorators â Real Python
I will post the code to my GitHub account and announce it here when I do.
Then in a browser open the host name of your RPI, or its ip address, followed by :5000. With my broadband router it creates DNS entries for each host, but some donât.
It is currently a debug version. To take over port 80, the default port for a web page, you need to change this line and run it as root with sudo.
Had a busy weekend here, and just found your posting and software on Github. I will have a closer look at the software later this evening and load it onto the Raspberry Pi. I may have a few questions, and may give you a shout.
Thanks so much for posting the software.
Tom
I get this error message shown below when I run app.py
Traceback (most recent call last):
File â/usr/lib/python3/dist-packages/thonny/workbench.pyâ, line 1450, in event_generate
handler(event)
File â/usr/lib/python3/dist-packages/thonny/shell.pyâ, line 220, in _handle_program_output
msg.data[0], (âioâ, msg.stream_name, âvertically_spacedâ)
File â/usr/lib/python3/dist-packages/thonny/shell.pyâ, line 422, in _insert_text_directly
if â\aâ in txt:
TypeError: argument of type âintâ is not iterable
#2. -----------------------------------------------------------------------------------------------------------------
This what I get when I type in the RPI address into the Chromium browser.
When I type in the RPI address 192.168.1.132:5000 I get the line below:
jinja2.exceptions.TemplateNotFound
#3. -----------------------------------------------------------------------------------------------------------------
I donât understand the line below at all.
It is currently a debug version. To take over port 80, the default port for a web page, you need to change this line (3) and run it as root with sudo.
I hope this note make some sense.
I assume Thonny should work ok for running the program.
Does it matter where the app.py program reside on my Raspberry P ?
#1. I have never used Thonny but the stack trace looks like a bug in Thonny as all the lines are in its code, not mine.
I just run it with python3 app.py.
#2. Have you downloaded all the files. There should be a templates folder with two templates in it.
#3. If you want to access the web page with just the url, and not have to add :5000, then the server has to serve it on the default http port, which is 80. However you can only do that if you run it as root because ordinary users are not allowed to take over port 80.
app.py can be anywhere but it must have the static and templates folders with it.
I should add that my RPI Zero is headless so I canât run Thonny. I edit the files on my PC using Samba to share them over the network and I run the code in a remote shell.
Greetings
Thanks for your prompt reply.
I do not have the templates together with the app.py program. The following question may solve some of my problems. You mentioned your github files should be together in a folder. Do the files all have to be in a special folder or just together in my own folder?
Thanks
Tom
The files should be in the two folders and the two folders should be where app.py is. I.e. the same structure as it is on github. The best way to get it is with git clone because then it is easy to update if I make a change. You can also download it as a zip file and unzip it to get the original structure.