Bluetooth 5 Energy Management through a Fuzzy-PSO Solution for Mobile Devices of Internet of Things

Energy efficiency is a fundamental requirement for a wireless protocol to be suitable for use within the Internet of Things. New technologies are emerging aiming at an energy-efficient communication. Among them, Bluetooth Low Energy is an appealing solution. Recently, the specifications of Bluetooth 5 have been presented with the purpose to offer significant enhancements compared to the earlier versions of the protocol. Bluetooth 5 comes with new communication modes that differ in range, speed, and energy consumption. This paper proposes a fuzzy-based solution to cope with the selection of the communication mode, among those introduced with Bluetooth 5, that allows the best energy efficiency. This communication mode, used by mobile devices, is dynamically regulated by varying the transmission power, returned as the output of a Fuzzy Logic Controller (FLC). A Particle Swarm Optimization (PSO) algorithm is presented to achieve the optimal parameters of the proposed FLC, i.e., optimizing the triangular membership functions, by varying their range, to reach the best results concerning the battery life of mobile devices. The proposed FLC is based on triangular membership functions because they represent a good trade-off between computation cost and efficiency. The paper presents a detailed description of the FLC design, a logical analysis of the PSO algorithm for the derivation of best performance conditions values, and experimental assessments, obtained through testbed scenarios.


Introduction
The Internet of Things (IoT) is a model that aims to globally connect networks of physical and virtual devices, whose core is represented by the mixture both of different technologies and distributed intelligence [1,2].The IoT scenarios need the scalability beyond millions of devices because it is clear that centralized solutions surely reach their bounds [3].In fact, in this case, if the central node collapses, then all network infrastructure is subject to the same problem because the various devices, belonging to the Network of Things, do not possibly have direct communication between those that are not coordinators.Obviously, the solution to this problem may be the implementation of network architectures where all nodes can communicate with each other and not just with the coordinator.As a consequence, the result would be a Machine-to-Machine (M2M) communication in a mesh network.In these last years, several standardized protocols and interfaces have been developed to address device heterogeneity and to enable universal access [4].The achievement of global connectivity was the goal.However, it is necessary to note that the resources afforded by the IoT devices not only need to be distinguished globally, but they must be addressable and discoverable [5].The same feature refers to services since their operation and interfaces need to also be identifiable.More in detail, the services should be loosely-coupled and must support mobility [6], but, at the same time, maintaining the Quality of Service (QoS) constraints [7].
Previously, wireless networks were viewed as highly unreliable and insecure [8].Nevertheless, over the past ten years, they have growth in reputation since clear advances have been achieved regarding the capacities of wireless connectivity, whereby, only in the last decade, wireless networks have been used by devices both with an end-user operating them actively and for transferring the network traffic.This result has been made possible since today's wireless technologies can be considered considerably improved and matured.As a consequence, the concept of IoT has reached the forefront of wireless devices [9].In fact, originally, the devices that now belong to the IoT were rigidly self-sufficient and had no network aptitudes.On the contrary, now many of them can be combined with a wireless network to afford automation and data management that was not achievable previously.The result is that with the extension of the IoT, more and more devices will depend on wireless networks.
The standardization of a wireless protocol is a primary requirement to accomplish the interoperability, not only between products of various vendors but also between different solutions, applications, and domains [10].The latter are of particular interest to IoT and wireless networks since the universal access to devices and sensors from various application areas, leading to new cross-domain applications, is an important purpose of the IoT.Considering the aim of wireless networks in IoT scenarios to grant data transfer between "things" and applications embracing several domains, the communication and information layer standards are of central concerns, but also different application areas might use generic functions [9].For these reasons, several wireless protocols have been developed and presented in these last years with the aim of becoming the reference standard for IoT applications.
Nevertheless, there is a central requirement that establishes a wireless protocol ideal and suitable for use in the IoT, which is the energy consumption [11].In common cases, the devices are battery-powered, as a consequence, a low-power characteristic is a fundamental requirement.For instance, in few cases, a possible solution is to develop ad-hoc devices [12].On the contrary, in the development of devices that use a wireless protocol, several solutions can be employed to improve the energy efficiency [13].In fact, the goal is to achieve the lowest possible power consumption.To this end, in [14], an algorithm for scheduling a beacon interval based on the video frame size distribution to improve the energy efficiency of wireless devices is introduced.The proposed algorithm employs the statistical distribution for the dimension of video frames and changes the lengths of awake periods in a beacon interval dynamically.However, although the proposed approach is interesting and fairly efficient, its applicability is not scalable to all wireless protocols.A smart solution for the management of battery-powered wireless device used in street lighting is proposed in [15] and subsequently further enhanced in [16].The reference scenario is a smart city of the Internet of Things.The approach introduced by the authors is interesting and the results obtained are promising both for street lamp management and for energy efficiency.However, these works can be further improved by applying new techniques, such as soft computing, to maximize even more the energy efficiency of wireless devices.A new distributed topology control solution for low-power IoT wireless communications is proposed in [17].The authors focus on the development of asynchronous and asymmetric neighbor discovery method by mixing the concept of the combinatorial block design.The collected results show that the solution proposed by the authors discovers neighbors quickly with minimum battery power compared with other protocols.Nevertheless, this approach to prolong battery life is only applicable in distributed topology control contexts.In [18], the authors introduce an energy-quality-balanced technique that operates in association with an energy-aware routing algorithm for wireless mesh devices.The goal is to maintain some degree of content delivery data rate trying to prolong the battery of wireless devices.The proposal is interesting and allows to obtain up to 23% energy savings.However, it is suitable only for wireless mesh networks.A new energy efficient algorithm is proposed in [19] to maximize the lifetime of a wireless network.This algorithm takes into account the coverage and the connectivity of wireless nodes.The aim not only is to extend the life of the wireless networks but also to meet the QoS metrics.The results of simulations are promising.Nevertheless, the solution has been only simulated, so the authors did not address both the feasibility and the viability on real hardware.In addition, the kernel of the approach relies on Medium Access Control (MAC) scheduling adjustment, which is not always feasible with all devices on the market.A new approach, based on a distributed fuzzy logic control method, is proposed in [20].This fuzzy logic engine is developed on each wireless network node to decrease the number of message transmissions.As a consequence, the battery life can benefit from the number of transmissions reduction.The approach presented by the authors is compared with other solutions in the literature, achieving only satisfactory results, but, even in this case, it has not been tested on real hardware.In fact, its implementation could be quite complex.The authors of [21] introduce a solution for joint duty-cycle and transmission power control management suitable for wireless networks.This approach takes into account the energy harvesting level as well as the wireless channel conditions.The authors simultaneously manage both the transmission period and the transmission power.In fact, the method introduced by the authors fits the wireless channel conditions and controls the transmission power to maintain a good link a to minimize the energy consumption.The approach is interesting, and the results are promising.However, mobile nodes are not taken into account by the authors.
It is clear that many approaches can be implemented to achieve an efficient battery management.Obviously, apart from these specific solutions, a remarkable contribution to a low energy consumption is given by the specific wireless protocol.Concerning the wireless protocols that can be employed in IoT applications, the choice is quite wide.Obviously, it is appropriate to briefly analyze only the protocols that in the last few years have received a larger agreement.Different functions can be automated in everyday life by embedding a small computer, with limited storage and communication capacities, in physical objects placed in the environment.As a consequence, these objects become smart.A possible wireless network of these smart objects employing the Internet Protocol (IP) is called 6LoWPAN [22], or IPv6 over Low-power Wireless Personal Area Networks.As it is known, IPv6 grants a large address space to connect billions of uniquely identifiable smart objects with the Internet.6LoWPAN could be an IoT enabling technology that should allow running the heavyweight IPv6 protocol in resource-constrained devices, by giving compression and fragmentation capacities.Unlike traditional wireless networks, 6LoWPAN networks are being deployed in environments where the users are an integral component of the system.Nevertheless, currently, this standard has not been integrated into any commonly used devices, such as smartphones, tablets, or computers.
Low-power IEEE 802.15.4 [23] is the standard in the link and physical layers for 6LoWPAN networks.Furthermore, ZigBee [24], another popular standard for WPANs (Wireless Personal Area Networks), is also based on the IEEE 802.15.4.It is designed to be a low-power and low-cost wireless mesh network standard originally formulated as a real alternative to Wi-Fi/Bluetooth Classic for self-organizing ad hoc digital networks.In fact, in ZigBee networks, any nodes can be the coordinator.However, the lack of native support for IEEE 802.15.4 in mobile devices (laptops, tablets, smartphones) is a real problem, mainly for mobile or temporarily mobile use cases.Even though IEEE 802.11/Wi-Fi [25] technology looks attractive for IoT, the system developers have quickly realized that the power consumption associated with this technology is too high, leading to a short active time before recharging.
Other new technologies are emerging aiming at an energy-efficient communication.Among them, Bluetooth Low Energy (BLE) is an appealing solution.It is useful to remark that in 2003 the Bluetooth technology was supposed to be dead [26], but, fortunately, that did not occur because Bluetooth has experienced great popularity and success in the last ten years in various application areas.Nowadays, this wireless protocol is aiming mainly to short-range wireless communication markets [27,28], such as the IoT and Machine-to-Machine (M2M) communications [29].Bluetooth Low Energy, also known as Bluetooth Smart [30], is a lightweight alternative to Bluetooth Classic designed for low-power resource-constrained devices.The Bluetooth Special Interest Group (SIG) introduced the Bluetooth Low Energy (BLE) to attract application developers of emerging IoT.BLE was first specified in Bluetooth 4.0 [31] and further enhanced in Bluetooth 4.1 [32] and 4.2 [33].Recently, the Bluetooth SIG has presented the specifications of Bluetooth 5 [34], whose main aim is to offer significant improvements compared to the previous specification, regarding the speed, range, and broadcasting capacity.In the twisted battle for the control over the IoT communication standards, these new advantages might help BLE to prevail and to become the ultimate standard for IoT.This article provides an overview of the new enhancements introduced by Bluetooth 5 and describes the potential benefits of each one.An analysis on how these improvements will enable current and future applications is presented, showing how Bluetooth 5 will be a very competitive technology in the envisioned IoT applications.Freshly, the Bluetooth SIG has introduced the specifications of Bluetooth 5 [34], whose main aim is to accomplish important enhancements compared to the previous versions of the protocol, concerning the speed, range, and broadcasting capacity.In the twisted battle for the control over the IoT communication standards, these new advantages might help BLE to prevail and to become the ultimate standard for IoT.
Nevertheless, for Bluetooth to be suitable for M2M and IoT applications [35], it must decrease the power consumption [36], so that it can be employed in battery-powered devices for a longer period.In fact, as mentioned above, IoT devices have to be connected, but power consumption is usually a real concern.For instance, considering wearable devices, such as fitness wristbands, the time between recharging could make or break the commercial viability of a product.For this reason, the improvements introduced by Bluetooth 5 [34] not only concern the speed, range, and broadcasting capacity but primarily aim at better energy management through the use of different communication modes.In fact, these modes can be set in the device according to its distance with the beacon node.However, the devices can be mobile, so it is not possible to use always the same communication mode when the distance to the beacon is variable.
This paper proposes a fuzzy logic based approach to coping with the choice of the best communication mode in Bluetooth 5 that allow the achievement of an efficient energy management.In the proposed smart solution, the communication mode of mobile devices is dynamically regulated, based on the transmission (TX) power, by a Fuzzy Logic Controller (FLC).In fact, the application of rule-based FLCs facilitates the implementation of multi-criteria control procedures.Fuzzy logic is capable of making real-time decisions, even with incomplete information.Additionally, a Particle Swarm Optimization (PSO) algorithm is presented in this paper to achieve the optimal values and parameters of the proposed FLC.In detail, the PSO is used to optimize the membership functions, by varying their range to reach the best results concerning the battery life of mobile nodes.PSO is an evolutionary calculation technique proposed by Kennedy and Eberhart in 1995 [37].It is part of Swarm Intelligent (SI) methods and is recognized as an efficient heuristic procedure for optimization problem in a continuous and multidimensional search spaces.In fact, for these optimization problems, the PSO algorithm reaches high-quality solutions through a lower computational cost, compared to other stochastic techniques such as Genetic Algorithm (GA).PSO is an all-around population-based optimization method and has its foundation in the SI algorithms.These last handle the configuration of smart multi-agent systems by receiving stimulation from the combined actions of social insects, such as termites, wasps, ants, bees and as well as from groups of animals-for instance, schools of fish or flocks of birds.In the PSO technique, the particles, which outline possible solutions, move around in the phase space with a velocity refreshed by the particle's experience, the experience of the particle's neighbors or the experience of the whole swarm.
PSO has been applied in many papers with the aim to optimize a FLC.For instance, in [38], the PSO is introduced for wind turbine converters, in [39,40] for photovoltaic systems, in [41] for neural networks training, in [42] for DC/DC converter, in [43][44][45] for energy management, in [46] for Unmanned Aerial Vehicle (UAV) management and control, in [47] for clustering, and so on.The results shown in all these works confirm that an optimization through the PSO can lead to valuable advantages regarding the performance of approaches based on a fuzzy controller.This feature is also valid in this paper because validations prove the benefits of the solution proposed in this work.Furthermore, to the best of our knowledge, there are no papers in the literature in which the PSO is applied for the optimization of a FLC to choice the communication mode in Bluetooth 5 that allow the best energy management.
This paper is organized as follows.Section 2 provides an overview of the new enhancements introduced by Bluetooth 5 and describes the potential benefits of each one.The proposed system model is introduced in Section 3, showing the design of the suggested intelligent FLC.Section 4 shows how PSO works and presents the proposed PSO algorithm for FLC optimization.Section 5 assesses the performance obtained in testbed scenarios and, finally, Section 6 concludes the paper.

Overview on Bluetooth 5
Contrary preceding versions of the Bluetooth standard, published as ".0" and succeeded by updates, such as Bluetooth 4.1 and 4.2, the new standard is simply known as Bluetooth 5.The classic version of Bluetooth 5 is equal to the previous, while the innovations focus on the BLE version.It is crucial to remark that according to the specification [34] introduced by the SIG, the hardware boards can support three types of Bluetooth connections.They are BLE 4.x, Bluetooth 5 at 2 Mbps, and Bluetooth 5 Coded.BLE 4.x is the connection model employed by the Bluetooth Low Energy spec, i.e., 4.0, 4.1 and 4.2.This connection type is identified as the BLE at 1 Mbps because that is its estimated rate at the lowest layer before protocol overheads are attached.Bluetooth 5 at 2 Mbps is the new high-speed connection that has been introduced with Bluetooth 5.In this case, at the lowest layer, its speed is 2 Mbps.Bluetooth 5 Coded is a new special connection type that comes with Bluetooth 5. Its aim is to implement long-range Bluetooth connections, but with a low bit rate.As a consequence, the main purpose is a larger range rather than speed.The specifications of Bluetooth versions are depicted in Table 1.Moreover, an analysis of the innovations that the SIG has introduced with Bluetooth 5 is carried out in the following subsections.x has a range between 50 and 100 m, which is reduced to 10/20 m in indoor environments due to walls or obstacles.Bluetooth 5 proposes to quadruple the range of BLE devices.In fact, in the worst case, this range should be 200 m outdoors and about 40 m indoors.This goal can be accomplished since Bluetooth 5 introduces a special connection type, developed for long distance communications.This operating mode aims at the IoT, where it is necessary to place low-cost nodes/devices all over a building or in an open space and collect data.These gathered data could be anything from temperature, light, humidity, traffic monitors or movement detectors, and so on.Nevertheless, these devices/sensors require to send their data to a central hub/gateway and, mainly, need a power supply.If the device is combined to the main electricity, then the power supply is not a problem.In this case, for instance, the device could use Wi-Fi to communicate.Nonetheless, the demand for energy consumption and Wi-Fi coverage restricts the scope and potential of such devices.
In this scenario, Bluetooth 5 can prove its strength.In fact, the devices that use Bluetooth do not necessarily need mains power.They could be placed with just a battery to power them.A feasible solution to increase the range without growing the energy consumption is to decrease the data rate.An awesome innovation of the PHY (physical layer) changes in Bluetooth 5 is the way for increasing the sensitivity.It is implemented only in the LE Coded connection type.Typically, in BLE, the packet headers and payloads are un-coded, i.e., 1 bit refers to 1 modulated symbol.This feature remains fixed for both 1 Mbps and 2 Mbps connection mode.However, in the LE Coded connection mode included in Bluetooth 5, two network data rates can be used, which are 500 Kbps and 125 Kbps.In these cases, the payloads have many symbols for each bit, S = 2 for 500 Kbps and S = 8 for 125 Kbps, where S is the symbol/bit rate (Table 2).As a consequence, more symbols per bit allows an extended tolerance with a poor signal to noise ratio, and still provide a recoverable data stream, whereby, a receiver can repair bit errors on the receiving side of a communication link.This mechanism happens completely in hardware in a transparent way to the developer.The coding process includes two stages.The first is the Forward Error Correction (FEC), and, subsequently, a pattern mapper outlines a bit code to the input bits.The result of these steps is a spreading of the data that provides a recovery using the FEC if bit errors occur.As a result, thanks to the mixed use of the FEC and the pattern mapping, an enhanced ability to recover the received bit stream is reached.This goal can be achieved in conditions, where the Signal-to-Noise Ratio (SNR) is lessened to a level that data recovery would be impossible without the LE Coded mode.Concerning the range, the question focuses on the selection of the 125 Kbps or 500 Kbps data rate.It is clear that this choice is strictly related to the needs of the specific application.In fact, with 500 Kbps, it is possible to obtain about twice the range of standard BLE at 1 Mbps, while, on the contrary, with 125 Kbps twice the range of 500 Kbps can be obtained.The bit time on air is different, becoming longer from 1 Mbps to 500 Kbps and then still longer to 125 Kbps.As a consequence, 500 Kbps allow to obtain the extra range and do not spend as long on-air time as 125 Kbps.In this way, the collision with other devices is reduced, at the same time, less power is consumed.However, considering the packet structure, when LE Coded mode is used, shown in Figure 1, a notable portion of the packet is the preamble address, and coding is at 125 Kbps all the time, even when selecting 500 Kbps, which happen in the 1 bit CI (Connection Interval) field of the packet.In fact, for quite simple sensor/actuator operations, for instance, from 4 and up to 8 bytes, it is not possible to save that much at 500 Kbps over 125 Kbps regarding collision avoidance or power consumption, while the larger range is sacrificed.Only the two following CRC (Cyclic Redundancy Check) fields (Figure 1) are read at 500 Kbps since everything else, i.e., the majority, is at 125 Kbps.As a result, for simple sensor/actuator operations, it is preferable to use 125 Kbps to get the extra range, while, for larger data transmissions of tens of bytes or more, the data rate of 500 Kbps can be employed to obtain its advantages.

More Speed
The increase in the data transfer speed is a crucial feature.Future wearable devices will synchronize with twice the speed of the current ones.The rate of current Bluetooth standard for delivering data to the platform is sufficient, for most applications.In fact, the speed is not a huge issue in many IoT utilizations that don't involve streaming.For instance, considering wearable devices, such as fitness wristbands, the amount of data to be transferred is almost modest, and the currently supported BLE data rate is sufficient.Nevertheless, even for such wearable devices, higher transfer speed can allow faster software and firmware updates and enhances the user experience.
It is useful to remark that, already with Bluetooth 4.2, significant improvements in network data throughput became possible.In fact, about 700 Kbps can be accomplished for the application data rate.This progress has been possible both through the extension of maximum packet size and other enhancements in the ratio between the data and the overhead.Bluetooth 5 consolidates the packet extension feature of Bluetooth 4.2.In fact, by increasing the on-air transfer speed, the achievable network data throughput is doubled, about up to 1400 Kbps.Earlier, a packet of data (actually 251 bytes) could be transported in a set time frame of 2120 microseconds.On the contrary, at present, with Bluetooth 5, the same data can be sent in 1060 microseconds.Nevertheless, a real doubling of the data rate is not achievable because the inter-frame space (the period between two consecutive packets) remains the same as with Bluetooth 4. The data is sent faster, but the gap among the packets has not been reduced.Anyhow, considering the specs and some mathematical calculations, right now Bluetooth 5 is about 1.7 times faster than BLE 4.2.In addition to opening up new application opportunities, another significant advantage of having a 2 Mbps data transfer speed is that the energy savings could be an option.For instance, assuming that both sides of the link support the 2 Mbps data transfer speed mode, it could be possible to carry out operations twice as fast as before on-air.Obviously, this feature involves being on-air half as long, i.e., using possibly half the RF (Radio Frequency) transmission energy on average.Moreover, due to less time present on-air, the risk of collision with other communicating devices can be decreased.This feature could be more helpful over time as many devices could shift to using the 2 Mbps mode for their communication activities.

Beacon Diffusion
Proximity devices and beacon systems are accessories and chipsets capable of automatically sending, to every device in the vicinity, localized information.Another important enhancement that arises with Bluetooth 5 is the extended broadcast capacity compared to previously versions.This improvement could have a meaningful result in the world of beacons and will grow the range of use cases for them.In fact, Bluetooth 5 also enhances the capability of sending special data packets, called "advertising packets".This communication strategy enables two Bluetooth devices to transfer packets and information even if they are not synchronized with each other.In the new standard, the packets are larger, and this makes it possible to send more information also to asynchronous devices.This perspective is fundamental to the development of an IoT network.
With larger packets and LE Coded mode, it is probable that advertising channels could become overfilled with traffic.This situation can usually occur on the three advertising channels with small packets, equal to or less than 31 bytes.On the contrary, when larger packets (up to 255 bytes) are used, a new non-advertising channel is negotiated, and the longer data packet is transmitted on this non-advertising channel.Both the variation in advertising and the use of non-advertising channels for data payloads involve a synchronization to make known both to the transmitter and the receiver where exchange data.This feature is known as the Advertising Extensions (AE), which represent a technique for transmitting Periodic Advertisements (PA) on a deterministic period to establish true connectionless broadcast.The PA uses a selection algorithm for channels and intervals in the same way as a connection occurs.

Battery Life
The increased range and speed could suggest a higher energy consumption.Nevertheless, thanks to some ingenious design, such as the way in which the signal is modulated and the improvement in the use of the frequency spectrum, Bluetooth 5 can use fewer energy resources.In fact, in the best case, it can consume about two times less power than the previous version of Bluetooth.If the speed is doubled in a wired device, the direct result is doubling of energy consumption.It should be noted, however, that Bluetooth also operates at 2.4 GHz and this radio frequency commands the power consumption, not the data rate.Bluetooth 5 allows exchanging twice the amount of data, and the result is that the device consumes half the power to transfer the same data.In fact, the PHY layer of Bluetooth 5 has endured its biggest change since the presentation of Bluetooth 4.x.Until now, the on-air data rate of 1 Mbps, at up to a maximum output power of +10 dBm, was the only one available for BLE.As mentioned above, the goals of Bluetooth 5 were extended range through greater sensitivity and higher peak output power, at the same time maintaining or reducing the average power.It is necessary to note that Bluetooth needed to be as good or better than comparative IEEE 802.15.4 solutions to become a real competing technology within living environments.For this reason, new BLE output power classes have been introduced in Bluetooth 5.

The Proposed Fuzzy-Based Solution
Mobile devices have now matured as an integral part of people lives.For instance, they have extensively employed everywhere in the society with many applications in various sectors, which include smart cities, smart houses, irrigation systems, healthcare and much more.What differentiates Bluetooth 5 from its antecedents is the way in which it manages the beacons, i.e., packets/messages that can be sent continuously from a "presenting" device and received by nearby mobile users on their smartphones, tablets or wearable devices.A Bluetooth 5 beacon does not need the pairing that occurs with headsets, speakers, and other Bluetooth accessories.Considering that the beacon can transmit information when a mobile Bluetooth-enabled device reaches into range, site-specific content, location-enabled marketing, process updates, and other applications become feasible.For instance, a typical case may be a big shopping center, within which each store will have its Bluetooth beacon capable of sending a message, maybe related to offers or promotions, to nearby users.
The new connection modes introduced in Bluetooth 5 allow having a much larger coverage range.In this way, the beacons can reach mobile devices located at distances that were previously unreachable.There is an import requirement that Bluetooth 5 must respect to be entirely suitable for the Internet of Things that is energy efficiency.The new power classes introduced in Bluetooth 5 allow a slightly better power management than Bluetooth 4.x.On the contrary, the choice of the proper communication mode (presented in Subsection 2.1) can surely improve the battery life of mobile devices.Obviously, the connection mode is closely related to the transmission power to be used.In fact, the latter enables to reach a greater or lesser range.The different connection modes of Bluetooth 5 can be applied in different application scenarios, but they differ mainly in the coverage range.However, in the case of mobile devices, it is not desirable to set a connection mode statically.In fact, considering the LE Coded mode at 125 Kbps , it is true that it reaches the maximum coverage range but does not guarantee the better battery consumption.If the mobile node approaches the beacon, its connection mode should be changed, for instance in LE Coded at 500 Kbps or after at 2 Mbps or 1 Mbps.In addition, as noted above, the application of different techniques, which are not usually provided by the protocol, can significantly increase the battery life of mobile wireless devices.
A generalized illustration of the solution introduced in this paper is represented in Figure 2. It clearly presents what are the input parameters of the FLC and also the one that returns as output.It is valuable to remark that the proposed FLC is employed to choose the communication mode in Bluetooth 5, based on the transmission power, that allow the best energy management of mobile nodes.The composition of the proposed FLC shown in Figure 2 is quite simple because it permits both an easy implementation on real devices and especially a low computational complexity.The proposed smart system involves small data exchanges, as the data to be managed by the FLC are the distance between the mobile node and the beacon and the battery level.As a consequence, there is a lower computing power.On the contrary, other methods based on complex fuzzy controllers (such as Type-2 fuzzy or Petri net), other schemes that employ many controllers in parallel or other solutions that take into account several parameters as input to the controller, need a higher computational cost.These benefits of the proposed FLC not only yield to realize the solution presented in this paper on low-cost devices but are also expected to be beneficial concerning lower data processing times and lower control actuation times for the fuzzy logic controllers.

Distance Estimating
As revealed in Figure 2, in the proposed method, the mobile node employs an FLC to determine the proper communication mode among those introduced in Bluetooth 5 (Table 2) based on the required TX power.However, the mobile node defines the communication mode also based on the battery level and its distance from the beacon.Different solutions can be adopted to evaluate this distance.Generally, in radio frequency communications, the Received Signal Strength Indicator (RSSI) is a widely used parameter for assessing both the quality of a signal and the distance between wireless devices.In fact, the RSSI is a measure of how strongly a device can "hear" a signal from another one, such as an access point, a router, or a beacon.Theoretically, RSSI is inversely proportional to the square of the distance between the two devices.Another method to determine the distance is to use the Friis equation, also applied and rearranged in the model proposed in [48]: where PTX is the transmit power; GTX and GRX are the antenna gains, so the total antenna gain is G = GTX + GRX; c is the speed of light (3 × 10 8 m/s); f is the central frequency (i.e., 2.44 GHz); n is the attenuation factor (i.e., 2 in free space); and, finally, d is the distance between transmitter and receiver (in meters).The distance d can be calculated from Equation (1) as follows: Nevertheless, it is essential to note that the model shown in Equations ( 1) and ( 2) can only be employed in theory.In fact, the correlation between the RSSI and distance becomes slightly more complicated both due to the environment (reflection, obstacles, noise) and to antenna orientation.Before clarifying how distance has been dealt with in this paper, further clarifications have to be made.In fact, usually, a misunderstanding can be generated when referring to dBm and RSSI.They are distinct units of measurement that, however, denote the same parameter, i.e., the signal strength.The RSSI is a relative index.On the contrary, dBm, seldom expressed as decibel-milliwatts or dBmW, is an acronym for the power ratio in decibels (dB) of the calculated power associated to 1 milliwatt (mW).The dBm value is employed as a useful measure of absolute power since of its ability to describe both quite large and quite small values in a short form.Considering that it is associated to the Watt, the dBm value is an absolute unit, used when estimating the absolute power.It is useful to note that the decibel (dB) is a non-dimensional unit, employed for determining the ratio between two values, such as signal-to-noise ratio.Regarding the RSSI, a higher value denotes a stronger signal.
Unlike the received power, the RSSI is a relative measure that is frequently established by each chip manufacturer.In fact, there is no standardized relation of each specific physical parameter to the RSSI interpretation.For instance, a manufacturer could have an RSSI range from 0 to −60 while another one will return RSSI values from 0 to −100.However, there is a certainty, that is the higher the RSSI value is, the better the signal is.Moreover, the RSSI estimation can be very helpful in the proximity applications, for instance, to obtain the trend of the RSSI values changes.In fact, this trend could provide very significant information, for instance, if the mobile device is going towards or away from the beacon.Furthermore, if the precise mapping between the RSSI and the location of the distinct receiving device is understood, it could be possible to have a quite accurate estimation of the distance, taking into account likely multipath effects.An example of the correlation between the distance and the RSSI is shown in Figure 3.It is clear that, when the RSSI is taken into account for proximity applications, the value floats in range due to the environmental influence.For this reason, is it useful to employ a "summarizing" statistic.In this paper, a sampling algorithm which gives the "Mode" (i.e., the value that occurs most frequently) of the RSSI sample set in a period has been implemented in the mobile node to filter out the environmental influence.The "Mode" has been chosen compared to other "summarizing" statistics, such as Mean or Trimmed-Mean, since the resulting value of RSSI was surely measured by the mobile device previously.In fact, it is the value that most frequently occurs.On the contrary, considering the other mentioned approaches, the final value of RSSI is the result of a different math processing, and possibly it has never been concretely measured by the mobile device.Then, in this latter case, the resulting value of RSSI could be incorrect (flawed).The value obtained using the sampling algorithm which gives the "Mode' can closely match the actual signal strength and filter out the noise.In addition, another characteristic that has been taken into account in the proposed solution is the Measured Power, i.e., a factory-calibrated, read-only constant on hardware, which specifies what is the expected RSSI at a distance of 1 meter to the beacon.As a consequence, combined with RSSI, the Measured Power permits estimating the distance between the mobile device and the beacon in a proper way.

Fuzzy Inference System
Following the explanation of the proposed Fuzzy Logic Controller design, it is now appropriate to focus on the fuzzy inference system that determines the TX power, and, particularly, defining briefly the membership functions considered in this paper.The proposed FLC employs three membership functions (Low, Medium, High) for each input and output variable.These functions fuzzify the crisp inputs, while their ranges are: , where 0 expresses the lowest level of battery while 1024 denotes the highest level of the battery, and it is the maximum value at the output of a 10-bit AD converter (with an appropriate electronic signal conditioning circuit); • TX power: [−20 ÷ +8] (dBm), where +8 dBm value is the maximum transmission power and −20 dBm is the minimum one considering the SoC (system-on-a-chip) used in this paper for performance evaluation, i.e., the nRF52840 (Nordic Semiconductor, Trondheim, Oslo, Norway) [49].However, this range can be adapted based on the specific SoC.
The triangular membership functions of the distance, battery level and the TX power are represented in Figure 4, where the degree of membership is realized by normalized values [0 ÷ 1].As depicted in Table 3 , the output value is determined through nine fuzzy rules based on the IF-THEN statement of traditional programming languages.For instance, considering rule 6, if distance is Medium and battery level is High, the TX power will be Medium.As it is acknowledged, in an inference mechanism the outputs are fuzzy variables.For this reason, the FLC must convert its internal fuzzy output variables in crisp values, by the defuzzification method, so that the actual system can handle them.Several approaches can perform the defuzzification process.In the fuzzy solution introduced in this work, the Centroid of Area (COA) method [50] has been preferred.In this scheme, the centroid of each membership function, for each rule, is first estimated.The final output is then estimated as the average of the individual centroid weighted by their membership values as follows: where Out i is the output of rule base i, and C i is the centre of the output membership function.

Particle Swarm Optimization
The PSO algorithm simulates the social behavior of groups of animals, such as a flock of birds to achieve optimal, or near optimal, solutions of a multi-variable objective function in a continuous exploration space.It is a population-based approach in which a swarm of particles, i.e., an assortment of individuals whose positions denote the candidate resolutions of the addressed problem, goes in the search space.The particle performance is based on its position and is measured using a cost function that depends on the considered optimization problem.The initial status of each particle is created randomly, and in each iteration, their movement, in the search space, is influenced by their current best position, called personal best position, and may also depend on the current best position of all particles of the swarm, called global best position.Considering a single swarm of size K, connected completely, and an N-dimensional search space, the velocity, and position of each particle are updated as follows: x k,n (t + 1) = x k,n (t) + v k,n (t + 1), (5) where 1 ≤ k ≤ K and 1 ≤ j ≤ N ; x k (t) and v k (t) are the position and velocity vector of the k-th particle at the t-th time step, respectively; p k (t) is the personal best position of the k-th particle at the t-th time step while g(t) is the global best position of all particles in the swarm at the t-th time step; r 1 and r 2 are random numbers uniformly distributed in the range [0, 1]; w is the inertia weight while c 1 and c 2 are the cognitive coefficients.The inertia weight is used to achieve a balance in exploration and exploitation of the search space and plays a key role in PSO convergence behavior.There are different techniques of setting this parameter, although to simplify the algorithm implementation may be fixed to a constant value.According to Equation ( 4), the velocity of each particle is adjusted based on the inertial component, which outlines its actual velocity, the cognitive component and the social component, which depend on the personal best and global best position, respectively.A pseudo-code of the PSO algorithm is summarized in Algorithm 1.Initially, the position and the velocity of each particle of the swarm is initialized randomly.For each particle, its cost function value is estimated so that the global best position in the swarm is detected.Iteratively, the velocity and position of the particles are refreshed according to Equations ( 4) and (5).If necessary, the personal and the global best position are updated according to the cost function of the particles.The loop is stopped if the termination criterion is satisfied.The global best position at the last iteration is the solution determined by the Algorithm 1.
Algorithm 1 Particle Swarm Optimization Pseudo-Code for (each particle) do initialize position and velocity; evaluate cost function; compute global best position; end for repeat for (each particle) do update velocity and position according Equation ( 4) and ( 5); evaluate cost function; update personal and global best position; end for until (termination criteria is met) return (global best position);

The Proposed PSO Algorithm
Considering the structure of the FLC shown in Figure 2, the controller inputs are the distance and the battery level, while the TX power represents the output.There are three membership functions for each input and output variable; therefore, there are nine fuzzy rules, as shown in Table 3.As stated above, triangular membership functions (Figure 4), for each input and output, are taken into account in the proposed solution.To optimize them through the PSO, they can be represented as in Figure 5.This representation is valid only for the triangular membership functions of the inputs and the output (Low, Medium, High).To simplify the implementation of the PSO algorithm, in this paper, it is assumed that the parameters a L , b M and c H , for each input and output, are fixed.In this way, there are eighteen membership functions parameters to optimize by using the PSO algorithm, and the structure of the generic particle for each input and output is given by: Considering the Figure 5, i.e., triangular membership functions, in the proposed optimization algorithm, it is supposed that the six parameters to optimize each input and output must meet the following criteria in the specified order: In each iteration of the PSO algorithm, it is necessary to check the constraints in Equation (7).A PSO assisted by a proportional technique is introduced in this paper to reduce this extra computational cost in such a way to increase the convergence speed of the algorithm.To clarify the presented PSO algorithm, it is useful to consider the n-th position of the k-th particle at the t-th iteration.It is necessary to note that the following constraint must be satisfied: where the constraints A k,n (t + 1) and B k,n (t + 1) have already been updated to the order considered in Equation (7).Moreover, it is useful to highlight that, eventually, only one of them can be modified.
The main steps of the proposed PSO, assisted by a proportional method, are: 1. if the position x k,n (t) does not belong to interval [A k,n (t + 1), B k,n (t + 1)], it is redefined proportionally as follows: otherwise, if x k,n (t) > B k,n (t + 1), then 2. update the velocity v k,n (t) in accordance with Equation (4).It is necessary to note that, in the scenario considered in this paper, the velocity n-th of the k-th particle at the (t + 1)-th iteration is: k,n (t + 1) are given, respectively, by: 3. update the position x k,n (t) in according to Equation (5).If the position x k,n (t + 1) does not belong to interval [A k,n (t + 1), B k,n (t + 1)], firstly the minimum and the maximum velocity value are calculated according to Equations ( 12) and ( 13), and then the position x k,n (t + 1) is redefined proportionally as follows:

PSO Performance
In this section, the performance of the PSO algorithm, introduced in this paper, are presented.In the solution proposed in this work, the inputs of the FLC are the distance and the battery level, while the output is the TX power of the mobile node.Considering that the main aim is to prolong the battery life, just the TX power is counted as fitness function, and the proposed PSO algorithm is developed to minimize it.The PSO performance has been examined considering different values of the swarm size, k = 5, 10, 20, 40, 50. Figure 6 shows the TX power achieved by the PSO algorithm averaged over 200 runs for 20 iterations.It useful to note that the simulations have been carried out with Matlab (R2016b, MathWorks, Natick, MA, USA).In each run, the PSO algorithm has been initialized randomly, the inertia weight has been set to w = 0.73, the cognitive coefficients have been set to c1 = c2 = 1.48, and the termination criteria has been 20 iterations.As was expected, the algorithm performance is enhanced by increasing the size of the swarm.The implementations of the PSO with k = 20, k = 40 and k = 50 reach convergence, i.e., the minimum TX Power, around after the first six iterations.It is valuable to note that the implementation with k = 50 has a higher speed convergence than the other implementations because it explores better the search space by processing more particles in each iteration.

Performance Evaluation
Using the proposed fuzzy-based solution optimized through the PSO algorithm, introduced in the previous Sections, several experimental measurements have been conducted to verify it.Nonetheless, to compare the proposed solution with another similar work in the literature which aims to optimize the battery by varying the transmission power, in the performance evaluation, the approach of Castagnetti et al. [21] has been taken into account.However, it is necessary to highlight that, to the best of our knowledge, there are no papers in the literature in which the PSO is applied for the optimization of an FLC to choose the communication mode in Bluetooth 5, through the transmission power variation, which allows the best energy management.In the following subsection, the model that has been developed to validate the proposed approach, at first in Matlab and then exported to real hardware, is presented.

Experimental Model
The model that has been developed in Matlab/Simulink (8.7, MathWorks, Natick, MA, USA) is shown in Figure 7.This model has not been used for simulations but to implement all system components and, subsequently, to export them on real hardware for experimental evaluations.As shown in Figure 7, the behavior of the Mobile node is evaluated through the Simulink/Stateflow environment.This tool uses flow charts and finite state machines to represent the evolution of a system.The Mobile node component has three inputs, which are TX power, RSSI, and the connection mode (Conn_mode).The TX power value is received by the output of the Fuzzy Logic Controller.The Memory block is required to have a value initialized to 0 at the startup phase of the system.In the proposed model, the RSSI value is generated randomly.On the contrary, this value is obtained by the wireless link quality in the case of running the proposed model on real hardware.The Connection mode evaluation block is a Matlab function that by taking as input the value of the TX power received by the FLC returns an output that represents one of the connection modes supported by Bluetooth 5.As shown in Figure 7, the Mobile node block has two outputs.The distance represents the gap between the mobile node and the beacon, estimated taking into account the value that most often occurs in the RSSI, i.e., the "Mode", and the Measured Power, as mentioned above in Section 3.1.The Battery_level is the digital value of the battery capacity in the range [0 ÷ 1024].These outputs represent the inputs for the Fuzzy Logic Controller that returns TX power as output through the inference system.

Results
Several experimental measurements have been carried out both to validate the proposed solution and, mainly, to compare the different optimizations of the PSO by varying the particle number.As stated previously, the main aim of the PSO is to optimize the membership functions of the FLC modifying their range.To understand its operation, it is necessary, as a starting point, to consider the membership functions shown in Figure 4 that are statically established for the FLC proposed in this paper (Section 3.2).For instance, the result obtained in Matlab by the application of the PSO, using particles 50 and 20 iterations, is depicted in Figure 8.As it is possible to perceive, the range of the membership functions is quite different from that statically specified in Figure 4. Nonetheless, this optimization, in almost all cases, has significantly positive effects on the performance of the solution introduced in this paper.It has been chosen to show the membership functions range achieved with 50 particles and 20 iterations in PSO because they have allowed obtaining the best performance.Nevertheless, different tests have been carried out using 5, 10, 20, 40 and 50 particles in the PSO, with 20 iterations.At the end, an amount of particles greater than 50 has been not preferred because the improvements introduced were slight, i.e., few minutes/seconds regarding the increase of the battery life.
Numerous measurements have been made, in each of which the FLC has been modified considering the membership functions previously determined by the PSO in the offline phase through simulations in Matlab by varying the number of particles (5,10,20,40,50).In addition, three other cases have been taken into account, i.e., in the first considering the mobile board (node) without the FLC implemented in it, the second developing the FLC without the PSO and, finally, the third applying the approach of Castagnetti et al. [21].The mobile board has been equipped with a 3.7 V lithium-ion battery.Adopting this battery, its maximum level, when it is fully charged, is 200 mA, while the corresponding digital value, obtained through a 10-bit AD converter, is 1024.In the first scenario, the proposed solution has been tested in an indoor scenario, in the university labs.A basic plan of this scenario is depicted in Figure 9.One fixed board (i.e., the beacon) has been connected to a PC in room 6, while the other board has been moved further and further away to different rooms.The proposed fuzzy-based solution has been implemented in this mobile board that followed the path from room 1 to room 5, and vice versa, several times.During this route, the distance between the mobile board and the beacon has fluctuated between about 20 and 5 m.The duration of the measurements has been 5 h in each case.Table 4 clearly reveals that in general the proposed fuzzy-based solution achieves a real power consumption reduction and, as a consequence, it increases the device lifetime.Nevertheless, the best results have been reached by implementing the PSO with an amount of particles greater than 5.In fact, the best result has been attained by using the membership functions optimized through the PSO with 50 particles because 54% of the battery has been drained.The battery consumption has been 56% using 40 particles.As it is possible to note, there is only a small advance using more particles, which is further reduced if more than 50 particles are employed.On the contrary, there is a discernible difference in performance by using 20 or 10 particles because the battery has been 60% and 65%, respectively.It is helpful to note that, using five particles, the results are lower than using the FLC without PSO as the battery consumption has been 69% and 68%, respectively.Thus, in this case, the optimization has not been beneficial to prolong the battery life.This result can be explained because of the use of a low number of particles if, on the one hand, offers a faster computation, on the other hand, the optimal achieved does not always involve the best performance.In the case without FLC, the drained battery has been 75%, while using the approach proposed by Castagnetti et al. [21] the battery consumption has been 71%.It is clear that, in general, the performance of the proposed solution, even without PSO, is better than the one suggested by Castagnetti et al. and the case without FLC.The optimization through the PSO, for instance with 50 particles, has allowed for achieving the best results.However, it is necessary to highlight that in this scenario the LE Coded mode has never been used by the mobile device since the distance with the beacon has not been too high (Figure 9).In fact, it is useful to analyze the obtained values concerning the throughput, shown in Table 5, to confirm it.These results prove that Bluetooth 5 is faster than Bluetooth 4 in every case.Moreover, for closer distances, the speed of Bluetooth 5 is significantly faster than BLE 4.2:1215 Kbps vs. 672 Kbps for room 4, 980 Kbps vs. 641 Kbps for room 5 and 900 Kbps vs. 629 Kbps for room 3.In addition, it is clear that the throughput decreases as the distance increases.In fact, this issue happens for both BLE 4.2 and Bluetooth 5.As a consequence, considering that in this scenario the Long Range mode has not been used, as the range grows, the advantages of Bluetooth 5 diminish compared to BLE 4.2.It is necessary to note that the throughput for room 2 and room 3 are not the same, although they have both the same distance and the same number of walls.This strangeness can be explained because the amount of furniture and their disposition is different in the rooms.In addition, the walls can be constructed with a different material, in the case, for instance, of a supporting pillar.Thus, certainly, the signals to reach the room 2 have a more hindered path than those that reach room 3.In the second scenario, the proposed solution has been assessed in an outdoor situation, in the university campus.The plan of this scenario is shown in Figure 10.In this case, the distance between the mobile board and the beacon has fluttered between about 35 and 120 m.The duration of the measurements has been five hours in each case.In most of the tests, the two devices have been in the line of sight.The results depicted in Table 6 clearly reveal that even in this case the proposed fuzzy-PSO solution obtains a better energy management.The best result has been accomplished by using the membership functions optimized through the PSO with 50 particles.In fact, the consumed battery has been about 50%.This result is the best of all obtained in all the indoor and outdoor scenarios.Thanks to the solution proposed in this paper, the LE Coded mode of Bluetooth 5 has been capable of reaching a larger range without an excessive battery consumption.Using 40 particles, the difference is minimal because the battery consumption has been 51%.On the contrary, this consumption increases as the number of particles used decreases.In fact, with five particles, the consumed battery has been 69%.However, a tangible difference in the results is notable both for the approach of Castagnetti et al. [21] and without the FLC since the battery consumption has been 75% and 80%, respectively.It is clear that in this scenario the LE Coded (500 Kbps and 125 Kbps) mode has been used by the mobile device.When the mode 500 Kbps has been used, the average throughput has been 278 Kbps, while in the mode at 125 Kbps, the average throughput has been about 100 Kbps.From the results obtained in both scenarios, it is possible to conclude that Bluetooth 5 operates best when there are no obstacles.For instance, a throughput up to 1000 Kbps can be obtained, based on the distance.On the contrary, the performance decreases concretely when the signal encounters walls or metal materials.Nevertheless, with the Bluetooth 5 Long Range (Coded) mode, a connection of over 100 m can be achieved.The fuzzy-PSO solution introduced in this paper concretely enables to choose the most appropriate connection mode of Bluetooth 5, varying the TX power, to accomplish a better energy management that extends the battery life of the mobile devices.

Conclusions
In this work, a fuzzy-based approach to deal with the choice of the best communication mode in Bluetooth 5 that allows the achievement of an efficient energy management has been presented.The suggested solution grants the possibility to reach the optimal values and parameters of the proposed Fuzzy Logic Controller, i.e., optimizing the triangular membership functions, by varying their range, to obtain the best results concerning the battery consumption of mobile devices, by using a Particle Swarm Optimization algorithm.The triangular membership functions have been chosen because they represent a good trade-off between computation cost and efficiency.The paper offered a deep analysis for the configuration of the FLC assisted by the PSO to obtain the one that achieves the best performance.The paper also has provided extensive experimental assessments, performed through the Bluetooth 5 nRF52840 development boards from Nordic Semiconductors, regarding the battery consumption and the throughput.
The obtained results clearly reveal that, in general, the proposed fuzzy-PSO solution achieves a real power consumption reduction and, as a consequence, it increases the mobile device lifetime.Bluetooth 5 has kept the promise of higher throughput since rates up to 1200 Kbps are feasible when the devices are within range of few meters.Moreover, nearly the halfway point of the signal coverage, Bluetooth 5 is faster than BLE 4.2.On the contrary, the speed differences diminish significantly at the very edges of the range.In fact, using the 2 Mbps connection mode, the theoretical range of Bluetooth 5 is slighter than those of BLE 4.2.Nevertheless, Bluetooth 5 introduces the new Long Range (Coded) connection mode, at 500 Kbps and 125 Kbps, which allows reaching a greater range, but with a limited throughput.The support for the 2 Mbps and LE Coded connection modes are optional in Bluetooth 5 because of only the connection mode at 1 Mbps, inherited from Bluetooth 4, is mandatory.However, even if a Bluetooth 5 device only supports the 1 Mbps connection mode, it will still need to implement the new protocol features, such as the larger broadcasting capacity considering the increased packet size from 31 to 255 bytes.It is clear that the possibilities for the LE Coded mode are very attractive and there will certainly be lots of Internet of Things applications that will be based on this connection mode in the future.

Figure 1 .
Figure 1.Packet structure with Low Energy (LE) Coded mode.

Figure 3 .
Figure 3.An example of the correlation between the distance and the Received Signal Strength Indicator.

Figure 4 .
Figure 4. Triangular membership functions of input and output parameters for the FLC: (a) distance; (b) battery level; (c) transmission (TX) power.

Figure 5 .
Figure 5. Generic representation of triangular membership functions.

Figure 8 .
Figure 8. Triangular membership functions obtained by the application of the PSO using 50 particles and 20 iterations: (a) distance; (b) battery level; (c) TX power.

Figure 9 .
Figure 9. Plan of the indoor scenario.

Figure 10 .
Figure 10.Plan of the outdoor scenario.

Table 1 .
Comparison among Bluetooth versions.

Table 2 .
Bluetooth 5 communication modes-S is the symbol/bit rate.