This device will act as the data collector in each node placed all over the city.
This device will receive the data from the above kit and send it to Adafruit IO. It would be better to use the Pi Zero, if you have one.
A 6000 mah Battery Bank to power the whole Sensor Node.
One to power the Pi and the other to connect the Rapid IoT kit to the Pi for juice.
This is to connect your nodes with the power of IoT. You can use any other IoT platform too.
The Metro cities all around the world are facing a lot of problem because of the increasing population, which is resulting in an exponential pollution rise, which is a very serious problem and needs immediate attention.
But the problem is that there is no proper monitoring device for these Urban environments, so we are unable to get any reliable data. Even if there are devices to monitor the conditions, they are in limited number due to the current cost - to - reliability and accuracy count.
The UQM - A quality Monitor designed specifically for urban environments. Please note that I have designed this device keeping in mind the Indian metro city conditions, as cities like Delhi are one of the most polluted cities in the world when it comes to Air Pollution.
Lets get started with the project.
The Kit - Small! Right?
This is the main component of the sensor node, as this is the device with all the embedded sensors. This will collect the data, show it on its LED Display, and send it to the Raspberry Pi via Bluetooth. It comes with a pre installed demo application which I have explained in the video given below.
The Pi will get the data collected by the Kit via Bluetooth and send it to the Adafruit IO feeds using a simple Python code. We need BLE for this project, so I would recommend you to use any device with embedded Bluetooth chip.
The best choice would be the Pi Zero W, but I didn't have one so used the Pi 3B.
3. A Battery Bank - for Powering the device.
This is all, so lets get started with the Project.
So, first lets have a look at a simple schematic diagram describing the workflow of this project.
This diagram describes the whole workflow of the project. So, lets start with the Basic Functionality of our device first.
1. The device has a Raspberry Pi and the Rapid IoT prototyping kit as its hardware components. The Rapid IoT acts as a sensor node and sends all the data to the Pi via Bluetooth (Python Code explained later). Each Pi accesses its location via Internet (as I couldn't get the GPS click board in time).
It firstly stores this data locally in the form of csv file for creating a database. It stores sensor values, and the latitude and longitude on their current position.
Secondly, for web interface, this data is sent to the Adafruit IO platform, for visualization in the form of graphs, meters, etc.
The data is also sent to a Fire base database, so that this can be used and accessed by the Android app users, so they can view this data even remotely.
3. We can analyse the csv file data using numpy and matplotlib to create heatmaps, and also plot this data on the map (as we have the location data).
So, overall this project has all the features required for a quality monitoring device to operate at its maximum efficiency. So, lets start with the project.
Now, to develop new firmware applications for your Rapid IoT prototyping kit, you need to use the rapid IoT studio and the MCU Expresso SDK for more advanced development. As I got the kit with less than 20 days left for project submission deadline, we will stick to the easy to use Rapid IoT studio.
In addition to that, we will create two new function triggers to get the value of BatteryLevel and the Charging Status of the Rapid IoT device. This Device will also have an Anti-TheftFeature, in which the device will send an alert of it senses any unwanted motion(motion detected using the Accelarometer of the Rapid IoT).
The code for the same is given in the Rapid IoT Reference Manual.
According to the manual in Chapter 4: Battery sensor, we can get the current battery state by using this function.
In the NXP Rapid Studio, click the element function. Then click the code view which we can write some custom functions that fits our needs.
Add this code to get the Charging State of the device.
Then also add another function and paste this code to get the Battery Percent level of the device.
So, the final Project image of our UQM Device is given below.
1. If the air quality index is above 175 ppm, the RGB LED of the device will turn red warning the user and below this threshold value, the RGB LED will remain Green, indicating safe air.
2. It have theft protection using motion sensing, and also it is able to share its location to the user.
Now, the next step is to compile and load the firmware into the Rapid IoT device.
Detailed instructions on how to upload the firmware to the device can be found in the link above.
An alternative to this is just by pressing the top left and bottom right buttons to enter into flash mode. The video is the same is shown below.
It is a very easy to use platform with python as there is minimal settings, you just need to give your userid and key to connect to your feeds, nothing else!
Just like any free platforms, there are also some limitations in using this platform.
In the free plan, we are limited to 30 data points per minute, 30 data storage, 10 feeds and 5 dashboards per account.
Now that your account is created, you have to click on the view AIO Key option on the left menu, to get your username and key, which will be used to connect your python client with the Adafruit IO.
This is have you get the key.
After this is done, we now have to create feeds for our project on the Adafruit IO website.
Just like what I have stated earlier that in free plan, we can only create 10 Feeds (Maximum). So if you are planning to modify this and send some other data, you should take this into consideration.
NOTE: After Creating all feeds, please do take note of the Key column in the feeds table as we will be needing this in getting the value of that specific feed later.
Now, after created, we have to define the keys of each feed on the python program which is shown by the code snippet given below.
Download data of a specific Feed just by clicking on the download button.
Create a dashboard that will be the home for all of your feeds. Click Action > Create a New Dashboard and fill up the necessary data like the name of your dashboard.
Next, click the dashboard that you have created.
Now, let's create some blocks in the dashboard. Blocks are widgets that we can add base on the value from a feed. Click the plus icon in the upper right.
A detailed explanation on what is the function of each specific blocks can be found in the documentation of adafruit here.
This is what our final dashboard looks like after adding gauges and line graphs for data visualization.
I have also sent the battery level and the charging state of the device, so we can even add that to the dashboard, which I haven't done for now, but its just as easy as adding 2 new elements to the Dashboard.
Now, our Web Visualization part is over.
1. We can only download the last 30 day data.
2. We get a csv file for each feed, so we have to merge those into a single file manually.
So, to overcome these drawbacks, I have added a small code snippet in which the obtained data in stored in a local csv file itself, so that it can be used later for analyzing the conditions of that particular locality.
print "Data stored in csv file successfully"
This is a simple code snippet used to write csv files with the data, csvData in the above case.
This local data can be useful for training machine learning models that predict the weather and air quality of a particular area or locality.
The Rapid IoT data can be visualized via BLE using the Rapid IoT app, as shown below.
But what if we want to get real time data remotely, without being anywhere near the device, which would be the practical case in the real world.
Of course, we can use the Adafruit IO dashboard for this, but for an end user, who would be a normal person busy with his day to day life, how would he get time to go search for the dashboard, sign in and then see the data. It is just not a fruitful way, and moreover with the increasing number of users, we can't use the same account.
So, I had a solution for this problem too. I pushed the sensor data to a Firebase database using the "put" method for overwriting the data.
Part 3. Android App integration and Data fetching from Firebase real time Database.
I kept this app simple for easy understanding.
This completes our Fire Base Setup.
Now, you can copy your Firebase URL from the database page of your project. The image showing the URL is shown below.
Now, change the database rules for read and write to true, so that you can write into the database using the python code.
Now, it is really simple to send your data to firebase real time database from your python code. Just use the following code snippet, in which I sent 5 sensor data values to the Database.
I used 'Put' method to send the data, so it will be replaced every time a new data is sent, which will be reflected by a color(yellow) change in the firebase database.
So, this concludes the firebase python integration.
1. Create some Data Text Views which will be set to the read values and give some text views that will give the description of the data being displayed. Give appropriate id's to the Data text views so that we can find and set them via Java code. My Activity_main.xml file looks something like this.
2. Now that we have the text views, lets move to the MainActivity.java code. Firstly, import the google firebase database files we are going to use for the project.
Now, for this to work, you need to add a dependency in the app gradle file.
Now, after this is done, we create an Instance of the database and get a reference of the parent using the following command. We also define the text view variables.
Now, we find the values of the text view by their ids using the following code snippet.
After this, we create and onStart function to fetch or read the data from the above referred table, 'urban-quality-monitor' in my case.
The function will have an addValueListenner() function of Firebase, which will read and set the value of the text views. The code snippet for the same is given below.
So, this is all that is required for the android app. Our app is finally ready and can be now tested.
Now, the video Demo of the whole project is given below.
Sorry for the fact that I didn't have any casing for my project showcase. I actually got my Rapid IoT kit just a few days back, so couldn't focus much on the Hardware casing in such a Short span of time.
So, This was all about my Project.
I would like to thank NXP for giving me the opportunity to build such a project. It won't have been possible without your Hardware and the constant technical support from the authorities.
Please respect the project if you like it and follow me, so you don't miss our more of such practical and innovative projects.