# IoT Based Smart City Bus Stops
## 4 Proposed System Software Architecture  
The system's software architecture is divided into three layers: data acquisition and processing layer, storage layer, and mobile app layer. As shown in Figure 1, the data acquisition and processing layer is responsible for acquiring the real-time data from sensors that reflect the status of the bus stop, which is installed in a RPi at the bus stop. The RPi reads the status and values of a bus stop light sensor, temperature sensor, humidity sensor, motion sensor, smoke sensor, and air pollution sensor. The program was developed using \begin{table}
\begin{tabular}{c c c c c c} \hline \hline  & \multicolumn{2}{c}{**Arduino**} & \multicolumn{2}{c}{**RPi**} & \multicolumn{2}{c}{**Justification**} \\ \hline  & **Score** & **WS 1** & **Score** & **WS** & \\ Cost (15\%) & 8 & 120 & 6 & 90 & Arduino UNO: 295, RPi3: 35\$ \\ Memory (7\%) & 3 & 21 & 8 & 56 & Arduino UNO: 2 KB SRAM, RPi3: 1 GB SRAM \\ Remote Access (15\%) & 3 & 45 & 10 & 150 & Arduino UNO: Needs Extra WiFi Shield, RPi3: \\ Available & I/O Pin Availability (16\%) & 5 & 80 & 10 & 160 & Arduino UNO: 14 I/O, RPi3: 26 I/O \\ Power Consumption (18\%) & 7 & 126 & 3 & 54 & Idle Arduino UNO: 232.5 mW, Idle RPi3: 1.9 W \\ Clock Speed (10\%) & 1 & 10 & 10 & 100 & Arduino UNO: 16 MHz, RPi3: 1.2 GHz \\  & & & & & & Arduino: Size and weight depends on added \\ Weight \& Size (15\%) & 5 & 75 & 7 & 105 & shields, RPi3: Credit card compact size \\
**Total Weighted Score** & & **477** & & **715** & \\ \hline \hline \end{tabular} \({}^{1}\) WS = Weighted Score.  
\end{table} 
Table 1: Edge devices alternative comparison. Python and is divided into several functions. At the start of the program, a function is called to configure the I/O ports of the RPi. The program then returns the temperature and humidity sensor values in \({}^{\circ}\)C and RH%, respectively. It communicates with the light sensor to read a value relative to the light intensity in the surroundings. It detects the motion of commuters entering and existing at a bus stop. It also outputs a value relative to the levels of smoke in the vicinity of the sensor and communicates with the air pollution sensors to read air pollutant levels. The program reads light levels reported by the light sensor and compares them to a threshold value to determine if the indoor bus stop lights need to be turned on. It also compares the temperature to a threshold value to determine if the air conditioning needs to be adjusted. Finally, the program transmits data collected from all sensors to the remote database, which is the storage layer. The flowchart of the data acquisition and processing layer is shown in Figure 2.  
The second software layer is the data storage layer. This layer consists of a cloud hosted remote database called Firebase. The Firebase platform provides a real-time database that we used to store the bus stop sensor data. Data are stored in JSON format in the Firebase real-time NoSQL database. When Firebase detects a change or insertion of new data in the database, it triggers an event that pushes the most recent values to the third layer, which is the mobile app layer. Figure 2: Flowchart of the control and processing layer. The third and final layer is the mobile app layer, which is the top most layer that the end-user interacts with. It is responsible for enabling the visualization of information to the mobile app users (i.e., the bus stop maintenance personnel) and runs a background service for notifications. In addition to Firebase, the mobile app uses an SQLite database local to the device to store daily and monthly averages of temperature and pollution levels. This allows the app users to view the statistics for each bus stop. The software of this layer was developed using the Android Studio IDE. The app's implementation consists of Graphical User Interfaces (GUI) for signing in, viewing the map, and for viewing the bus stop status and statistical graphs. The app runs a background service to receive sensor readings from Firebase and to send notifications to the app users.