###### Abstract  
The increasing proliferation of Internet of Things (IoT) devices has created a growing need for more efficient communication networks, especially in areas where continuous connectivity is unstable or unavailable. Opportunistic networks have emerged as a possible solution in such scenarios, allowing for intermittent and decentralized data sharing. This article presents a novel communication protocol that uses Bluetooth 5 and the libp2p framework to enable decentralized and opportunistic communications among IoT devices. The protocol provides dynamic peer discovery and decentralized management, resulting in a more flexible and robust IoT network infrastructure. The performance of the proposed architecture was evaluated through experiments in both controlled and industrial scenarios, with a particular emphasis on latency and on the impact of the presence of obstacles. The obtained results show that the protocol has the ability to improve data transfer in environments with limited connectivity, making it adequate for both urban and rural areas, as well as for challenging environments such as shipyards. Moreover, the presented findings conclude that the protocol works well in situations with minimal signal obstruction and short distances, like homes, where average latency values of about 8 s have been achieved with no losses. Furthermore, the protocol can also be used in industrial scenarios, even when metal obstacles increase signal attenuation, and over long distances, where average latency values of about 8.5 s have been obtained together with packet losses of less than 5%. opportunistic networks; opportunistic edge computing; OEC systems; opportunistic IoT; Bluetooth 5; decentralized IoT +
Footnote †: journal:  
00C0 Opportunistic networks are a useful alternative when continuous access, whether to the Internet or to a Local Area Network (LAN), is missing [6]. These networks allow for effective data sharing and routing even in the lack of constant connectivity. They also help to overcome some of the constraints associated with Cloud Computing, such as scalability, lack of security mechanisms for resource-limited devices, and excessive energy consumption [2]. To enhance Cloud Computing, technologies such as Edge Computing have emerged [7]. When combined with opportunistic networks, they allow for creating Opportunistic Edge Computing (OEC) systems, which provide Edge Computing services in an opportunistic way [8; 9]. Bluetooth stands out as one of the most used technologies in the field of IoT [10; 11]. For instance, Bluetooth Low Energy (BLE) has been developed as one of the most energy-efficient wireless communication technologies, with a high transmission-energy ratio [12]. BLE Mesh allows for completely decentralized operation [13], with advertising for node communications, making it ideal for opportunistic communications. Despite these characteristics, it has certain limitations [14; 15]:  
* It requires continuous activity to maintain the mesh network, which usually involves increasing power usage. * Messages have to go through numerous nodes before reaching their destination. * Network congestion may occur in environments with high node density. * The limited memory and processing resources of some nodes may lead to making it more difficult to manage the complexity of the network. * Large volumes of high-speed data cannot be sent without latency limitations. This article describes a communication protocol based on libp2p [16] and Bluetooth Mesh for two different home IoT and Industrial IoT (IIoT) scenarios. The developed protocol enables decentralized and opportunistic communication among nodes so that each node acts both as a client and a server, allowing for direct data exchange between them, as well as taking advantage of communication opportunities that arise in a dynamic and non-predefined way.