# Open-Source MQTT-Based End-to-End IoT System for Smart City Scenarios
## 4 Proof-of-Concept
### Gateway Interface to Sensing Layer: The ESP32 Platform  
As stated before, the first goal of the proposed IoT architecture is to integrate wearable devices, requiring the development of the software that manages the data, as well as the connections of each node with the rest of the architecture, and a feasibility study of the hardware, in particular the SoC and the sensors. We predicat that the microcontroller with the sensors will be worn by the users, providing a fully functional smart-device. With these premises, one of the issues we aimed to solve was determining which microcontroller would best fit the requirements that a wearable solution, due to the constrained sizes of the device, generally requires, even though it is difficult to have a system where all these requirements are met. In order to process the stream of data acquired by the sensors, we have decided to use the ultra-low power SoC ESP32 [18], having all the most updated state-of-the-art characteristics of low-power chips, such as clock gating, power modes and dynamic power scaling. The ESP32 SoC is a single 2.4 GHz WiFi and Bluetooth combo chip designed by the Taiwan Semiconductor Manufacturing Company (TSMC) ultra-low-power 40 nm technology, which mounts a Tensilica Xtensa LX6 dual-core microprocessor together with 448 KB of ROM, 520 KB of SRAM and 4 MB of flash memory. Moreover, by having a look at the architecture, the Ultra Low Power co-processor stands out, which is an FSM (Finite State Machine) designed to perform measurements using the Analog/Digital Converter (ADC) or external Inter-Integrated Circuit (I2C) sensors, while the main processor is in deep-sleep mode; this is particularly important as it is used to wake up the chip from its sleeping mode. In the literature, there are many use cases [24; 25] where this SoC is used; such applications range from IoT solutions to much more complex systems, such as voice encoding or music streaming, where a huge quantity of resources are involved. The main reason for choosing the ESP32 SoC is that it jointly implements Bluetooth and WiFi connections with a very efficient power management scheme, which permits drawing a current as low as 10 \(\upmu\)A when it is used in sleep-mode; for what concerns the transmission of BLE packets, the datasheet defines 130 mA as the typical power consumption considering measurements taken with a 3.3 V supply at 25 \({}^{\circ}\)C of ambient temperature. This microcontroller's advantages make it a feasible chose for IoT devices;indeed, there are many examples of plug-and-play devices that are currently available on the market to purchase. Among others, it is worth citing the LilyGo platform, which is an open-source hardware Smart Watch based on the ESP32-PICO-D4 [26]. In addition to the ESP32 platform, we considered an external sensor device. In particular, we resorted to the BME280 [27], an integrated environmental sensor developed by Bosch Sensortech, offering the possibility of sensing the relative humidity, the barometric pressure and the ambient temperature. This chip, with its 8-pin metal-lid 2.5 \(\times\) 2.5 \(\times\) 0.93 mm\({}^{3}\) LGA package, has mainly been developed for IoT devices, particularly wearable devices, where size and low power consumption are key design parameters. Current-wise, it is indeed perfectly feasible for low current consumption, and it has a 0.1 \(\upmu\)A current consumption when it is in sleep-mode and 3.6 \(\upmu\)A when it is in active-mode. In the developed prototype, we use a pre-build module based on the BME280, where it is integrated together with a Low Drop Out (LDO) Voltage Regulator and a I2C Voltage Level Translator. The connection between the BME280 module and the ESP32 is implemented through the I2C connection interface, which allows having synchronous communication between the two devices and a data-stream with a bit rate equal to 100 kb/s.