## 3 Network Architecture Description
### Sensor Nodes Layer  
The sensor node architecture is the standard one of any node-forming WSN (see Figure 2), and this section highlights the modularity and flexibility of the network. In general, the node in its minimal form is composed of a microcontroller, an energy source,  
Figure 1: Network architecture overview. sensors and/or actuators, and a transceiver. Each of these components could be an off-the-shelf solution as well as an ad hoc customised one. The microcontroller is the core of the device since it is in charge of managing all of the peripheral, along with carrying out all of the routines that are hardcoded in its firmware. The energy source could be either a non-renewable one (e.g., batteries) or a renewable one (e.g., solar energy). Of course, this choice is strongly dependent on the application scenario and on the overall system requirements. In addition, miscellaneous electronics are usually required to correctly power the sensor node (e.g., voltage regulators) or to properly exploit the selected renewable energy source (e.g., battery management systems). Similarly, the choice of sensors and actuators is fully subject to the extent and the type of physical phenomenon to be monitored (e.g., temperature or humidity) or to the kind of action to be executed (e.g., controlling the state of an opening, or switching on and off external appliances). Finally, the transceiver is fundamental for providing the node with connectivity to remotely control it and to allow the node to send data. Sensor nodes within the network of this paper can alternatively embed LoRaWAN or NB-IoT transceivers. LoRaWAN Nodes bidirectionally communicate towards the LoRaWAN-NB-IoT multi-protocol Gateways by exploiting LoRa modulation as it usually happens within standard LoRaWAN networks. Similarly, NB-IoT Nodes establish a bidirectional communication with the eNodeBs. However, NB-IoT Nodes exploit the MQTT protocol over NB-IoT to send and receive information. Thus, the network allows for both uplinks and downlinks. At the same time, NB-IoT Nodes are capable of setting up subnetworks with the aim of establishing a peer-to-peer paradigm that still relies on MQTT. Such a feature provides for an autonomous connectivity scheme to which the nodes can resort whenever neither actions from users nor controls at the Cloud Layer are required. For instance, this technique is effective in all contexts in which the state of an actuator must be changed upon the occurrence of a given event that is properly sensed at the edge of the network. MQTT protocol was originally invented by IBM two decades ago. As it is stated in its reference website [28], MQTT is a publish/subscribe, extremely simple and lightweight messaging protocol designed for constrained devices with low bandwidth and high latency within unreliable networks. The design principles are to minimise network bandwidth and device resource requirements whilst also attempting to ensure reliability and some degree of assurance of delivery. These principles also turn out to make the protocol ideal for emerging Machine to Machine (M2M) or the IoT world of connected devices and for mobile applications where bandwidth and battery power are at a premium. In MQTT systems, there are a multitude of clients communicating with a server, which is also known as a broker, once they establish a prior connection to it. Clients may be either publishers and subscribers. In particular, a client could behave as a publisher and a subscriber at the  
Figure 2: Sensor node general architecture block scheme. same time. Publishers exchange messages enveloping information with subscribers by posting them on topics that have a hierarchical structure (e.g., this/is/a/topic), to which clients have subscribed. Between publishers and subscribers, there is the broker, whose task is to take charge of all of the messages posted by the publishers and to forward them to any clients that have subscribed to the topic on which those messages were posted.