# Carbon Oxides Gases for Occupancy Counting and Emergency Control in Fog Environment
## 2 Materials and Methods
### Simulation Platform
#### 2.3.3 FogDevice  
This class specifies hardware characteristics of Fog devices and their connections to other Fog devices, sensors and actuators. _FogDevice_ is extended from the _PowerDatacenter_ class in CloudSim, it has attributes, such as accessible memory, processor, storage size, uplink and downlink bandwidths. _FogDevice_ also defines resources scheduling, modules deployment policy, etc. Notice that Fog device can compute the processing time of a tuple. However, it does not have the ability to analyze real data. Taking this limitation into account, we modify _FogDevice_ class and add data process unit to function _executeTuple()_ as presented in Algorithm 1. The Fog device firstly judges whether a tuple is sent from a sensor and has not been processed. Only if this Fog device has data analysis capacity, the tuple will be stored in the buffer list. Line 2 to 5 limits the buffer size of a sensor, and ensure it carry the latest tuples. Step 7 loads the machine learning model and predict occupancy and state. Details about the prediction model are given in the following paragraph. ```
1:Tuple
2:Tuple
3:Tuple marked with _occupancy_ and _state_
4:if the tuple is sent from south to the current

==ERROR: No output for this page==
Figure 10 compares the average delay of different physical topology configurations. The delay measures the time spent to complete a control loop. It starts from when a Tuple is generated, and after intermediate processing, finally displaying results. Cloud-only configuration has longer delay than edge ward. This is mainly caused by network congestion and longer latency to link remote cloud. Figure 11 shows the network usage of the five different topologies. All of them show an increase usage of network as the number of sensors increase. Cloud-only configurations requires more network because all the sensor data needs to be sent to the remote cloud which pass through more gateways. By contrast, edge ward mode can process data from nearest computing center which reduces the additional transmission. Figure 12 gives the energy consumption of Cloud, fog and coordinator devices in the application. Figure 13 presents the execution time of different topologies and input workload. +++

## 4 Conclusions

In this paper, we mainly focus on an application of WSNs, where carbon oxides gases are collected and analyzed. The concentration of CO\({}_{2}\) is used to estimate human occupancy, as this is important for energy conservation. On emergency condition, the rough information about the number of humans can be useful for rescue. In addition, when potential fire occurs, the content of CO and CO\({}_{2}\) changes significantly. The combined carbon oxides gases are monitored which is useful for emergency control before the fire spreads widely. We also improve iFogSim and simulate the system in the improved iFogSim. Compared with Cloud environment, application in Fog shows some merits, such as less latency, network usage and energy consumption. With respect to our future works, we will collect more data in different sizes of rooms with different numbers of people, and then try to use different methods to build a better model between the occupancy of people and CO\({}_{2}\), such as neural networks, deep learning, etc. Furthermore, other topologies will be taken into account when simulating the WSNs. Figure 12: Energy consumption of devices in Cloud and Fog execution. Figure 13: Execution time of simulation for varying size of topology and input workload. **Acknowledgments:** The authors are grateful for financial support from the research grants (1) 'Nature-Inspired Computing and Metaheuristics Algorithms for Optimizing Data Mining Performance' from the University of Macau (grant No. MYRG2016-00069-FST); (2) 'Building Sustainable Knowledge Networks through Online Communities' from the University of Macau (grant No. MYRG2015-00024-FST); and (3) 'A Scalable Data Stream Mining Methodology: Stream-based Holistic Analytics and Reasoning in Parallel', from FDCT, Macau government (grant No. FDCT/126/2014/A3).