Raspberry Pi BME280 Weather Station Using Python and Flask

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi welcome to donkey effect I'm going to show you my new project called the Raspberry Pi BME 280 weather station using plus and python so as you can see in here it is the weather station dashboard that I have created that will show you the sensor readings coming from my bme280 sensor at the top of my Peaks are the current values of the temperature the humidity pressure and relative altitude at the rightmost part of the page are the current values of the temperature humidity pressure altitude engage chart representation the H chart will tell you if the current readings exceeds a particular threshold so for example in here my threshold is 30 degrees Celsius and make my current temperature is 27.7 so the threshold value is up by less than 2.3 from the 30 degree celsius so it is a good way for you to check if your temperature reading is exceeding a certain threshold on the left hand side of my it's my historical line chart of thanks for reading I am saving the last 12 sensor readings and displaying them as line charge the user interface automatically updates itself to retrieve the latest sensor readings so for example here I have here my Raspberry Pi zero W and my bme280 sensor and if I try to touch this bme280 sensor then I am assuming that the temperature should change currently it is 27.8 and if I touch the sensor with my index finger then as you can see it's now 29.6 and if you look the look at the line chart in here you would notice that the temperature indeed zoom up now if I remove my my index finger then I am assuming that the temperature should go down so let's see so what you have noticed the temperature did went down and it is being shown here by the historical chart and displayed also at the top which is the temperature I use Python and plugs in developing this bme280 weather station project would you like to know how I did this then let's start exploring [Music] foreign start let's discuss a little bit about what the bme280 sensor is it was developed by Bosch for mobile and wearable devices application it is capable of retrieving the temperature the humidity pressure and relative altitude with high accuracy this table here lists some of the important specification for this particular Center the bme280 module can use SPI or i2c Communication in my case here I am using the i2c module so the usual pin out such as the SEL and SDA pin it's present and the power pins be in and ground for the wiring I use an Raspberry Pi 0w single bird computer and I'm using the standard i2c pins which are the gpio2 and gpio T assigned as scl and SDA Hardware pins I just connected it with the BME bmp280sel SDA and the power pins the following is the overall design of my Raspberry Pi zero W DME 280 weather station dashboard I have created a plus web server inside my Raspberry Pi 0w that will create a web application which is my bme280 weather station dashboard the weather station periodically requires sensor readings through an HTTP call and when the web server reset receives this request then it communicates with the bme280 sensor to my Raspberry Pi 0w the ebme 280 sensor then retrieves the readings and then sends it back to my plus web server and the plus web server will then send back the sensor reading back to the web application weather station dashboard the weather station dashboard in turn is its user interface to show the latest sensor reading now these are the parts of my weather station dashboard the important part are the Box tests at the top which displays the current temperature humidity pressure and approximate altitude the great chart is in the right hand side and my line chart is in the left hand side the sidebar just displays my name which is then dots key text now let us discuss some code first how do we read the bme280 sensor readings read the bme280 sensor readings then we use a library called the rpi.bme280 the code is really simple as we just we need to declare an SM bus and then passing in the port which is one in my case in here I'm using a Raspberry Pi 0w so the port number assignment is one otherwise it will be zero for all Raspberry Pi model and then we just call the load calibration params in here by passing the path that we created at the topic address of my bme280 between this case is 0x76 next we sample a reading by calling this bme280. sample and then passing in the bus the address and the calibration params that we created earlier the return value will now contain the following and stored in this particular variable which is taken from this variable we can extract the value of the temperature the pressure and humidity so let's try this one in actual code so I'm just going to execute python pme underscore bmps.py and as you can see this is the value of the temperature the pressure and the humidity coming from my bme280 sensor next we talk about the BME underscore module.py ebme underscore module that UI is the representation of our bme280 Etc as you can see here I have a class called the bme-20 module which is a Class Property called the port address which is the 0x76 and the sea level pressure which will be using in calculating the relative altitude later it then creates some code that we have done already already in the BME text.py so if you take a look at the Constructor I just created the same box and the calibration params the method get sensory links is where we retrieve readings from our BME to h0 sensor by also calling the method bme280 sample and then we retrieve the value of the temperature the humidity and the pressure the additional coding here is the altitude calculation using this formula then you can guess the altitude if we know the current sea level pressure at this time just a reminder this is just an estimate though I just copied this one from the BMP 180 data sheets on how to calculate the altitude and then from these values we just return a python couple of all the values all these values are then returned back to the calling client which in this case is our BME 280 weather station dashboard file is the app.py the app.py is very quickly our plus web server I have here also the bme280 module which is initialized at this point the important part of this file are the rubs you should respond to requests from our browser or our bme280 weather station dashboard first the index or the root cloud will serve as our index.html page so this job which is the root will serve our index.html which is in the template folder next the backslash password readings route will read the values from our bme280 module by calling the get sensor reading so power rpme280 module class and then it will return a Json response back to the calling ion which in this case is our bme280 weather station dashboard the weather station dashboard periodically calls this route every three seconds the main function here it's just used to run our plus plus application now let's go to the index.html page the enclix.html page contains the HTML elements for our project and issues to display the sensor readings let us scan the important parts in the head section I am importing the Box icon points and the black lead that yes that I use to display graphs and part the sidebar which in this case is this one you place my logo name which is dot dotskin tag and the name of the current page which is which is the dashboard the home content as you can see in here which is the home section contains the boxes so these are the boxes which the temperature and then the humidity and the pressure the history chart which is at the bottom contains the HTML dips that will display my line chart and also my gauge div part it will be populated by the flatly.jscript library when it is time to draw the graph or chart the style.css inks our cascading style sheet file and it contains the classes that will beautify our index.html page I cannot discuss so much about how these CSS work because that is a big topic on its own but one thing I can say to learn how it works is to comment everything and then uncomment it one by one starting from the top there you would see the impact of such typing on our index.html page the last and the important file is the main.js file it initializes all configurations for our graphs so for example this is the history which I call as Trace so temperature Trace humidity Trace which is part the line chart or historical chart which you can see initialize by creating the part by calling the plotly that new plot and then passing in several parameters that we the head at the top for the gauge data which you can see in here it just creates also the glitch data by passing in the several important parameters like the dash divs and then the temperature data that is declared at the top also these array variables that you are seeing in here will hold the last work sensor readings for each data coming from the BME 280 sensor I am limiting the number to 12 points so that I I would only be displaying maximum of 12 data points now the function of date sensor readings is an important function which we'll call our last sensor readings which you can see also in the app.py which is the slash sensor reading scene here using the data retrieve from the calling the flash sensor reading throughout then we can extract the values of our temperature humidity pressure and altitude and then using those values you can update our user interface by calling this sub function called update boxes public gauge and update charts we take a look at what this sub function is doing as you can see in the sub boxes here I just update the value of the beeps and then changing the inner HTML value for the gauge chart I just call the flatly data API function the same also for the update chart I just called the flatly.update the last function that you are seeing in here is what we use to automatically trigger a refresh of our page every three seconds we have a set of loop functions in here that we'll call our sensor building at the top every three seconds that is all for the code the steps on how to run this project is in the description of this video that is how our project works if there are any questions or comments then please ask this in the companion write up of this video the companion write up the code and everything are in the in the description of this video I hope you learned something about exploring
Info
Channel: DonskyTech
Views: 2,732
Rating: undefined out of 5
Keywords: python, raspberrypi, raspberrypizerow, bme280, weatherstation, iot, flask
Id: -JtaMrrgePw
Channel Id: undefined
Length: 14min 2sec (842 seconds)
Published: Wed Dec 28 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.