PROBLEM STATEMENT
In Asia, due to hot weather and the outbreak of severe acute respiratory syndrome (SARS) in 2003, the primary and secondary school students need to perform temperature measurement during every quarter to ensure the well being of the students. Whenever there is a temperature taking exercise scheduled by the school, students are required to bring their own digital thermometer for this exercise. However, some students might not be able to participate during the exercise due to the reasons like misplaced or damaged thermometer and forget to bring the device. Due to personal hygiene, students are not allow to share their thermometers and they might not have sufficient money to buy a new piece. Hence, it affects the success rate of the temperature taking exercise. After the temperature measurement exercise, staff will have to manually key all the students temperature data and students particular to database. The task is very tedious and time consuming as each form teacher will need to perform entries for about 40 students.
What's The Solution?The Theme for our project is Social Impact by SqwidNet, and in the area of Good health and well-being in the Sustainable Development Goal (SDG). The reason for it is because our system is able to deploy to automatically measure the temperature of valid users so that their temperature can be monitored and an alert will be sent whenever it exceeds a certain threshold level.
HOW IT WORKS: RaspberryPi & ArduinoThe RaspberryPi holds a Python Program & the MySQL database.
Upon launching the Python Program, it automatically checks for if the database if already created, if not, it'll be created automatically. The tables inside will also be checked & created automatically if needed. This reduces the manual labor work of teachers/administrative staffs in the school.
Then, it establishes a query connection to check the database and awaits for the Arduino to send relevant information through the Serial Communication port.
Upon having an RFID card tap on the Arduino, the card information is stored in the Arduino, sent to the RaspberryPi via Serial Communication. Afterwards, RaspberryPi confirms with the database that said card is a valid user, and if it is, it sends to the Arduino confirming it and the Arduino outputs "Welcome, name" on the LCD screen. If it's not a valid user, it'd just say "Error! Invalid User!".
Let's say, now, we have a valid user that just tapped. Next, the Arduino will prompt the user to take their temperature. A distance sensor will then sense if a user is ready to take their temperature. If they are, it'll take their temperature and output their temperature on the LCD screen. If it's a valid temperature (28*C - 42*C), this information will be sent both to the RaspberryPi (MySQL) and Sigfox (ThingSpeak) for data storing. The MySQL database would store the userID, date, timestamp and the temperature of each taking.
When receiving the temperature data from the Arduino, the RaspberryPi would constantly check if the temperature is properly delivered before proceeding with anything else. This is because, if the Python Program only checks once for the temperature data, it might not have been sent yet by the Arduino, because both of the code executes at different timing. So to sync, we constantly check for the temperature data on the Python code before proceeding with the rest of the program.
NOTE: Both the RaspberryPi's Python code & Arduino code utilizes a syncing method called Handshaking. If the RaspberryPi is not ready to receive another temperature/user information, the Arduino would not allow the user to tap the card, vice versa.
A simple way I did that is to constantly send a "READY" signal till the other party sends back a "RECEIVE" signal so they know that they are both ready.
Arduino -
boolean readySignal = Serial.readString() == "READY";
if(readySignal)
{
tapped = true;
Serial.println("RECEIVED");
}
Python -
while(readySignal == True):
ser.write(b'' + "READY")
receivedSignal = ser.readline().strip() == "RECEIVED"
if(receivedSignal == True):
readySignal = False
Remember to close your query connection every-time you're done with a query! This is to eliminate any possible memory leak and it's a good practice overall.
HOW IT WORKS: Sigfox (SiPy)After receiving the temperature data from the Arduino, the SiPy will separate the userID, and the temperature into whole numbers and decimal places. After doing this, all the data is sent to the Sigfox backend through bytes (so that it can be sent to Ubidots as well as ThingSpeak)and should look something like the following picture.
After receiving this, the Sigfox backend will re-code this data to be sent to ThingSpeak to be stored. The following will show you how to code the backend for sending data to thingspeak.
In the Sigfox Backend under device type > Device Name > CALLBACKS, you will need to put in the custom payload exactly as itis unless you have changed the coding in the SiPy as the custom pay load will set what is received first as the userID, so for example if you send up the temperature first, on the backend it will convert that temperature to the userID instead of temperature. In the body, the write api key needs to go on top, while the fields can be placed with any of the custom data you have created in the custom payload.
After the data is successfully sent up to ThingSpeak, it first receives it in a private viewing channel where a MATLAB Analysis script analyses the data and combines the temperature data into one value instead of the separation of a whole number value & a decimal value.
The table code was taken from an open sourced project and modified to suit our needs. It's very useful as the table auto updates every time a new data is sent in, perfect for our usage.
At the same time, it checks if the temperature is at a dangerous level (fever), if so, an email will be sent to notify the staffs/teachers.
In summary, the first channel that has the temperature value separated in whole number & decimal number is a backend channel, not really for viewing. For the second channel, the temperature values have been combined and made nice for staffs/management/administrators to view and has an Excel-like table for easy data analysis.
1. Arduino Nano Connections SetupFor the Arduino Nano, here are the connections we have made with our modules.
Nano and Uno have the same Pinout.
RFID - RC522
SDA D10
SCK D13
MOSI D11
MISO D12
IRQ UNCONNECTED
GND GND
RST D9
3.3V 3.3V
How to test RFID
LCD
SDA A4
SCL A5
GND GND
5V 5V
How to test I2C LCD
Distance Sensor
5V 5V
GND GND
Input A0
How to test Sharp IR Distance Sensor
Buzzer
GND GND
Output D6
How to test Buzzer
IR Temperature Sensor
SDA A4
SCL A5
GND GND
5V 5V
How to test the IR Temperature Sensor,
LED
Flat Side(cathode) GND
Non-flat Side(Anode) D7
Good! For the Arduino connections, you should be good to go now.
2. RaspberryPi SetupThere are mainly two things that needs to be installed onto your Raspberry Pi 3 machine,
1. Raspbian OperatingSystem-
The installation of the Raspbian Operating System is considered fairly straight forward.
A short answer on how to do it would be flashing (writing) an image file onto a SD card and slot this SD card into the Raspberry Pi 3.
However, if you're looking for a step by step long answer tutorial, here's how to do it -
Firstly, you have to download a software that allows you to flash.img files into a storage drive. You can use the software called balenaEtcher.
Afterwards, head to the Raspberry Pi - Raspbian page and pick a one that suits your need. I chose the "Raspbian Buster with Desktop and recommended software" because like the name says, it comes with recommended software and that saves you the extra hassle of downloading softwares.
Once you're done with the aforementioned steps, simply launch the balenaEtcher software. This step is pretty self explanatory: Select the image (your.img Raspbian file), then select your SD card, and press flash. Now, you just have to wait. Once it's done, it should prompt you and you can now insert the newly flashed SD card into your Raspberry Pi.
Following this, connect your Raspberry Pi machine via HDMI to a monitor and do your initial setup. Lastly, head to Preferences -> Raspberry Pi Configuration and you should be on this menu -
Follow the options, this step enables interfaces like SSH, VNC that allows you to connect to ip addresses via eth0 or wlan0 (So you don't need the HDMI cable anymore, you can do it all via SSH).
(optional step) - I open the terminal and edit the dhcpcd.conf file (sudo nano /etc/dhcpcd.conf) and I add these command lines,
interface eth0
static ip_address=192.168.0.11/24
The above allows me to connect to the Raspberry Pi via an Ethernet Cable with the static address, 192.168.0.11, so I know every single time that, that is my Raspberry Pi's address.
This is an option step as, once you're connected to WiFi, you will gain a wlan0 ip address that allows you to connect to the Raspberry Pi without an Ethernet Cable and anywhere in the location as long as you're connected to the same WiFi. To see what's your wlan0 IP ADDRESS, simply hover your mouse over the WiFI symbol located at the top right and it'll indicate.
Nice! You're done with your initial Raspberry Pi's setup!
3. MySQL Database SetupI would consider this step a little difficult, especially the part where you have to setup the MySQL root user, follow it carefully because it's very difficult to rectify any errors.
First, you have to make sure your system is upgraded and updated to the latest firmware. You can make sure by entering these commands,
sudo apt update
sudo apt upgrade
After this is done, you will install apache2.
sudo apt install apache2
Apache2 will allow you to create a web server so you can access the websites you create later.
Once apache2 is installed, you need to install PHP.
sudo apt install php php-mbstring
PHP will allow you to create and see your own PHP websites.
Let's stop and see if everything you just installed is working, simply type your Raspberry Pi's IP in your web browser or "localhost" if you're still connected via HDMI, and you should see an Apache index page.
Now, you will need to install the database. For this, you will be using MySQL and mariadb.
sudo apt install mariadb-server php-mysql
IMPORTANT - Please make sure you read what's below very carefully.
Now, you will create your MySQL root user so you can use it to access the database.
sudo mysql --user=root
You will now enter a MySQL session where you can type MySQL codes, type these line by line, (You can replace password with your own password)
DROP USER 'root'@'localhost';
CREATE USER 'root'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;
You can now test your MySQL root user by logging in;
mysql --user=root --password=yourmysqlpassword
If it all works, now you can install PHPMyAdmin, the Administrator Control Panel for you to access (view) and modify the MySQL database.
sudo apt install phpmyadmin
(after installation)
sudo phpenmod mysqli
sudo /etc/init.d/apache2 restart
Congratulations! You can now access your newly made database using http://your_raspberrypi_ip_address/phpmyadmin.
Firstly, you will need to insert the SiPy Module onto the Expansion Board with the reset button facing the USB Connector and should firmly click into place with the pins no longer visible.
Source: Pycom Documentation
After doing that, you will need to update the firmware on the SiPy, so that you can upload and run programs as well as getting the Sigfox Device ID and PAC number which will be used to register for the Sigfox backend. Download the firmware updater according to what OS(operating system) you are using.
After downloading the pycom firmware upgrade, when you start the updater for the first time, the following pictures will only occur once so ensure you select the correct Sigfox Region, Board.
Follow the instructions on the firmware update carefully as it can cause your Sigfox to not function properly like the Sigfox Device ID and PAC number being all "F" (like below) instead a mixture between numbers and alphabets.
b 'FFFFFFFF'
b 'FFFFFFFFFFFFFFFF'
Once the firmware has been updated, you will need to download Visual Studio Code and install the extension Pymkr as well as nodejs before you can start uploading and running programs on the SiPy.
Firstly, you will need to create a new folder to save all the files you are going to upload into the SiPy later on or just to store all the programs you are going to run. Press file at the top left corner and press Open Folder or Ctrl+K+O, then select where you want to put this folder and right click to create a new folder. After that, create a new file or Ctrl+N to open a new file. After creating a new file, you will need to save the new file as a python and change the save as type to python file so that the code can be run on the SiPy later on and save it into the new folder you created.
Note: File Name can be anything like Test, Trial, Etc.. But if uploading into the SiPy file name need to be called main.
To just run your code without uploading it into the Sipy Module all you have to do is press the run button located at the bottom of the program. The upload next to it uploads the current folder to the SiPy Module. Be careful when using while 1 loops as once these are uploaded into the SiPy Module, the only way to access the SiPy Module again is to FTP into the flash and remove the main.py file from the SiPyModule.
If you accidentally added a infinite while loop, there's no need to worry as you can still upload your program or remove the previous one through FTP. Firstly, go and download filezilla free version and install it.
After installing, you will need to setup the connection. Firstly open up filezilla and go to site manager which is under file or press Ctrl+S and press new site.
You can rename the site to SiPy or whatever you want to call this connection and change the settings for encryption to Only use plain FTP (insecure) and transfer settings to passive and limit the number of active connections to 1
You can find the Host (address), User and Password through Visual Studio Code by pressing all commands and selecting global setting. This will show you the default settings for the Host (address), User (username) and password. This can be changed by pressing the project settings in all commands.
Next you will need to know the SiPy Module SSID which can be found using all commands and pressing get WiFI AP SSID. Each SiPy Module SSID will be unique but the password is the same throughout and cannot be changed. Password for SiPy Module SSID is www.pycom.io
Note: Desktop Users will need to get a WiFi adapter
Now you can start using filezilla to access the SiPy Flash! Firstly connect to the SiPy SSID, then go to filezilla site manager and connect to the new site you created and type in the password. Now open the flash folder and delete main.py ONLY! After deleting the main.py, restart the SiPy and you can start running/uploading your programs.
Note: You might want to copy the flash folder onto your OS (Operating System) in case you delete everything.
5. Registering with Sigfox BackendAfter installing Visual Studio Code, connect the pycom extension board to the computer and it will automatically detect the connection when you open Visual Studio Code. Copy the code below and either paste it into the terminal or into a file and run it. Either method will do.
from network import Sigfox
import binascii
# initalise Sigfox for RCZ* (You may need a different RCZ Region)
sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ*)
# print Sigfox Device ID
print(binascii.hexlify(sigfox.id()))
# print Sigfox PAC number
print(binascii.hexlify(sigfox.pac()))
Note: Replace * with your RCZ Region Number.
Terminal Method to get Sigfox Device ID and PAC number
To bring up the terminal in Visual Studio Code Press Ctrl+~. Then paste the code inside and it will show like the following picture.
File Method to get Sigfox Device ID and PAC number
Once the new file is saved by pressing Ctrl+S or going to file then save, paste the code into the file and save the file then you can run the file by pressing the run button at the bottom of the screen and should get the same as the picture below.
After getting your Sigfox Device ID and PAC number, you will need to register your Sigfox to the Sigfox Backend before you can start transmitting to it. The first page you see will be where is your sigfox company based. You have to choose the country in which this Sigfox device will be used in as each of the Sigfox Zones are configured differently.
After choosing the correct country, the next page will require your Sigfox Device ID and PAC number which you have gotten in the beginning of this chapter. Paste them into correct field and the page should look like the picture blow. As for the rest fill up accordingly.
After filling up the device page, Create a Sigfox Account or login to an existing Sigfox Account, you have to register the Sigfox to your account. If your're creating a new Sigfox Account, Sigfox will send you an email to the registered email to set up the password.
After you have setup your sigfox backend account, you can run this code to send up some data to see if the backend can receive them.
Note**: Connect your sigfox antenna first before running any sigfox program.
from network import Sigfox
import socket
# initalise Sigfox for RCZ* (You may need a different RCZ Region)
sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ*)
# create a Sigfox socket
s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)
# make the socket blocking
s.setblocking(True)
# configure it as uplink only
s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False)
# send some bytes
s.send(bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]))
Note: Replace * with your RCZ Region Number.
6. Setting up the CloudFirstly, you will have to setup the IFTTT for emailing, go to the IFTTT website and create an account. After setting up the account and logging in, go to your profile which is located near the top right corner of the screen on the left side of the “Explore” and press on the Create.
Click "This" and then search for Webhooks and press it. If you are unsure, the following pictures will help you with what to do.
After selecting Webhooks, press the Receive a web request box and enter an event name to fit your requirements (in this example fever is used), afterwards press Create trigger.
Press the word "That", type email in the search box and press Email then press Send me an email box
Enter message information. You can pass data about the event that triggered your message by using ingredients. For example, including {{Event Name}} adds the event name to your text message. The Body section must include at least {{Value1}} and {{Value2}}. Click Create action to finish the new applet. Note: Value 1, value 2 and value 3 in body message are derived from MATLAB Analysis and can be modified according to your requirement
ThingSpeak is an IOT (Internet of Things) platform which can be easily setup, learned and is open source.
First, we create two channels; (SIGFOX) TEMPERATURE PRIVATE VIEWING & (SIGFOX) TEMPERATURE PUBLIC VIEWING.
For the (SIGFOX) TEMPERATURE PRIVATE VIEWING, its purpose is to obtain data from the Sigfox backend. Sigfox sends up using bytes, this is because, we have realised that Ubidots (a web service) do not really work well with decoding Strings, so to make it work and accessible with both ThingSpeak and Ubidots, we chose to use bytes as it contain numbers from 0-255.
Therefore, using bytes makes it so we have to send both the whole number and the decimal number of the temperature information separately. So, this channel is mainly for keeping these messy values, later transferring to another channel for viewing which is the (SIGFOX) TEMPERATURE PUBLIC VIEWING channel.
We use MATLAB Analysis to convert the two messy values (whole number & decimal number) into just one combined value and transfer it onto the other channel. At the same time, we also transfer the userID onto the (SIGFOX) TEMPERATURE PUBLIC VIEWING as it's used for viewing. The MATLAB script is triggered on data insertion using a ThingSpeak REACT which will be explained below.
To setup the react, first go to Apps and then select React which will open the reacts tab. Press New React to create a new react for the MATLAB Analysis to be triggered when new data arrives from the Sigfox backend. Set the condition type to string, test frequency to on data insertion, condition to field 3 (which should be your userid) of the (SIGFOX) TEMPERATURE PRIVATE VIEWING when its not equal to 0, action to MATLAB Analysis with the code for calculating the temperature and Options to Run Action only the first time condition is met.
The table code was taken from an open sourced project and modified to suit our needs. It's very useful as the table auto updates every time a new data is sent in, perfect for our usage.
Unfortunately, the MATLAB plugin for the table is only view-able in private view and not in the public view. As it's intended for administrative purposes only, we do not subject this as an issue, it's intended to be only viewed in private view.
To retrieve Webhooks information, Click on your profile logo near the top right corner of the screen on the left of the “Explore” tab. Select My Services, select Webhooks then click documentation near the top right of the web page, from there you can see your key and format for sending a request. Enter that event name. The event name for this project is fever
https://maker.ifttt.com/trigger/{event}/with/key/(example)
https://maker.ifttt.com/trigger/fever/with/key/(example)
The service can be tested to see if it works or not by pasting the URL(example of the URL are shown above) into your browser or pressing the test button upon creation of the webhooks and email applet
After all that is done, you should be able to receive an email like the following picture, after you have finished setting up the ThingSpeak React.
Aden - RaspberryPi + Arduino + its modules + ThingSpeak (MATLAB+ Setup)
Reginald - Sigfox + ThingSpeak Data Collection + Schematics
Bo Sheng - IFTTT Setup
Comments