Creating a system to detect and filter Carbon Monoxide using IoT and Nordic Thingy
Advisor: Mr. Smith
Internship Location: American Computer Services, Georgia(Remote)
Onsite Mentor: Vinay Kodancha
The aim of this project is to improve student retention with the use of a detector to help identify CO2 concentration levels in the air. High levels of CO2 result in discomfort which makes it harder to focus, resulting in worse concentration and therefore lower grades. The device used will be a “Nordic Thingy 91,” which contains a sensor that detects CO2 concentration levels. I will build a User Interface for the device to make it easy to detect gas levels by anyone. This interface will provide CO2 concentrations by classroom in real time, graphs to allow the user to track patterns in concentrations, and an alert system for when levels get dangerously high.
Project Blog
Week 0: Blog: Introduction
Hello everyone, my name is Akul Karnataki, and I am a student at Basis Independent Fremont. This will be my blog for keeping track of my Senior Project updates, so please look out for more later. One thing that often bothers me is poor air quality. I have many allergies that often result in feelings of discomfort and can often be very disruptive to my life, with symptoms that can even make breathing difficult. Therefore, one thing I really care about is having clean air that is more comfortable to breathe. In order to pursue this goal, I must be able to first find the concentrations of CO2 in the air of classrooms. High levels of CO2 is correlated to more difficulty breathing, due to it being associated with lower levels of Oxygen, which can often make students more uncomfortable, and is linked to worse concentration and memory retention.
My goal is to improve student comfort in classrooms with the use of a detector to help identify CO2 concentration levels in the air. I will use a “Nordic Thingy 91,” which contains a sensor that detects CO2 concentration levels. In order to prepare for this project, I have taken steps to learn to develop on this platform by taking courses on C++ at Ohlone community college during the fall semester. I have also received certification in nRF Connect SDK Fundamentals after completing an online official course. These courses will help me build a browser-based user interface for the device to make it easy to detect gas levels by anyone. This interface will provide CO2 concentrations by classroom in real time, graphs to allow the user to track patterns in concentrations, and an alert system for when levels get dangerously high. I will test out this product in various classrooms at BIF Upper to track the levels of CO2 in the air over time. While schools do have smoke detectors, these only raise the alarm if levels are dangerously high, ignoring all the times we are uncomfortable. My device will fix this by not only organizing all the data into one place, but also alert staff to take action if the levels of CO2 are high enough to be affecting focus.
Next week, I will begin by connecting the Nordic Thingy device to my computer and start testing it out to see if it works.
Week 2
Hello, everyone! I just got back from a one-week trip to Costa Rica on Tuesday, which is why I did not write a Blog last week. I made many fond memories and experienced a brand, new culture. Anyway, this week, on my return, I met with my external advisor. We discussed IoT technology and he helped me understand it a bit better. Internet of Things, aka IoT, is essentially device-to-device communication on a small scale. Now, let me give a more illustrative description of what that entails. When you are playing a video game, various devices allow you to do so. There is the console itself which is where the bulk of the operations run; a controller, via which you command your character, and the monitor you are using, which displays the game. If you are also, say, recording your gameplay for YouTube or Twitch, you also need a camera to record yourself and a computer to upload that recording onto. All of these things make up an IoT. They work together, transmitting data between each other to enable you to play your game and upload it as a video.
I also did more research into what the Nordic Thingy is and how it works to gain a better understanding of the device. The Nordic Thingy 91 is an Internet of Things(IoT) device with many environmental sensors that record data for different functions, including temperature, humidity, air quality, and air pressure. The device has a Central Processing Unit(CPU) to run all the operations. This device takes data from the BME 680 sensor, which detects air quality, humidity, and temperature, and the BHI 680 which detects color and light. The Nordic Thingy also has cloud space in an nRF cloud hosted by AWS. AWS essentially allows you to rent servers from Amazon, which allows users to host websites without having to pay the high server maintenance costs. AWS is actually where Amazon gets most of its profit from, and it hosts around a third of the internet.
Cellular IoT is a service that allows for the transmission of information between devices without Wifi. Instead, it uses cellular data, transmitted via land-based towers. It is far more flexible due to reaching more areas than Wifi IoT does. In addition, it offers lower energy consumption, as well as high data rates compared to Wifi. There are two main types of cellular IoT: LTE-M and NB-IOT. LTE-M, or Long Term Evolution for Machines has longer battery life, low power consumption, and more voice and data support. However, this is more expensive than NB-IoT, or Narrow Band IoT, which is much longer range and also cheaper. Nordic Thingy uses LTE IoT to allow users to read data from many different devices no matter where they are. This means I can test the code in multiple different rooms and compare all of them with a good amount of speed, and even areas with no internet access can use these devices.
Next week, I will resume working on the User Interface.
Post 3: Week One: Initial Setup
Hello everyone, this is the first week of working on my new project.
This week, I started by connecting the Nordic Thingy to my device. This is a surprisingly complicated process. First, I had to set up an nRF Connect for Cloud account, and pair my device with the account. In order to pair it, I had to verify the SIM card in the device that stores its memory, which was where I ran into a major hitch. I had to enter the devices ICCID, which was supposed to be on the device, but the required ICCID was 18 digits, while my device had 20 on them. After doing a bit of research, I came across a forum post that had some code to convert the number into an ICCID, and used that to finally connect the device to my computer.
Now, it was time to test whether the device worked. After programming the device to display the concentrations of gas, I put the device in various rooms and measured the concentration of VOCs in those rooms. Throughout the day, I changed the location of the device just to test it out and do a bit of experimenting. First of all, the amount of VOCs detected rose over time when I was sitting in my room and the windows and doors were closed. However, opening the door allowed many of these trapped gases to escape and thus lowering the concentration of them. Therefore, I believe that opening the doors in rooms will help to increase focus by lowering the concentration of these VOCs. Also, while the heater was on or someone was cooking, the levels rose significantly, showing that it is much better to try to wear thick clothes or blankets than turn on a heater while studying or working.
Next week, I will take a break for a trip, but when I return, I will be studying the Nordic Thingy device itself to understand how it works.
Week 3: Senior Project: Week 3
Hello everyone! I'm back to tell you guys all about another week of progress. This week, I learned about World Wide Web and HTTP. HTTP is a client-server protocol that serves as the basis for all websites. HTTP is a useful tool for my work, as it also has multiple different command types that I can use to request data and change the device state. The different commands are GET, which obtains a file, HEAD, which obtains data on the target's state, POST, which processes the file that the client sends, PUT, which updates the target, DELETE, which deletes the target's state, CONNECT, which establishes a TCP/IP link, OPTIONS, which requests a list of available commands, and PATCH, which shows the current version. Nordic uses a Representational State Transfer(REST) API that is built off of HTTP, which allows it to easily have multiple different devices all made by different developers communicate with each other. I also learned about MQTT, an application of HTTP with more of an IoT focus. MQTT uses a machine-to-machine "publish-subscribe model," in which the publisher, in our case the Nordic Thingy, puts Messages onto a "topic" that is read by the subscriber, my computer.
I also connected my device to a service known as "Postman." Postman is a free, MQTT-based, API tester that I can use as an interface to command my Thingy device. Connecting to Postman was pretty difficult, but fortunately, I found an official guide online to help out from the Nordic developers themselves. First, I had to ensure my device was off. Then, I had to create a new Postman account, and download the software from their website. In order to get the testing started, I had to create a new workspace on Postman, which I then had to input my nRF device's key and download the nRF Cloud REST API which allows my computer to actually talk to my device. Following this, to test it out, I had to try to obtain the device "shadow" and display it on Postman. The "shadow," represented as a .JSON file, essentially represents the current state of the device compared with the desired state. For example, if the Nordic Thingy were to read data every minute, the JSON file would tell me that in the "activeWaitTime" for both the current and desired state, assuming I have not given the device any instructions. However, if I would I were to command the Nordic Thingy to only read data every hour, but the device wasn't turned on, meaning it hasn't listened to my command yet, the "desired" state would show what I asked of it, but the "current" would show what it is actually doing.
Next week, I will set up two more Nordic Thingy devices, try to read the Air Quality data from Nordic REST API, and research which framework to use to display the Air Quality Data reading coming from the sensors.
Week 4: Blog
Hello everyone! On my first day, I decided to download the Angular software to allow me to actually code websites. This was pretty difficult. First of all, I had to use the Mac Terminal to install the software, which is a pain as it requires knowledge in using Linux. I kept getting strange errors, but almost every time it had the same solution - using Sudo before every command to get administrator permissions. After all this, my external advisor said to use Vue instead of Angular, so I made no progress.
Instead, he advised me to learn more about HTML, so I can build my own website. I’m going to walk you through the steps on how to do it so you can try it for yourself. The first thing you have to write before doing anything is <!doctype html>. In the past, this linked to a set of rules that the code had to follow to be good HTML, but now, it only ensures that the document is working properly. The next thing you have to write always is <html></html>. This will “wrap” your code, meaning all code should be written between these two. The next thing you need is <meta charset="utf-8">, which accesses the utf-8 library of characters. The utf-8 library contains characters from the vast majority of written languages, so it is a useful tool if you also want to write in say, Hindi or Mandarin as well. To actually write text use the format <p>Hello World</p>. The line <meta name="viewport" content="width=device-width"> ensures that the website can be viewed even on mobile devices, as it prevents the devices from rendering sites wider than the screen can show. To set the title, use <title></title>. For everything you don’t want the user to see on the page, like the descriptions you see when searching things up, use <head></head> to wrap the code. For stuff you want visible, use <body></body> to wrap that code. However, this just lets you create a boring text-based website. To make it look nicer, we need to add some pictures. We can do this with the <img> element, which has the format <img src = “(image path here)” alt = “(text here)”>. The image path is the directory and file name of the image, while alt is what shows if, for whatever reason the image cannot load. However, there is still one more thing we need to make a good website, and that is links. With the format <a href="(hyperlink here)">(displayed text here)<a>, we can even put links to other sites on our website.
With this said, how exactly does the framework for the Internet work that allows us to actually use websites? Computers connected to the Internet are called Clients and Servers. Clients are the devices you typically use to access the Internet, including both hardware(like a computer or phone) and software(like a browser). Servers store webpages, sites or apps. When you access those services, you do it through a server. Clients send requests to Servers, and Servers follow up those requests with responses. Now this is where the TCP/IP stuff I talked about earlier comes in. When attempting to access a website, the browser first finds the real address of the server that the website is on. Then, it sends an HTTP request to the server asking for a copy of the requested website. If the request is approved, the server sends a “200 OK” response along with small chunks of the data called “packets.” However, if anything goes wrong it can send one of the following numbers as responses instead: 301, which means the resource has been moved into another location permanently; 400, meaning the server can’t process the request; 403, meaning the client does not have the permission to access the desired content; 404(the most well-known one probably), which means the link is invalid; and 503 which means there is an issue with the server itself, usually meaning a temporary pause due to maintenance. Finally, the browser assembles the packets into a full website. Another important thing to note is that servers use IP addresses, not URLS to store websites. However, the “Domain Name System” or DNS was invented to make the internet more intuitive to understand, so special servers are used to match the name of the website to the IP address. Also, as I mentioned earlier, the HTTP GET command will obtain the state of the website that it is sent to, which includes the date and time, expiry date and time, server, date of last modification, length of the content, and the format of the content.
Now that we learned how to make a website, lets discuss formatting text for a bit. CSS is a rule-based model for formatting text. It contains everything that is used to modify the text, including color, font, font size, and others. When a browser first loads a website, it first receives the HTML document containing web page content and converts it into a DOM tree. After that, CSS files are sorted into different “buckets” based on what they will be applied to. CSS files are stored in external filesheets, which have a .css extension. This is useful, as this means multiple different html files can access the same formatting file, which is certainly convenient for larger servers. Internal stylesheets also exist though, and they are stored under the <style> header. Finally, you can use in-line styles and write a css file inside a css variable. However, it is generally considered bad practice to use these, as it makes maintenance harder and doesn’t look as neat. Now, lets say you need to adjust the look based on the location in the document. You can simply use a device called a descendant combinator to help you with this.
Next week, I will be learning how to implement Javascript to add interactive elements.
Week 5: Blog Week 5
This week, I learned about JavaScript. JavaScript is a programming language that allows users to implement complex features, such as graphics, interactive maps, animations. It is the third layer of technology used to build websites, on top of HTML and CSS which we discussed last week. So what exactly can JavaScript do? It can store useful values inside variables, do operations on strings to combine or separate them, run code in response to events such as clicking happening, and more. In order to unlock its full potential, however, we must use a special tool called an Application Programming Interface(API). APIs are ready-made sets of code that facilitates the implementation of programs. There are two types of APIs: Browser APIs and Third-Party APIs. Browser APIs are built into web browsers, and can expose data from the surrounding computer environment, like the DOM API, which allows you to manipulate HTML and CSS. Third-Party APIs are not built into the browser by default, and you have to grab the code from elsewhere. For example, the Bluesky API allows you to display your latest Bluesky posts onto your website.
So what is JavaScript doing on your page? Every tab on your browser has its own “execution environment,” meaning the code is running completely separately. This essentially means that no tab can affect any other tab, which is mainly used to prevent pirates on one website from stealing data from another. You may also have heard of Server-side and client-side code. Server side is what runs the background processes, while client side runs what the client can see. In order to build our website, we will use client-side code mainly.
Now lets discuss some variables that Javascript uses. First of all, we have the classic integer. These numbers are all numbers without a decimal point at the end, including negative numbers, zero, and positive numbers. Next, we have floats, which do have decimals at the end. There are also different number systems within JavaScript. Bits use base 2, Octal uses base 8, denary is base 10(which is what most people think of numbers in), and hexadecimal is base 16.
Now that we know how the numbers work, how do we modify them to do mathematical problems? We can use operators to do this. Num++ will increment the value by one, while Num-- will decrement it by one. We also have assignment operators: =, which changes the value to whatever is on the other side, += which adds the other side to the value, -= which subtracts from the value by the other side, /= which divides them, and *= which multiplies them.
Now, lets discuss how we can put in some words. In order to do this, we are going to need a device called a “string.” In order to declare a string you need to use the format const string = “text.” You can also use single quotes, double quotes, or back quotes, in Javascript; all of these can contain stings. In order to concatenate them, you need to use a “+ string” for normal strings, and a ${string} for string literals. Literals also allow you to break lines into paragraphs if you so wish, and it counts new lines in the string as new lines. Finally, you can display a string and a number at the same time with a + sign as well. Another way of storing data is through arrays, which are essentially lists of variables, formatted {data, data, data, data, …} You can find the length of the array with the command console.log(listname.length). With indexOf(data), you can find the location of the requested data in the array. To add more items to the end we need to use push(data), which adds it to the end. If we want to add it to the front, use unshift() instead. To remove the last element use pop(), while to remove the first element use shift(). Now lets suppose we only want our code to do something dependant on some other variable. For this, we will need to use a conditional statement. With the phrase if(condition) we can make it so that the code inside the if statement will only activate if the conditions inside are true. We can also use comparison operators inside to test the conditions as well. Additionally, we also may want a certain action to be repeated. For this, we can use a loop. The loop statement is for(element in array). Essentially, the statement will be done for every element in the array. Another type is the while statement, which is an if statement that will keep repeating until the condition is false.
Next week, I will start to code for the actual website itself.
Week 6
Hello everyone! I would like to tell you all about the frustrating world of working with Vue. Basically, I had to get Vue to work with an API, and read data off of that API. This was incredibly frustrating to do even with a guide! I used a guide for making a website that could display news taken from an API developed by the New York Times. The guide contained a lot of outdated information, and was therefore unreliable. For example, in order to use it, I had to install a program called Axios which came with its own issues. Therefore, I had to play a game of “whack-a-mole” whenever a new issue popped up, as the fix for one thing only created problems in other things. Although the task was quite difficult and frustrating, it was incredibly satisfying to pull off. Next I tried to create a line graph. This was significantly easier, but still I had no shortage of error messages while working on it! I needed to use something called “Echarts” to create graphs. Echarts is a software package that allows for the use of graphics such as charts on websites. This was far easier to work with, as the information I found on this tool wasn’t as outdated, making the effort more straightforward. Next week, I intend to finally create the graph and finish the product .
Week 7
Hello everyone! This week, I spent my time working on a major part of my web app which will display the air quality data from one test device, graphically. I started by parsing the JSON response from the REST Cloud API which contains key information like the date and time the data was retrieved, the device ID, and the actual sensor data. To access and display this information, I used an HTTP client called Axios. Using Axios, I can make HTTP requests and retrieve data from tools like Postman, which I then render directly onto the website. I was able to see the JSON response in the Postman tool, but when I used the Axios API I was not able to get anything. It kept returning error code 4200. I was getting a response from the REST Cloud endpoint, but not the one I wanted. I then realized that I had not set the Bearer token field as part of the Header. Once I set it up correctly, it worked.
Right now, the data is displayed in a readable list format, with each individual data point shown clearly on the page. This was a good first step, but I’ve run into a challenge when it comes to turning this data into a visual graph. Creating the graph has been tough, especially because I’m still learning the tools. A lot of the code was implemented with the help of guides, so I don’t fully understand everything yet. To improve my understanding and capabilities with the tool, I’ve started taking online classes and tutorials in the subject as well. While I work through this learning curve, I’m also experimenting with displaying the data in Google Sheets as a temporary solution for visualization. I am not very confident that I will be able to get the chart fully working in next few weeks as now I realize that it will take many months to become a Full Stack developer. I am still happy that I have got the JSON response and I understand how different client side Web Technologies work.
Also, I am learning more about Linux Systems programming, as Linux programming is a foundation for most IoT Device development. I am really learning how pointers and memory management and file management work. I have started to understand how a real operating system is implemented and I have yet so much to learn.
Week 8: Blog
Hello everyone! This week, I have some great news! I finally got the website working! I first used chart.js to display the graph. As it turns out, using Axios and Vue was far too difficult. Instead, I finished my project with a basic HTML file that only uses chart.js. What my chart does is call the json file from the Nordic API. Then, it reads the data and turns that into a graph. The next step was to make a basic user interface. To do this, I first created a group that had all the devices that I would read data from. Then, I had the UI read the group, and create a drop down list of all the devices. Finally, I created a radio button that had three things: Temperature, Humidity, and Air Quality. For the next step, I had to combine my previous two ideas. For this, I had it create a graph depending on the buttons that were clicked. To do this, I had it dynamically create the link by tying button presses to strings that were used in the link that allowed it to change the device the graph was drawing data from. In addition, I also learned more about Zephyr OS. This is a Real-Time Operating System(RTOS) that supports features like multi-tasking, support for communication protocols, and real-time scheduling. Zephyr supports a wide range of devices, possesses low overhead, which allows it to be used even on weaker devices, and is open-source. These features allow users to make any modifications to it that they desire. Next week, I will test the devices in a classroom setting.
Week 9: blog
Hello everyone! We are finally approaching the end of the senior project. This week, I worked on the testing of the product. I installed my devices in three locations: inside my home, outside my home, and in a classroom. However, the classroom device wasn’t sending me any data. I tried for days to get it to work, and tried all sorts of things: plugging it into the wall, checking on the code, and replacing it with another one. However, nothing seemed to work until I started looking into a funny looking error code which I had overlooked. I was just trying to see why it was erroring out. I looked into more details of the error code and then I realized that I had exhausted the number of messages my device can send with my basic subscription to AWS IoT. I then upgraded to a pro version for a month so my test devices can send as much data as needed. I can now get enough data in my dataset. In addition, I finally got a website working! Using tiiny.host, a free website hosting service, I created a link for you guys to view the project: https://classroomairquality.tiiny.site/. This website has data for all three devices, and displays Air Quality, Temperature, and Humidity. Another thing I am working on is trying to get all the data to display on a single graph so they can be compared directly. This will allow you to see comparisons across all of the different rooms. Also, I will be working on trying to make the User able to pick their own group of Nordic Thingy devices to display, and also make it so they can rename the Thingy devices to allow for more organization.
Week 10: blog
Hello Everyone! This is our final week working on the Senior Project, and what a ride it has been! 10 weeks really did pass by in a moment, and I feel like I have emerged out of them with a much stronger grasp of HTML and IoT. Just to briefly recap all that I have done, I was able to get a Nordic Thingy: 91 device to acquire data related to environmental conditions in some classrooms and display data via a graphs that are generated using an online utility. I did this using HTML and Javascript, which read the “json” files containing device state from the Nordic Thingy: 91. This week, I worked on making presentation that details everything my project is about. I got lots of valuable data on how the air quality, temperature, and humidity change over time that I will showcase in my presentation. For those of you who have been keeping up with my blog, thank you so much for doing so, and I give a sincere goodbye to all of you as I publish this final entry.