Architecture to Embed Software Agents in Resource ... - MDPI

0 downloads 0 Views 7MB Size Report
Dec 29, 2018 - basic hardware devices for the Internet of Things (IoT). ..... It will also have a database to store the different data transmitted in order to avoid a ...
sensors Article

Architecture to Embed Software Agents in Resource Constrained Internet of Things Devices Daniel H. De La Iglesia * , Gabriel Villarrubia González , André Sales Mendes, Diego M. Jiménez-Bravo and Alberto L. Barriuso Computer and Automation Department, University of Salamanca, Plaza de la Merced s/n, 37008 Salamanca, Spain; [email protected] (G.V.G.); [email protected] (A.S.M.); [email protected] (D.M.J.-B.); [email protected] (A.L.B.) * Correspondence: [email protected]; Tel.: +34-923-294-500 (ext. 6072) Received: 29 November 2018; Accepted: 24 December 2018; Published: 29 December 2018

 

Abstract: Sensing systems in combination with treatment tools and intelligent information management are the basis on which the cities and urban environments of the future will be built. Progress in the research and development of these new and intelligent scenarios is essential to achieve the objectives of efficiency, integration, sustainability, and quality of life for people who live in cities. To achieve these objectives, it is essential to investigate the development of cheaper, more accurate, and smarter hardware devices, which will form the basis of the intelligent environments of the future. This article focuses on an approach based on intelligent multi-agent systems that are integrated into basic hardware devices for the Internet of Things (IoT). A multi-agent architecture is proposed for the fast, efficient, and intelligent management of the generated data. A layer of services adapted to the needs of the new intelligent environments is built on this architecture. With the aim of validating this architecture, a case study based on electric vehicles of the e-bike type is proposed. Keywords: software agents; Internet of Things; WSN; smart devices

1. Introduction At present, citizens live in a global world where people and objects are increasingly interconnected, regardless of their geographical location. Buildings, cities, vehicles, Smartphones, and other devices are already equipped with digital sensors capable of recording large amounts of data [1]. Sensing systems represent a fundamental element in the actual information age. Thanks to these systems, it is now possible to measure certain values that previously could not be measured. These new data have been a revolution in the way in which users interact with the environment. To a large extent, this advance has been motivated by the price of sensors, which has been decreasing during the last ten years. Estimations indicate that sensor manufacturing and design processes will be reduced by approximately 5% per year in the next decade [2]. This prolonged drop price will mean significant savings when installing large-scale sensors in different environments, such as those needed to connect a large number of devices in an IoT (Internet of Things) environment [3]. The IoT concept is one of the most used in recent years to refer to all those connected devices that make up intelligent environments. One of the main problems that IoT environments face is the amount of data that their devices collect and with which, in many cases, nothing is done. These data are usually sent to central servers in the cloud, where they are analyzed to obtain derived information or activate certain events. For this reason, concepts such as Edge Computing [4] or Fog Computing [5,6] have emerged, which seek to change this passive behavior of the IoT nodes and turn devices into an active part of the system. By providing these devices with data analysis mechanisms, processing of the data

Sensors 2019, 19, 100; doi:10.3390/s19010100

www.mdpi.com/journal/sensors

Sensors 2019, 19, 100

2 of 25

closest to the place where they are created is achieved instead of being sent through long routes to reach external data centers. Bringing data processing to local environments makes even more sense if growth forecasts for the next few years are analyzed in the number of devices connected to the Internet that generate data. According to the report [7], it is expected that by the year 2020, the number of connected devices will surpass 50 billion, which will mean that for each citizen, there will be almost seven connected devices emitting data. Therefore, it is important that these data are processed in the devices themselves to avoid network saturation, unnecessary redundancy, and higher data storage costs. This local processing will improve the efficiency by not having to transmit all these data to the cloud, assuming significant cost savings and an increasement in processing speed. For certain sectors such as industry, health, transportation, telecommunications, or finance, among others, the real-time analysis of data is a fundamental need that is achieved with a faster processing of recorded data. One of the main problems currently existing is the lack of intelligence implemented on the deployed sensor devices. To a large extent, this lack is due to the limited computational resources (memory, computing capacity, and electrical consumption) of these devices. Even though the industry is getting closer and closer to developing lightweight, efficient devices with high capacities, the reality is that, at this moment, the majority of available sensors and actuators are limited computationally. In order to achieve a real revolution from the analog world to a digital world with intelligent environments, it is necessary to incorporate intelligence capabilities and mechanisms into existing devices on a day-to-day basis. By achieving this objective, intelligent and technologically and economically viable environments will be achieved. This paper proposes an integral IoT framework based on multi-agent systems for the intelligent management of computationally limited hardware devices that are the basis of the deployed sensor systems. The proposed system seeks, on the one hand, to provide IoT devices with intelligence in order to achieve decentralized, prior data processing with a greater efficiency. On the other hand, it seeks to provide a platform based on intelligent software agents able to efficiently manage all the information derived from the IoT systems on which to develop services and products that benefit citizens. The way in which this intelligence is achieved is through embedding a reactive agent in the hardware devices. This agent will be part of the MA (multi-agent) architecture as one more agent, regardless of its location, type, or characteristics. Thanks to this abstraction, the system will be able to execute artificial intelligence mechanisms on the data and processes generated by the agent embedded in the device. It is not therefore a simple input/output agent, and this agent (through its abstraction in the system) will take an active role in the management of data and processes carried out in the main system. The work carried out seeks to provide a solution to the problems posed by the authors in [8], where a series of needs and requirements are introduced when building intelligent IoT environments that are adapted to the changing circumstances. This article is structured as follows: Section 2 reviews the current state of the art work; Section 3 describes the proposed system in detail; Section 4 presents the case study which was conducted to validate the proposed architecture and the results obtained. Finally, conclusions drawn from the work are outlined in Section 5. 2. Background In the current technological framework, the development, management, and integration in real environments of IoT systems, such as Smart Homes or Smart Factories, represent a complex challenge for all the agents involved in its development and exploitation. That is the main reason why it is necessary to design and apply appropriate models, methodologies, technologies, and paradigms that help developers to address these new challenges. In this sense, different solutions, tools, and middleware methodologies have been developed that aim to address these problems. As the authors of [9,10] explain, it is possible to group solutions based on their design approaches, resulting in different

Sensors 2019, 19, 100

3 of 25

groups such as service-based architectures [11], event-based architectures [11], or architectures based on agents [12]. The latter are those based on software agents, which are addressed in this work. Specifically, an analysis of the current state of the art has been carried out on platforms responsible for providing intelligence to the computationally limited devices that make up the current IoT. For the authors of [13], the solution is to implement mobile agents on hardware devices. Specifically, this work is committed to work with hardware devices that can run TinyOS, an open source operating system specially designed for wireless sensor networks. This operating system is specially designed for a series of platforms (Telos, Mica2Dot, Mica2, Mica) so it is not possible to integrate it into other devices than those. In the case of [14], the authors also bet on the integration of mobile agents as a method to provide intelligence to the hardware nodes. The authors highlight the fact that their implementation, as suggested by the work of [13], can also be displayed on TinyOS or on a Java MV. Specifically, it can also be displayed on Sun SPOT devices, compatible with Java programming, but with a high price, so this has been discontinued. In contrast, in [15], the authors propose the integration of a mobile agent with the rest of the architecture through the implementation of a REST API. This API provides the creation and control of mobile agents, the migration of agents, the communication between devices and agents, and the local and remote access to available resources. It is therefore a new approach, where the exchange of data between the nodes and the rest of the platform through an API is the key to a functional system. In previous research [16], the authors made use of Self-StarMAS [17], a lightweight implementation based on the architecture of Malaca agents [18]. It is an architecture in which the agent is specially designed, taking into account the restrictions of the resources and capabilities of each device (for example, the communication protocol used). The different versions of Self-StarMAS can be run on Android devices, mobile phones with an MIDP profile (Mobile Information Device Profile), desktop computers, Sun SPOT sensors, and Libellium Waspmotes. The main characteristic of the internal architecture of a Self-StarMAS agent is that it is composed of a set of components that help to keep the specific functionalities of the application of the concrete communication protocols uncoupled. Therefore, through Self-StarMAS, it is possible to integrate new important devices, such as Android terminals or Waspmotes sensors. The concept of a software agent for the authors of [19] is used theoretically and no methodologies, implementations, or specific techniques are described. As previously commented, the work of the authors [20], despite being one of the most complete available in the literature, does not delve into the methods or designs employed to embed software agents. As a conclusion and after having analyzed the most relevant works of recent years in the field of study of this work, it is possible to identify some notable shortcomings. In recent years, there have been numerous works that address the main issues of the management of IoT environments through multi-agent systems and software agents embedded in limited hardware devices. It has not been possible to find works that delve into mechanisms and design concrete solutions to carry out these developments. It is also possible to identify a lack of specific implementations and developments, deepening and detailing the code and programming languages used. Another aspect that stands out is the lack of concrete security and confidence mechanisms of the MAS systems proposed and described by the authors of the different works analyzed. Having considered the points above, this work seeks to provide a concrete solution, and proposes a concrete and well-defined software agent model to embed software agents in computationally limited devices, as well as security and trust mechanisms appropriate to the needs raised in current IoT environments. 3. Proposed System As discussed in the previous section, this work seeks to provide solutions to the challenges posed by the authors of [8] when addressing the design of dynamic IoT environments through the

2018, 19, 18, 100 x FOR PEER REVIEW Sensors 2019,

44 of of 25

such as a processor, a communication system, and sensors or actuators to take control of the incorporation of software and agents on computationally wireless devices. In the work environment, measuring acting on it [21]. On thelimited other hand, thehardware concept of SE is defined as a of the authors, two fundamental concepts are introduced when modeling IoT environments: Smart cyber-physical environment where different heterogeneous devices are used, capable of collecting Objects (SOs) Smart Environments (SEs). So-called SOs are the fundamental components of IoT data from the and environment and interacting with the environment [22,23]. environments and refer to all those everyday objects that are equipped withan hardware The main requirements posed by the authors of [8] and to which answercomponents is proposedsuch are as a processor, a communication system, and sensors or actuators to take control of the environment, detailed in Table 1. measuring and acting on it [21]. On the other hand, the concept of SE is defined as a cyber-physical environment where different heterogeneous devices are used, capable of collecting Table 1. Main requirements of intelligent environments and smart objects. data from the environment and interacting with the environment [22,23]. Domain TheRequirement main requirements posed by the authors of [8] and to which an answer is proposed are detailed in Table 1. Req. 1 (SE) Abstraction over heterogeneous input and output hardware devices Req. 2 (SE) Table 1. Main Abstraction over hardware and software interfaces requirements of intelligent environments and smart objects. Abstraction over data streams (continuous or discrete data or Req. 3 (SE) Requirement Domain events) and data types 4 (SE) Abstraction over physicality context) Req.Req. 1 (SE) Abstraction over heterogeneous input(location, and output hardware devices Req. 2 (SE) Req. 5 (SE) Req. 3 (SE) Req.Req. 4 (SE) 6 (SO) Req. 5 (SE) 7 (SO) Req.Req. 6 (SO) Req.Req. 7 (SO) 8 (SO) Req. 8 (SO) Req.Req. 9 (SO) 9 (SO)

Abstraction over hardware and software interfaces Abstraction over the development process Abstraction over data streams (continuous or discrete data or events) and data types Abstraction over physicality (location, context) Heterogeneity and Application Development Abstraction over the development process Augmentation VariationDevelopment of Smart Objects Heterogeneity and Application Augmentation Variation of Smart Objects Management of Smart Object Management of Smart Object Evolution of Smart Evolution of Object Smart Systems Object Systems

3.1. Limited Hardware Hardware Devices 3.1. Limited Devices for for the the IoT IoT In In the the IoT, IoT, light light hardware hardware devices devices that that can can be be integrated integrated into into aa multitude multitude of of ‘things’ 'things' and and which which form the basis of the cyber-physical systems involved in the Internet of Things, play a fundamental form the basis of the cyber-physical systems involved in the Internet of Things, play a fundamental role. It is is necessary, necessary, therefore, role. It therefore, to to define define what what is is meant meant by by computationally computationally limited limited devices devices or or limited limited resource devices. resource devices. In general terms, devices may limited by their size, size, by by their their data data storage, storage, by by their their energy energy In general terms, these these devices may be be limited by their source, their computing computing capacity, capacity, or capacity. Therefore, carried source, by by their or by by their their communication communication capacity. Therefore, the the tasks tasks carried out by these devices are usually highly optimized. The main elements (software and hardware) present out by these devices are usually highly optimized. The main elements (software and hardware) in an IoTindevice described in Figurein1.Figure 1. present an IoTare device are described

Figure 1. Basic architecture of an IoT device.

Currently, there are are different different hardware hardware devices on the market with reduced prices that can be incorporated into aa large large number numberof of'things' ‘things’and andthat thatcan canexpand expand horizons IoT, well incorporated into thethe horizons of of thethe IoT, as as well as as help students and educators to enter the world of cyberphysical systems. There are numerous help students and educators to enter the world of cyberphysical systems. There developments, kits, and and boards boards from from different but there there are are two developments, kits, different manufacturers, manufacturers, but two that that stand stand out out from from the rest of them at present: ESP8266 and ESP32. This is the case for ESP8266 modules from the Espressif company, company,which whichhave haveaa complete completeTCP/IP TCP/IP stack together with a microcontroller, which allows them to connect to WiFi networks in a simple way, as well as incorporate external sensors and actuators, all with a very low cost of just one euro.

Sensors 2019, 19, 100

5 of 25

Sensors 2018, 18, x FOR PEER REVIEW

5 of 25

way, as well as incorporate external sensors and actuators, all with a very low cost of just one euro. The module isistherefore thereforea amore morecomplete complete solution projects. Arduino devices are The ESP8266 module solution forfor IoTIoT projects. Arduino devices are used used for simple IoT projects or prototypes, the inclusion of these boards is performed with for simple IoT projects or prototypes, wherewhere the inclusion of these boards is performed with an ad an hoc topology. On contrary, the contrary, theircharacteristics, characteristics,ESP8266 ESP8266modules modules can can be easily hocadtopology. On the andand duedue to to their easily integrated integrated into into new new industrial industrial developments, developments, based on IoT. IoT. Therefore, Therefore, many many of of the the devices devices that that are are currently currentlymarketed marketedon onthe theIoT IoTmarket markethave havethis thismodule moduleincorporated. incorporated. In In addition addition to to using using the the C C and and C++ C++ languages, the ESP8266 module can be programmed in Lua Lua or or JavaScript, JavaScript, while while the the Arduino Arduino board board can can only only be be programmed programmed in in the the CClanguage. language. Thanks Thanks to to the the success success of of this this module, module, aa series series of of devices devices have have emerged emerged in in recent recent months. months. The The prototyping prototyping and and development development of of IoT IoT projects projects based based on on the the ESP8266 ESP8266has has resulted resultedin in the the NodeMCU NodeMCU or or WeMos. WeMos.The The ESP32 ESP32 module moduleis is the the evolution evolution of of ESP8266 ESP8266 and and is is more more focused focusedon on the the evolution evolution of of the the IoT. IoT.The The ESP32 ESP32 is is aa much much more more powerful powerful device, device, and anduses uses an an Xtensa Xtensa dual-core dual-core processor processor LX6 LX6 32-bit 32-bit160 160or or240 240MHz. MHz. ItIt has has two two processing processing cores, cores, which which allows allows one one of of them them to to be be dedicated dedicated to to communication communication and and the the other other to to the the remaining remaining processes, processes, which which is is an an advance to to thethe ESP8266 module. The main disadvantage of this of module is its costisincrease advancewith withrespect respect ESP8266 module. The main disadvantage this module its cost (around euros) with respect to ESP8266. operation ESP8266 of andESP8266 ESP32 isand very similar, and increase 6(around 6 euros) with respect toThe ESP8266. Theofoperation ESP32 is very they are two devices that can be programmed the USB-to-TTL similar, and microcontroller they are two microcontroller devices that can beusing programmed using communication the USB-to-TTL interface. There are severalThere waysare to program these tothese makedevices them work in IoT environments. communication interface. several ways todevices program to make them work in IoT The most practical and simple method is to program them through the Arduino IDE. These boards environments. The most practical and simple method is to program them through the Arduino IDE. have series ofhave GPIO (General Purpose Input/Output) pins that can be used as can databeentry exit Thesea boards a series of GPIO (General Purpose Input/Output) pins that usedand as data lines. this way, andIncounting these entry lines, these devices analyzing the of the entry In and exit lines. this way,on and counting on these entry lines,work theseby devices work bydata analyzing environment and reacting to and them. the data of the environment reacting to them. As As itit has has been been proven, proven, both both the the ESP8266 ESP8266 and and ESP32 ESP32 boards boards are are very very focused focused on on the the development development of IoT systems, are widely used, and have become an industry standard. Therefore, this of IoT systems, are widely used, and have become an industry standard. Therefore, this work work will will focus focus on on the the development developmentof ofthese theseIoT IoTdevices. devices. 3.2. 3.2. Agent Agent and and Multi-Agent Multi-Agent Concept Concept Smart Smart software software agents agents are are aa series series of of entities entities that that seek seek to to emulate emulate human human reasoning reasoning processes processes or or behaviors. It is possible to find agents focused on helping users, performing certain tasks, performing behaviors. It is possible to find agents focused on helping users, performing certain tasks, performing supervisory supervisory and and security security tasks, tasks, or or filtering filtering information, information, among among others. others. Based Based on on these these definitions, definitions, Figure 2 shows the basic diagram of the relationship between an agent and the environment Figure 2 shows the basic diagram of the relationship between an agent and the environment in in which which itit is deployed. It is possible to observe how the agent perceives its environment through a series is deployed. It is possible to observe how the agent perceives its environment through a series of of sensors sensors and and subsequently subsequentlyintervenes intervenesin inititthrough througheffectors. effectors.

Figure 2. Agent model. Figure 2. Agent model.

It is necessary to highlight the difference between a multi-agent system and an agent-based system. It is necessary to highlight the difference between a multi-agent system and an agent-based The systems based on agents are those systems that work with the concept of agent as an abstraction system. The systems based on agents are those systems that work with the concept of agent as an mechanism when modeling a system, but when implementing it, this can be done through traditional abstraction mechanism when modeling a system, but when implementing it, this can be done through software structures. In contrast, a multi-agent system is designed with the clear idea that it will be traditional software structures. In contrast, a multi-agent system is designed with the clear idea that composed of several agents that interact with each other in order to achieve a desired functionality [24]. it will be composed of several agents that interact with each other in order to achieve a desired When a problem exceeds the capabilities of an individual agent, several agents can be integrated functionality [24]. into an MAS (Multi-Agent System) that provides a framework for agents to communicate and cooperate When a problem exceeds the capabilities of an individual agent, several agents can be integrated in solving problems [25]. An MAS is characterized as a system where each agent has incomplete into an MAS (Multi-Agent System) that provides a framework for agents to communicate and cooperate in solving problems [25]. An MAS is characterized as a system where each agent has incomplete information or capabilities to solve a given problem, it has no global control, it has decentralized data, and its tasks are executed asynchronously. Each individual agent, within an MAS,

Sensors 2019, 19, 100

6 of 25

information or capabilities to solve a given problem, it has no global control, it has decentralized data, and its tasks are executed asynchronously. Each individual agent, within an MAS, has its own objectives and knowledge, so coordination is required to combine these contributions and solve the problem addressed [26]. An MAS is generally considered a robust system since the failure of a single agent does not endanger the operation of the entire system. The agents in an MAS are able to learn and plan actions in a cooperative way. 3.3. Architecture Overview When dealing with the integration of software agents on wireless devices, it is necessary to establish a clear differentiation between the types of connection available on these devices. A valid classification is that offered by the authors of [27] and defined as ‘classification based on their network stacks’. In this classification, the level of integration between the Internet and wireless devices depends on the protocols and network interfaces they implement. A device can be completely independent from the Internet (Front-End), be able to exchange information through an intermediate host (Gateway), or use a complete network protocol such as TCP/IP. For this work, the devices framed in the first type (without possible connection to the Internet) are not taken into account. Only devices that have an Internet connection, either direct or indirect, will be relevant in an IoT system. In this work, devices capable of connecting to the Internet directly through TCP/IP protocols are considered as type A devices and those devices that need a Gateway to exchange information through the Internet are type B devices. Therefore, type A devices have a network interface capable of implementing a TCP/IP protocol (typically through an 802.11 WiFi protocol) that allows them to be directly connected to the Internet. Thanks to this connection, it is possible to send and receive data from an external distributed platform. It is therefore understood that these devices are fully integrated in the IoT. On the other hand, type B wireless devices do not have a direct connection to the Internet and need a hardware device that acts as a gateway between them and the network. In this type of device, it is possible to find those wireless sensors that have a connection of the type Bluetooth, Ant +, or Radio Frequency to transmit data. A clear example of Gateway for this type of device is a Smartphone that communicates through one of these wireless protocols to the sensor and transmits this data to the Internet through a WiFi network or a mobile data network. Depending on the types of wireless devices that exist in the context of the case study in which the system will be deployed, it will be necessary to adopt one solution or another. Next, the two main solutions proposed in this work are detailed.





For type A wireless devices: The design of a communication middleware capable of connecting the computationally limited device with the multi-agent IoT system through an agent embedded in the device itself is proposed. For this purpose, a communication channel will first be available through a message exchange protocol in which the device will send and receive the middleware information. Once the data has been obtained, the middleware will normalize the information and send it to the reactive agent based on rules in charge of representing the external device within the agent organization. This agent will communicate within the organization with the other agents, who will be responsible for managing the information obtained. For wireless devices type B: Not having a direct communication channel with the Internet, it will be necessary to introduce a Gateway device. For the system proposed in this paper, the aim is to develop a software agent embedded in an Android Smartphone device that acts as a gateway between these devices and the IoT multi-agent system. This agent embedded in the Smartphone will be responsible for collecting information from external devices and then transmitting the information to the rest of the agents within the MAS organization.

The core part of the proposed architecture, as can be seen in Figure 3, is the multi-agent IoT system. This system is based on a semi-closed organization capable of including new external agents in a controlled manner, guaranteeing stability, confidence, flexibility, and openness. Agents embedded

Sensors 2019, 19, 100

7 of 25

in the devices are presented in the organization through an agent that acts as their representative. Within this reactive Sensors 2018, 18,system, x FOR PEER REVIEWand deliberative agents will coexist as what is defined as a hybrid 7 of 25 system. The chosen methodology for the definition of the steps of analysis and system design will will be Gaia in combination with modelinglanguage languageAUML AUML(Agent (AgentUML). UML). A A series of roles be Gaia [28],[28], in combination with thethe modeling roles and and services services appropriate appropriate to to the the needs needs of of the the designed designed organization organization are are defined. defined. The The communication communication between between the the different different agents agents will will be be carried carried out out directly directly through through the the use use of of the the standard standard protocol protocol FIPA-ACL FIPA-ACL (Agent (Agent Communication Communication Language) Language) [29,30]. This This protocol protocol allows allows the the development development of of interoperable communication structures, which agents can run on different platforms with the interoperable communication structures, which agents can run on different platforms with the objective objective of exchanging information. of exchanging information.

Figure Figure 3. 3. General Generaldiagram diagramof ofthe theproposed proposed system. system.

The architecture of security withwith the aim providing a greater degree of stability The architecture will willhave havea layer a layer of security the of aim of providing a greater degree of and confidence. This system ensure onlythat agents a valid cantoken join the stability and confidence. This will system willthat ensure onlywith agents withtoken a valid canplatform, join the thus allowing creation a semi-closed organization that provides the degree ofdegree stability trust platform, thus the allowing theof creation of a semi-closed organization that provides the ofand stability sought. The JADE Framework be used aswill the be basis for the [31]. and trust sought. The JADE will Framework used as development the basis forand theimplementation development and The agents in JADE as JADE a set of Java classes agent properties, different implementation [31]. are Thedefined agents in are defined as that a setencapsulate of Java classes that encapsulate agent agent behaviors, interactions, states, interactions, and data. The interactions theinteractions agents are of carried out with properties, different agent behaviors, states, and data.ofThe the agents are the FIPA-ACL protocols, but the use of other also protocols possible. One of possible. the most carried out withinteraction the FIPA-ACL interaction protocols, but protocols the use ofisother is also important is that itfeatures allows integration through the Internet by supplying a series of services One of the features most important is that it allows integration through the Internet by supplying a that let the services provided by agents be invoked, through web services. series of services that let the services provided by agents be invoked, through web services. The following following three three sub-sections sub-sections will will detail detail the the three three main main elements elements that that make make up up the the system system The proposed in in this this paper, paper, shown in Figure 3. proposed 3.4. Middleware Middleware for for Type Type A A Devices Devices 3.4. As detailed detailed in in the the previous previous section, section, these these types types of of devices devices have have aa network network layer layer capable capable of of As implementing the TCP/IP protocol for direct communication between the wireless device and the implementing the TCP/IP protocol for direct communication between the wireless device and the Internet. With Withthe theaim aim of of embedding embedding software softwareagents agentson on these these devices, devices, itit isis necessary necessary to to design design aa Internet. strategy through which the embedded agent can run independently of the underlying hardware. strategy through which the embedded agent can run independently of the underlying hardware. For For this, the strategy of the ‘representative agent’ is used in semi-closed artificial societies, where this, the strategy of the 'representative agent' [32][32] is used in semi-closed artificial societies, where a a software agent that is inside MAS acts representative device. This agent software agent that is inside thethe MAS acts as as thethe representative of of thethe device. This agent willwill be be in charge of communicating with the hardware device through a message queue Publish/Subscribe (Pub/Sub). Thanks to this abstraction, the rest of the agents of the organization will interact with the representative agent as if it was the hardware device.

Sensors 2019, 19, 100

8 of 25

in charge of communicating with the hardware device through a message queue Publish/Subscribe Sensors 2018, 18, x FOR PEER REVIEW 8 of 25 (Pub/Sub). Thanks to this abstraction, the rest of the agents of the organization will interact with the representative agent as if it was the hardware device. More specifically, MQTT (Message Queue Telemetry Transport) [33] has been selected as a More specifically, MQTT (Message Queue Telemetry Transport) [33] has been selected as a Pub/Sub message transport protocol. It is an extremely light protocol and designed for IoT Pub/Sub message transport protocol. It is an extremely light protocol and designed for IoT communications, capable of establishing encrypted communications, which gives the network an communications, capable of establishing encrypted communications, which gives the network an extra extra layer of security. The main elements present in the MQTT protocol are the following: layer of security. The main elements present in the MQTT protocol are the following: • Client: This is the device responsible for posting messages, subscribing to receive messages, • Client: or both;This is the device responsible for posting messages, subscribing to receive messages, or both; It is the server in charge of receiving the messages published by the clients and then • Broker: • Broker: is the of receiving the messages published by the clients and then sending It them to server the restinofcharge the subscribers; sending them to the rest of the subscribers; • Publish: When a client sends a message to the broker; Publish: When a client a message the broker; •• Topic: Messages must sends be tagged with atotopic. Clients subscribe to a specific topic, and in this • Topic: Messages must be tagged with published a topic. Clients subscribe way, they only receive the messages on that topic. to a specific topic, and in this way, they only receive the messages published on that topic. Next, the stages of configuration and operation of the middleware for the type A devices are detailed. Next, the stages of configuration and operation of the middleware for the type A devices are detailed. 3.4.1. Pre-Configuration of the Devices 3.4.1. Pre-Configuration of the Devices Before being incorporated into the IoT system, the devices must complete a minimum Before being into the with IoT system, devices must minimum configuration to beincorporated able to communicate the rest the of the devices andcomplete with the aserver. It is configuration to be able to communicate with the rest of the devices and with the server. It is necessary necessary to configure the IP address of the main server on which the devices will have to operate. to configure the IP address of the server whichtheir the devices willprotocol have to operate. Afteras this After this initial configuration, themain devices willon execute connection to the server, is initial configuration, thechapter. devices will protocolstep to the as is indicated indicated later in this Thisexecute is the their first connection and fundamental in server, the configuration of later in this chapter. This is the first and fundamental step in the configuration of the devices. the devices. 3.4.2. Registration of of the the Device Device in in the 3.4.2. Registration the System System Once the IP IP address address of of the the server server is is configured, configured, the the device device is is registered registered in in the the system. system. To To do do this, this, Once the the must make make aa GET GET request by the the API-REST API-REST deployed the device device must request on on one one of of the the endpoints endpoints exposed exposed by deployed in in the system. As shown in Figure 4, the device sends its MAC address, which will be used as an element the system. As shown in Figure 4, the device sends its MAC address, which will be used as an element of server registers thethe device in of univocal univocal identification identificationof ofthe thedevice. device.After Afterprocessing processingthe therequest, request,the the server registers device the database and assigns a topic ininthe in the database and assigns a topic theserver’s server'sMQTT MQTTbroker. broker.This Thistopic topicwill will be be the the communication communication channel through which the messages will be exchanged between the server and the device and willwill be channel through which the messages will be exchanged between the server and the device and governed by the representative agent of the MAS designed. be governed by the representative agent of the MAS designed.

Figure 4. Sequence of registration of a device in the system.

The topic assigned to the device is generated by the server in a random and univocal way, with the aim of adding a higher level of security to the system. The communications through MQTT are encrypted through SSL/TLS, which provides another degree of security, avoiding the injection of packets or malicious data into the system. Thanks to the power of current devices such as ESP8266 or

Sensors 2019, 19, 100

9 of 25

The topic assigned to the device is generated by the server in a random and univocal way, with the aim of adding a higher level of security to the system. The communications through MQTT are encrypted through SSL/TLS, which provides another degree of security, avoiding the injection of packets or malicious data into the system. Thanks to the power of current devices such as ESP8266 or ESP32, it is possible to apply this layer of security where, before, due to the computational cost, it was impossible. 3.4.3. Notification of Device Services After having registered in the system and having obtained the communication topic with the MQTT broker, the device notifies the system of the services and the resources available to it. This notification is made through an MQTT message where these services are registered so the server has a record of the available services and can then make requests. The services and resources available from the device will depend on the environment and the elements deployed in each of the IoT scenarios where the system is implemented. Therefore, these services are well-known by both the servers and the devices before the system is started. A simple example is the device responsible for measuring the temperature and humidity in a room. Table 2 shows a list of services that would implement these devices. Table 2. Example of services available in a device responsible for measuring the temperature and humidity of a room. Service Name

Input/Output of Data

Description

sendTemperature sendHumidity setUnitsTemp

Data output Data output Data input

setSampling

Data input

Service used by the device for sending temperature data Service responsible for sending moisture recorded by the sensor Service responsible for configuring the units of measurement of temperature (Centigrade or Fahrenheit) Service responsible for configuring the sampling rate with which sensor readings are collected

3.5. Gateway for Type B Devices Type B devices, as already mentioned, are those that do not have a direct communication channel with the Internet through which to transmit the measured data. These devices are very numerous in current IoT environments, from heart rate monitors, cadence sensors, and temperature sensors to RFID identification cards. For the system proposed in this work, a mobile agent is implemented in an Android Smartphone device that will act as a gateway between these devices and the distributed multi-agent system. Currently, Smartphone devices have different communication protocols of a short and medium range, such as Bluetooth, NFC, Ant+, or WIFI. Thanks to these protocols, the devices are able to connect with a large number of type B devices, extending the range of action of the IoT. Smartphones are becoming more common among citizens and are often already fundamental elements for people who live or work in cities. Therefore, these smart devices have become the best candidates to act as a gateway between type B devices and the Internet. Specifically, thanks to the fact that the JADE platform allows the integration of mobile agents, a mobile agent will be deployed in an Android device, which will be in charge of receiving information from the devices, and will be communicated in the agent with the role of a Mobile Agent of the main IoT multi-agent organization. As detailed in the previous section, mobile agents can perform migration actions when circumstances require it. The following are the three main states in which the mobile agent Gateway of the proposed system will be found. 3.5.1. Mobile Agent as Gateway For cases in which the mobile agent does not require a process migration, this agent will act as a link between the wireless devices of type B, and the main architecture. As shown in Figure 5, it will be

Sensors Sensors 2018, 2018, 18, 18, xx FOR FOR PEER PEER REVIEW REVIEW

10 10 of of 25 25

3.5.1. Mobile Sensors 2019, 19, 100 Agent 3.5.1. Mobile Agent as as Gateway Gateway

10 of 25

For For cases cases in in which which the the mobile mobile agent agent does does not not require require aa process process migration, migration, this this agent agent will will act act as as aa link between the wireless devices of type B, and the main architecture. As shown in Figure 5, it will link between the wireless devices of type B, and the main architecture. As shown in Figure 5, it will responsible for reading the values of the different sensors through the specific protocol that each one be be responsible responsible for for reading reading the the values values of of the the different different sensors sensors through through the the specific specific protocol protocol that that each each implements and, subsequently, it will encode the information with the FIPA-ACL standard to send one one implements implements and, and, subsequently, subsequently, it it will will encode encode the the information information with with the the FIPA-ACL FIPA-ACL standard standard to to the data to the architecture. In the same way, the data that arrives from thethe organization will be sent send send the the data data to to the the architecture. architecture. In In the the same same way, way, the the data data that that arrives arrives from from the organization organization will will be be through FIPA-ACL messages, and this agent will be inbecharge of communicating with the devices and sent sent through through FIPA-ACL FIPA-ACL messages, messages, and and this this agent agent will will be in in charge charge of of communicating communicating with with the the devices devices transmitting the information. It will also have a database to store the different data transmitted and and transmitting transmitting the the information. information. It It will will also also have have aa database database to to store store the the different different data data transmitted transmitted in order avoid a lossaaof information duedue to ato of of signal. in order to loss of aa loss in to order to avoid avoid loss of information information due toloss loss of signal. signal.

Figure Communication between IoT architecture. Figure 5. Communicationbetween between the mobile agent and IoT architecture. Figure 5. 5. Communication the mobile mobileagent agentand and IoT architecture.

3.5.2. Mobile Agent Cloning 3.5.2. Mobile Agent Cloning 3.5.2. Mobile Agent Cloning In in the determines the agent be as in In cases cases in which which the system system determines that the mobile mobile agent must be cloned, cloned, as shown shown in 6, In cases in which the system determines thatthat the mobile agent mustmust be cloned, as shown in Figure Figure 6, an exact copy of the agent's code and status will be made in the main multi-agent system. Figure 6, an exact copy of the agent's code and status will be made in the main multi-agent system. an exact copy of the agent’s code and status will be made in the main multi-agent system. This cloning This cloning be motivated by an in Smartphone, aa lack of cloning may may be error motivated an error error in the the user's user's lackresources of computational computational mayThis be motivated by an in the by user’s Smartphone, a lackSmartphone, of computational (memory or resources (memory or processing), or aa low battery level. When the agent is cloned, communication resources (memory or processing), or low battery level. When the agent is cloned, communication processing), or a low battery level. When the agent is cloned, communication with the wireless devices with with the the wireless wireless devices devices is is not not lost lost as as long long as as the the original original agent agent does does not not cease cease to to be be operative operative on on the the is not lost as long asmain the original agent does not cease toofbe operative on the Smartphone. The main Smartphone. Smartphone. The The main objective objective is is to to keep keep an an exact exact copy copy of the the resources, resources, code, code, and and states states of of the the agent agent objective is to keep an exact copy of the resources, in code, Smartphone and states of the agent that can serve as a that that can can serve serve as as aa backup backup once once the the mobile mobile agent agent in the the Smartphone device device has has all all the the necessary necessary backup once the mobile agent in the Smartphone device has all the necessary resources. resources. resources.

Figure 6. Mobile Figure agentcloning. cloning. Figure6. 6. Mobile Mobile agent agent cloning.

3.5.3. Migration of of Mobile Agent 3.5.3. Migration Agent 3.5.3. Migration of Mobile Mobile Agent cases in the original mobile agent any reason, including those For For cases in which the original ceasesto tobe beactive activefor for any reason, including those For cases in which which the originalmobile mobile agent agent ceases ceases to be active for any reason, including those indicated in previous section, and access the wireless also interrupted, the mobile indicated in the previous section, wirelessdevices devicesis also interrupted, mobile indicated in the the previous section,and andaccess access to to the wireless devices is is also interrupted, the the mobile agent perform complete main architecture, as in In agent will perform complete migration migration to totothe the main architecture, as is is shown shown in Figure Figure 7. In this this7.way, way, agent willwill perform a aacomplete migration the main architecture, as is shown in 7. Figure In this despite not having communication with the devices, the active data and processes will not be lost despite not having communication with the devices, the active data and processes will not be lost way, despite not having communication with the devices, the active data and processes will not be their execution. Once the mobile agent is migration to and may continue their execution. Once the original original mobile agent agent is recovered, recovered, migration to the the to lost and andmay maycontinue continue their execution. Once the original mobile is recovered, migration Smartphone will again occur to continue the normal execution of the agent. This mechanism provides Smartphone will again occur to continue the normal execution of the agent. Thisagent. mechanism the Smartphone will again occur to continue the normal execution of the This provides mechanism aa high of to in system. If integrity of original mobile agent higha level level of tolerance tolerance to failures failures in the thein system. If the the If integrity of the the of original mobilemobile agent is is provides high level of tolerance to failures the system. the integrity the original agent compromised, the necessary mechanisms are activated to avoid the total or partial loss of the compromised, the necessary mechanisms are activated to avoid the total or partial loss of the code code is compromised, the necessary mechanisms are activated to avoid the total or partial loss of the code and and data data of of the the agent agent and and are are thus thus able able to to resume resume the the immediate immediate execution execution if if it it affects affects the the processing processing and of data of the agent and are thus able to resume the immediate execution if it affects the processing of the the system. system. of the system.

Sensors 2019, 19, 100

11 of 25

Sensors 2018, 18, x FOR PEER REVIEW

11 of 25

Figure7.7.Migration Migration of Figure of mobile mobileagent. agent.

3.6. 3.6. Multi-Agent Architecture forforIoT Multi-Agent Architecture IoT ThisThis section details the ofthe themulti-agent multi-agent architecture section details thestructure structureand and functionality functionality of architecture thatthat willwill be be the core of the proposal madeininthis thiswork. work. As in in previous sections, the the the core partpart of the proposal made As already alreadymentioned mentioned previous sections, architecture is especially focusedon onproviding providing services services to thethe management of the architecture is especially focused tothe theIoT IoTthrough through management of the computationally limited devicesthat thatcomprise comprise it. it. computationally limited devices Description Architecture 3.6.1.3.6.1. Description of of thethe Architecture When defining multi-agent architecturepresented presentedin inthis this paper, paper, it it is is necessary necessary to When defining thethe multi-agent architecture to define defineaa set set of fundamental characteristics and properties. The authors in [34] present a series of characteristics of fundamental characteristics and properties. The authors in [34] present a series of characteristics that a society of intelligent agents must have:

that a society of intelligent agents must have:

• • • • •

• A set of agents; A set of agents; • A set of restrictions within society; restrictions within society; •A set A of communication language; •A communication A series of roles language; that agents must play; •A series A set of of roles owners or agents coordinators the agents. that must for play;

A set coordinators for the agents. In of theowners case ofor the last of the characteristics described, the owner or coordinator of the agents

refers the person or organization that has thedescribed, power to decide which can enter what In thetocase of the last of the characteristics the owner oragents coordinator of society, the agents refers roles they should have, what communication language they should have, and the set of restrictions to the person or organization that has the power to decide which agents can enter society, what roles they will have within society [35]. However, not all companies have an owner in charge of making they should have, what communication language they should have, and the set of restrictions they these decisions and it will vary depending on the design and purpose of the organization. Depending will have within society [35]. However, not all companies have an owner in charge of making these on its purpose, an artificial society of agents needs to apply the following basic characteristics:

decisions and it will vary depending on the design and purpose of the organization. Depending on its • Opening: It is society necessary newneeds agentstohave thethe possibility of joining society; purpose, an artificial of that agents apply following basic characteristics:

• • • •

• Flexibility: That refers to the degree of freedom to move that agents have within society; It is necessary that new agents have the possibility of joining society; •Opening: Stability: Agents need to anticipate the consequences of their actions; ThatItrefers freedom to move that have within •Flexibility: Confidence: referstotothe thedegree level ofoftrust that the owners or agents coordinators have insociety; the actions carried out by their agents. Stability: Agents need to anticipate the consequences of their actions;

Confidence: refers to the level ofworks trust such that the owners or coordinators have in carried Based on It these characteristics, as [36,37] perform a classification of the the actions basic types out by their agents. of agent societies: open societies and closed societies.

Within the societies of open agents, it is possible to incorporate one or more agents from the Based on these characteristics, works such as [36,37] perform a classification of the basic types of outside into society without any restriction. An agent can join the agent society simply by beginning agent societies: open societies and closed societies. to interact with the other existing agents. With respect to the four basic characteristics mentioned Withinanthe societies of open is possible incorporate agents from above, open agent society hasagents, a greatitopenness andto great flexibility,one but or it ismore highly difficult to the outside into society without any restriction. An agent can join the agent society simply by beginning to ensure that an open society has adequate stability and trust. interact with the other existing agents. With to thetofour basic characteristics mentioned above, On the contrary, in a closed society, it isrespect not possible incorporate new external agents into the an open agent society has a great openness and great flexibility, but it is highly difficult to ensure organization. The agents are previously programmed by the system designer and therefore it is that known at all times what agents there and are, how an open society has adequate stability trust.they interact with each other, and what roles they can play. According to the basic characteristics explained before, this type of company provides greatinto On the contrary, in four a closed society, it is not possible to incorporate new external agents stability and trust, lacksare an previously acceptable openness and flexibility. The majority of the the organization. Thebut agents programmed by the system designer andmulti-agent therefore it is systems at present systems builtthey on the basis of closed societies. known at alldeveloped times what agents are there are, how interact with each other, and what roles they can

play. According to the four basic characteristics explained before, this type of company provides great stability and trust, but lacks an acceptable openness and flexibility. The majority of the multi-agent systems developed at present are systems built on the basis of closed societies.

Sensors 2019, 19, 100

12 of 25

Sensors 2018, 18, x FOR PEER REVIEW Sensors 2018, 18, x FOR PEER REVIEW

12 of 25

of 25 Due to this lack of alternatives when designing agent organizations, the authors of [32]12propose to this of alternatives whennew designing organizations, theaim authors of [32] propose in theirDue work the lack incorporation of two types agent of societies, with the of providing greater Duework to thisthe lack of alternatives when designing agent organizations, the authors of [32] propose in their incorporation of two new types of societies, with the aim of providing greater diversity. Specifically, the authors describe these two new companies as: semi-open companies and in their work the incorporation two new types ofnew societies, with as: the semi-open aim of providing greater diversity. Specifically, the authorsofdescribe these two companies companies and semi-closed companies. the diversity. Specifically, authors describe these two new companies as: semi-open companies and semi-closed companies. In semi-open societies, the figure of the person in charge of access is implemented, who will be semi-closed companies. In semi-open societies, the figure of the person in charge of access is implemented, who will be in charge of determining if anthe agent can the organization oraccess not. As implemented, shown in Figure 8,will first, In semi-open societies, figure ofjoin the person in charge or of bethe in charge of determining if an agent can join the organization not. Asisshown in Figurewho 8, first, the agent seeking to join the organization requests access to the person in charge, and once it is determined in charge of determining if an agent can join the organization or not. As shown in Figure first,itthe agent seeking to join the organization requests access to the person in charge, and 8,once is that the agent is to suitable for organization incorporation (or not),access this proceeds to access to the rest ofonce the agents. agent seeking join the requests to the person in charge, and it of is determined that the agent is suitable for incorporation (or not), this proceeds to access to the rest The person in that charge access must evaluate if the candidate agent trustworthy and,to therefore, able determined theof agent is suitable for incorporation (orifnot), thisisproceeds to access the rest of the agents. The person in charge of access must evaluate the candidate agent is trustworthy and, to the access. It is also possible to implement different levels of access, depending on the level of trust agents.able Thetoperson access to must evaluatedifferent if the candidate is depending trustworthyonand, therefore, access.inItcharge is also of possible implement levels ofagent access, the assigned by the person responsible for access. therefore, able to access. It is also possible to implement different levels of access, depending on the level of trust assigned by the person responsible for access.

level of trust assigned by the person responsible for access.

Figure agentin inaasemi-closed semi-closedsociety. society. Figure8.8.Access Access of of an external external agent Figure 8. Access of an external agent in a semi-closed society.

OnOnthe external agents agentsare arenot notallowed allowedto toenter enter theother otherhand, hand,inin semi-closed semi-closed societies, societies, external thethe On the However, other hand,they in have semi-closed societies, external areagent not allowed to society enter the organization. they havethe thepossibility possibility starting a new within the that organization. However, of of starting a agents new agent within the society that will organization. However, they have the possibility of starting a new agent within the society that will will act on behalf of the external agent, as shown in Figure 9. This operation is carried out through act on behalf of the external agent, as shown in Figure 9. This operation is carried out through a act on behalf ofagent the external agent, as shown in Figure 9.agent This operation is requests carried out through a to. representative responsible forfor whom thethe candidate contacts and access to. The a representative agent responsible whom candidate agent contacts and requests access representative agent responsible for whom the candidate agent contacts and requests access to. The representative agent created will will be anbe agent previously pre-defined by the system These The representative agent created an agent previously pre-defined by thedesigner. system designer. representative agenthave created will be an agent previously pre-defined by the good system designer. These types of companies a greater potential when it comes to implementing stability and trust, These types of companies have a greater potential when it comes to implementing good stability and types of companies have a flexibility greater potential when itfor comes to implementing good stability andIntrust, while providing adequate and openness the inclusion of new external elements. this trust, while providing adequate flexibility and openness for the inclusion of new external elements. whileofproviding adequate flexibility delimited and openness the inclusion new external elements. this company, it is very whatfor optimal access of flexibility will produce anInopen In type this type of company, it is clearly very clearly delimited what optimal access flexibility will produce an type of company, it is very clearly delimited what optimal access flexibility will produce an open system, but at the same time one which is secure and under the control of the organization open system, but at the same time one which is secure and under the control of the organization system, but atMaintaining the same time oneover which is secure and the control ofmany the organization administrator. control thethe architecture is a under prerequisite to apply ofmany the multiadministrator. Maintaining controlover over architecture is a prerequisite to many applyof of the administrator. Maintaining control the architecture is a prerequisite to apply the multiagent coordination paradigms [38]. multi-agent coordination paradigms [38]. agent coordination paradigms [38].

Figure 9. Creation of a representative agent in a semi-closed society. Figure agentininaasemi-closed semi-closedsociety. society. Figure9.9.Creation Creation of of a representative representative agent

Sensors 2019, 19, 100

13 of 25

Sensors 2018, 18, x FOR PEER REVIEW

13 of 25

As previously previously mentioned, mentioned, the the agent agent society society implemented implemented in in the the architecture architecture proposed proposed in in this this As paper follows the principles of a semi-closed society. Each of the external hardware devices that paper follows the principles of a semi-closed society. Each of the external hardware devices that make make IoT devices an external embedded that its representative the up theup setthe of set IoT of devices has anhas external embedded agent agent that has itshas representative in the in MAS MAS architecture. architecture. As shown shown in in Figure Figure 10 10 and and described described in in previous previous sections, sections, the the architecture architecture is is built built on on the the JADE JADE As framework as as aa basis basis for for its its implementation. implementation. The The first first sub-organization sub-organization is is identified identified with with the the security security framework layer implemented in the system, with the aim of filtering all communications that are made from layer implemented in the system, with the aim of filtering all communications that are made from outside the the organization. organization. To outside To ensure ensure that thatexternal externalagents agentsare arereally reallywho whothey theyclaim claimtotobe, be,ininthis thislayer, layer,a validation of the tokens associated with the communications made is performed. For this purpose, a validation of the tokens associated with the communications made is performed. For this purpose, there is is aa database database where where all all the the valid valid tokens tokens of of the the system will be be stored stored and and registered. registered. The The agent agent there system will management layer layer is is built built on on the the sub-organization sub-organization responsible responsible for for the the management management of of representative representative management agents for agents embedded in hardware devices. In this layer, there is a database where all all the the agents for agents embedded in hardware devices. In this layer, there is a database where possible profiles of the newly created representative agents are registered. possible profiles of the newly created representative agents are registered.

Figure 10. 10. General General scheme scheme for for the the proposed proposed architecture. architecture. Figure

The control thethe main sub-organization of theofarchitecture and will be in charge of charge managing The controllayer layeris is main sub-organization the architecture and will be in of both the communications of the devices, as well as all the information sent by the devices the managing both the communications of the devices, as well as all the information sent by the and devices management and execution of the tasks required by the users of users the system. and the management and execution of the tasks required by the of the system. The agents that compose this architecture follow the BDI deliberative model [39,40], in which an agent possesses a type of mental attitude about their beliefs (Beliefs), desires (Desires), and intentions (Intentions), which represent the states of information, motivation, and decision of the agent,

Sensors 2019, 19, 100

14 of 25

The agents that compose this architecture follow the BDI deliberative model [39,40], in which an agent possesses a type of mental attitude about their beliefs (Beliefs), desires (Desires), and intentions (Intentions), which represent the states of information, motivation, and decision of the agent, respectively. Therefore, as BDI deliberative agents, they can make use of reasoning mechanisms and learning techniques to perform management functionalities and coordination of them according to the particularities of the context in which they are executed. 3.6.2. Security Layer This sub-organization will be responsible for managing the security of the architecture, analyzing the communications that arrive from the outside, and validating that the access tokens are valid and active in the system. The three roles involved in this layer that are analyzed below are: Security coordinator, token manager, and validator. Security Coordinator Role: The Security Coordinator role is primarily responsible for the security and trust of the system in its relationship with agents external to the organization. The agent in charge of this role is the first to receive requests for access by external elements, so it must convert the MQTT messages to the FIPA-ACL standard. It must be verified that the sender of the message comes from a reliable source and that the structure of the sent message is correct and does not contain errors or faults. In the event that the external agent has a token, the agent with this role sends it to the agent with the Token Manager role, which proceeds to check it in the token database enabled in the system. In the event that the token is correct, a message is issued to the agent with the Validator role to proceed with the request of the external agent. This role is also in charge of connection requests through the REST web service for the assignment of a topic MQTT. Token manager role: As mentioned in the previous section, the agent with the Token Manager role is responsible for checking if the token is valid and is registered in the database. In the same way, this agent is in charge of notifying the agent with the coordinating role of Security if the token is valid or if it is not. The behavior of this agent based on that indicated follows the reactive model. Therefore, rules are defined so that the agent, after checking the token in the database, determines if it is valid or not. Validation role: The agent with the validating role is responsible for processing access requests after verifying that the tokens are correct, or that it is a request from a new external agent. This agent will be in communication with the coordinator of the representative agents and will be in charge of deciding if it is necessary to start the process of creating a new representative agent. 3.6.3. Management Layer of Representatives This layer is related to the sub-organization responsible for managing the requests of external agents for the creation of new agents that act on their behalf within the organization. The existing roles that are detailed below are: Representative Coordinator, Profile Manager, and Representative Generator. Coordinator of Representatives: The agent with the role of Coordinator of representatives will be responsible for managing the incorporation of new agents representatives within the organization. First, it must determine if the external agent that has requested the creation of a representative is suitable for its inclusion, if it complies with the security requirements, and if it implements the necessary services for the profile it requests. In the case of accepting the request, this agent issues a message to the agent with a Profile Manager role to start the creation process. In the event that the request refers to a representative agent already created and existing in the organization, this coordinator forwards the original message to the IoT coordinator of the control sub-organization. Profile Manager Role: Once the agent with the role Coordinator of Representatives has given its approval to the creation of a new agent, the agent with role Manager of Profiles is in charge of looking in the database of profiles for the one that best fits the characteristics of the external agent. These profiles are previously programmed according to the case study and deployment environment of

Sensors 2019, 19, 100

15 of 25

the IoT system. After selecting the profile, this agent issues a message to the agent with the Generator of Representatives role, who will ultimately be responsible for its creation. Generator of Representatives Role: The final person in charge of generating a new agent within the organization will be the agent with the Generator of Representatives role, who will communicate, as previously mentioned, with the Profile Manager agent. Once the new representative agent with the selected profile has been generated, this agent is responsible for registering it in the organization and registering its data so, from that moment, the rest of the agents involved know of its existence. 3.6.4. Control Layer The control layer will be the main sub-organization of the multi-agent architecture focused on managing the IoT environments in which it will be deployed. The roles involved that are detailed below are: IoT Coordinator, Topics Manager, IoT Data Manager, Executor, Mobile Agent, and Representative. IoT Coordinator Role: The agent with the coordinating role will be in charge of supervising the correct functioning of the active agents in the system. Through the monitoring of the data sent by the agents, it will be in charge of processing the information and determining if it is necessary for the representative and mobile agents to take any action in the IoT environment. Role Manager of Topics: The role Manager of Topics is in charge of monitoring the communications that are made through this protocol with external agents. They will be in charge of assigning new communication topics between a representative agent and their external agent. These topics will be stored in a database that will be implemented for this purpose and will be managed by the agent in charge of this role. When a new external agent requests the creation of a new representative agent, the agent with the role Manager of Topics will generate a new topic in a random and univocal way in the system for safe and consistent communication. IoT Data Manager Role: All the data measured and analyzed by the external hardware devices that are sent to the IoT architecture are analyzed, normalized, and stored by the agent with the IoT Data Gesture role. This agent is in charge of managing the database where all the data obtained is stored. The functionality of this agent is independent of the underlying technology used for the implementation of the database that may vary, depending on the needs and characteristics of the data analyzed in the environment. The agent in charge of this role will also be the intermediary of the agent with the executing role, responsible for sending the requested data in the service layer. Executing role: One of the main functionalities of the system is to provide services and data to users and external applications that wish to make use of this system. For this, the agent with the Executor role will be the link between the data and the services provided by the system through the service layer. This agent will process the requests that arrive from the service layer and will communicate with the agent with the IoT Data Manager role for the data query. This agent will also check the level of permissions and privileges of the users and applications that request data and determine if the requested data can be accessed by them. The implementation of the agent in charge of this role will depend on the specific case study in which the system is deployed. Mobile Agent Role: As detailed in previous sections, the so-called type B devices (they do not have a direct communication channel with the Internet) need a communication gateway with the Internet. The agent with the Mobile role will be the representative of the agent embedded in the Smartphone device in charge of communicating with Type B devices. As it is a type of agent capable of migrating its code and status from the Smartphone to the main IoT architecture, it is necessary that the agent with the role Mobile Agent is representative for cases in which the agent is cloned or moved from its original location. In addition, this agent will be responsible for communicating and exchanging data with the original agent from the Smartphone. Representative Role: The representative role is in charge of representing the external agents that request to enter the organization and are authorized for them. In the case of this system, the external agents are the agents embedded in the limited hardware devices and the component the IoT system implemented. The operation of these agents is key to the correct communication of hardware devices

Sensors 2019, 19, 100

16 of 25

with the rest of the system. They are in charge of direct communications through MQTT with external agents and are responsible for transforming the messages that arrive through JSON messages into standardized FIPA-ACL messages so that they can be delivered and read by the rest of the agents of the organization. The possible profiles that these agents will have will depend on the cases and environments in which the system is deployed. It will be necessary to differentiate three types of general profiles from which the rest of the profiles will be derived: sensor profile, effector profile, and mixed profile. In cases in which the hardware devices have one or more sensors and send the measured data to the organization, a representative agent with a sensor profile must be generated. In those cases in which the device is equipped with only one or several effectors (actuators), a new representative agent with an effector role must be generated. For cases in which one or more sensors are available in combination with one or several effectors, the profile of the representative agent generated will be mixed. 3.6.5. Services Layer This layer includes the services and functionalities offered by the IoT architecture on the data and devices active in the system. It will be possible to access these services in a ubiquitous and distributed way so that the computer systems that support the multi-agent architecture are not affected. The services and functionalities to be implemented will depend on each study and environment in which the system is deployed. The objective of this research work is the analysis and design of the upper layers previously described, and the final implementation of this layer is not focused. It will be possible to apply proven strategies with good results in other research works such as [41,42], where they apply subscription systems to define the services and functionalities that will be accessed by users and applications of the system. 3.7. Security and Trust Now the structure and functionality of the multi-agent architecture has been described, which will form the central part of the proposed system, this section analyzes the security and trust mechanisms in the system. In particular, when addressing security, as previously introduced, the system implements encryption over SSL/TLS to achieve a strong encryption of messages. Both ESP8266 and ESP32 devices have the necessary capacity to execute these encryption protocols without affecting their performance. Specifically, the ESP8266 can work as an SSL client or as an SSL server. Thanks to this native functionality, it is possible to generate bidirectional authentication with the server, in such a way that the messages exchanged between the embedded agent and the rest of the organization are protected and encrypted. The agent with the role Security Coordinator will be responsible for managing the network of certificates between agents. When it comes to providing a greater degree of confidence and avoiding anomalous behavior in embedded agents, the figure of the representative agent has been implemented. As mentioned in the previous section, thanks to the implementation of the representative agent mechanism, all the new instances that correspond to a new embedded agent will be created from within the organization. Being created from within, the system ensures that the behavior of the agent is clearly defined and strictly limited to the functions assigned by default. Below are some of the sequence schemes involved in the security and trust of the system. Figure 11 shows the relationship between the embedded agent and the security coordinator when processing an external access request with a previous token. In this relation, the token manager checks the validity of the sent token.

Sensors 2019, 19, 100

17 of 25

Sensors 2018, 18, x FOR PEER REVIEW

17 of 25

Figure Figure11. 11. Relationship Relationshipbetween betweenthe theembedded embeddedagent agentand andthe thesecurity securitycoordinator. coordinator.

The Figure 12 shows the relationship betweenbetween the three the agents of the sub-organization Thediagram diagramof of Figure 12 shows the relationship three agents of the subfor the management of representative agents. Specifically, the process of consulting and sending and the organization for the management of representative agents. Specifically, the process of consulting profile that new representative agent generated willgenerated have is shown. In this agents outside sending thethe profile that the new representative agent will have is way, shown. In this way, the organization are prevented from injecting malicious external codes into the organization. All agents outside the organization are prevented from injecting malicious external codes into the the agents included inthe theagents systemincluded are registered the system itself. by the system itself. organization. All in the by system are registered

Figure12. 12.Process Processof ofconsulting consultingthe theprofile profileof ofaanew newagent. agent. Figure

The Thediagram diagramin inFigure Figure13 13shows showsthe theinteraction interactionbetween betweenaauser useror orexternal externalapplication applicationand andthe the agentin incharge chargeof ofprocessing processingand andexecuting executingrequests requestsfor foraccess accessto todata datathat thatarrive arriveto tothe thesystem, system,once once agent hasbeen beenverified verifiedthat thatthe thepermissions permissionsare arecorrect. correct. In In this this way, way,security securityand andconfidence confidenceare areassured assured itithas whensending sendingthe thedata datagenerated generatedby bythe thesystem. system. when

Sensors 2019, 19, 100

18 of 25

Sensors 2018, 18, x FOR PEER REVIEW

18 of 25

Figure Figure13. 13.Process Processof ofinformation informationexchange exchangefrom fromoutside outsidethe thesystem. system.

4.4.Case CaseStudy Study After Afterhaving havinganalyzed analyzed the the current current state stateof ofthe theart artand andhaving havingdetailed detailedthe theproposed proposedsystem systemin in this thiswork, work,the thesystem systemdesigned designedin inaareal realIoT IoTenvironment environmentwill willnow nowbe beput putinto intopractice. practice.Through Throughthe the implantation implantationof ofdifferent differentsensors sensorson onaabicycle, bicycle,ititisispossible possibleto toobtain obtaininteresting interestingdata dataabout aboutthe theroute route taken, the effort of the user, and the behavior of the vehicle. The transport sector is one of the most taken, the effort of the user, and the behavior of the vehicle. The transport sector is one of the most important action in the building intelligent environments that seekthat to improve importantfields fieldsof of action in IoT. the Therefore, IoT. Therefore, building intelligent environments seek to the transport and mobility of vehicles in cities and roads, while optimizing energy and safety resources, improve the transport and mobility of vehicles in cities and roads, while optimizing energy and safety isresources, essential when it comes to achieving sustainability in the cities of the future. is essential when it comes to achieving sustainability in the cities of the future. Then, Then,in inthe thefollowing followingsections, sections,the thecase casestudy studywill willbe becarried carriedout outin inaareal realenvironment, environment,based based on the system proposed in this work, where it will monitor the routes made by an electric bicycle. on the system proposed in this work, where it will monitor the routes made by an electric bicycle. The safety, energy Theregistration registrationof ofthese thesedata datamay maybe beused used in in future future work work in in areas areas such such as as safety, energy optimization, optimization, or the comfort of bicycle users. It is a simple case study whose main objective or the comfort of bicycle users. It is a simple case study whose main objective isis to toillustrate illustrate and and validate the functioning of the system proposed in this work. More specifically, the case study will validate the functioning of the system proposed in this work. More specifically, the case study will be becarried carriedout outthrough throughan anelectric electricbicycle bicyclesince sinceitithas hasbeen beenaavery verypopular populartype typeof ofvehicle vehiclein inrecent recent years and provides a series of sensors and extra safety elements that improve the efficiency years and provides a series of sensors and extra safety elements that improve the efficiency of ofthe the system. In any case, the system can be implemented in the same way in a conventional bicycle through system. In any case, the system can be implemented in the same way in a conventional bicycle the implantation of the necessary sensors. In order to the efficiency of the proposed system, through the implantation of the necessary sensors. In measure order to measure the efficiency of the proposed this system has been compared with a traditional system based on sending data. Three fundamental system, this system has been compared with a traditional system based on sending data. Three aspects, including battery life, processing time, and abilitytime, to incorporate nodes, are compared. fundamental aspects, including battery life, processing and abilitynew to incorporate new nodes, are compared. 4.1. Architecture Implementation

This architecture is composed of a sensor network integrated into the bicycle, as well as a sensor 4.1. Architecture Implementation network deployed in the user’s Smartphone device and on the user’s own body. Thanks to them, This architecture is composed of a sensor network integrated into the bicycle, as well as a sensor it is possible to analyze all the data that occurs during the realization of a bicycle tour. Some of network deployed in the user's Smartphone device and on the user's own body. Thanks to them, it is these data are: Heart rate, battery level, or wheel speed. Figure 14 shows the general scheme for possible to analyze all the data that occurs during the realization of a bicycle tour. Some of these data this proposed system in the case study. As can be seen, within the proposed architecture are the are: Heart rate, battery level, or wheel speed. Figure 14 shows the general scheme for this proposed three sub-organizations described above and that correspond to the multi-agent system proposed in system in the case study. As can be seen, within the proposed architecture are the three subthis paper. organizations described above and that correspond to the multi-agent system proposed in this paper.

Sensors 2019, 19, 100

19 of 25

Sensors 2018, 18, x FOR PEER REVIEW

19 of 25

Sensors 2018, 18, x FOR PEER REVIEW

19 of 25

Figure 14.General Generalscheme scheme of Figure 14. of the theproposed proposedsystem. system. Figure 14. General scheme of the proposed system.

sensor network deployedininthis thiscase case study study that environment is the most TheThe sensor network deployed thatmakes makesup upthe theIoT IoT environment is the most commonly used for electric bicycles and practically all commercial electric bicycles already have it. commonly for electricdeployed bicyclesinand all makes commercial bicycles isalready Theused sensor network this practically case study that up the electric IoT environment the mosthave When a user travels a route on an electric bicycle, it is important that certain parameters are recorded it. When a user travels a route on an electric bicycle, it is important that certain parameters commonly used for electric bicycles and practically all commercial electric bicycles already have it. are during the trip to provide useful information, such as speed, battery consumption, GPS, and recorded the trip to provide useful information, such as speed, battery consumption, GPS, and Whenduring a user travels a route on an electric bicycle, it is important that certain parameters are recorded fundamentally, the Smartphone's accelerometer. fundamentally, the Smartphone’s accelerometer. during the trip to provide useful information, such as speed, battery consumption, GPS, and fundamentally, the Smartphone's accelerometer. 4.2. Sensor System

4.2. Sensor System

FigureSystem 15b shows the deployed sensor system that will act as the IoT layer of the proposed 4.2. Sensor Figure 15binshows the deployed sensor system that act asrole: theon IoT of the proposed architecture the case study. The user's Smartphone playswill a double thelayer one hand, it makes Figure 15b case shows the deployed sensor system that will act as the IoTon layer of the proposed architecture in the study. The user’s Smartphone plays a double role: the one hand, it makes use of different sensors that have the vast majority of devices, such as the GPS sensor, compass, or architecture in the casethat study. The user's Smartphone plays a double role: on the one hand, compass, it makes or use of different sensors have the vast majority of devices, such as the GPS sensor, accelerometer; on the other hand, it provides a mobile data network to the ESP8266. Connected to use of different sensors that haveitthe vast majority of devices,network such as the GPSESP8266. sensor, compass, or accelerometer; on the other provides a mobile to the Connected this device and through ahand, Bluetooth connection are thedata rest of the elements of the system. One of to accelerometer; on the other hand, it provides a mobile data network to the ESP8266. Connected to is the bicycle, which provides basic information, as speed, energy consumption, or of this them device andelectric through a Bluetooth connection are the restsuch of the elements of the system. One this device and through a Bluetooth connection are the rest of the elements of the system. One of the other hand, it is possible connect different sensors, such as the heart or thembattery is the charge. electricOn bicycle, which provides basictoinformation, suchexternal as speed, energy consumption, them is the electric bicycle, which provides basic information, such as speed, energy consumption, or ratecharge. monitorOn responsible measuring the heart rate of the user during thesensors, performance battery the other for hand, it is possible to connect different external such of asan theelectric heart rate battery charge. On the other hand, it is possible to connect different external sensors, such as the heart bike tour. Figure 15a shows a classic approach to the problem through the use of cloud computing monitor responsible for measuring the heart rate of the user during the performance of an electric rate monitor responsible for measuring the heart rate of the user during the performance of an electricbike services suchshows as Firebase. This regular approach aims tothrough comparethe theuse efficiency ofcomputing the architecture tour.bike Figure classic to the problem ofuse cloud services tour.15a Figure 15aashows aapproach classic approach to the problem through the of cloud computing proposed in this work. suchservices as Firebase. This regularThis approach to compare efficiency of the architecture proposed in such as Firebase. regularaims approach aims tothe compare the efficiency of the architecture this work. proposed in this work.

Figure 15. (a) Regular approach system based on cloud computing service. (b) Proposed approach based on Mobile Agent and Embedded Agent. Figure Regular approachsystem systembased based on on cloud cloud computing (b)(b) Proposed approach Figure 15. 15. (a) (a) Regular approach computingservice. service. Proposed approach based on Mobile Agent and Embedded Agent. based on Mobile Agent and Embedded Agent.

Sensors 2019, 19, 100

20 of 25

Sensors 2018, 18, x FOR PEER REVIEW

20 of 25

Specifically, Specifically, in in this this case case study, study,an anelectric electricbicycle bicycleof of the the Orbea Orbea brand brand has has been been used, used, to to which which an an IoT node has been added through an ESP8266, as can be seen in Figure 16. In this way, all the that IoT node has been added through an ESP8266, as can be seen in Figure 16. In this way, alldata the data are by theby system are managed by the IoT nodeIoT on node whichon thewhich embedded agent is deployed thatmeasured are measured the system are managed by the the embedded agent is that will act as an external agent in the MAS designed architecture. deployed that will act as an external agent in the MAS designed architecture.

Figure 16. 16. Sensorization system deployed on an electric electric bicycle. bicycle.

4.3. 4.3. Results Results As As previously previously mentioned, mentioned, the the case case study study carried carried out out in in this this work work compares compares aa classical classical approach approach based on a sensorization and cloud processing system with a new approach based based on a sensorization and cloud processing system with a new approach based on on embedded embedded intelligent To carry carry out intelligent agents. agents. To out this this comparison, comparison, the the data data collection collection platform platform for for electric electric bicycles bicycles ebikemotion developed in collaboration with the research group of the University of Salamanca ebikemotion developed in collaboration with the research group of the University of Salamanca has has been been used. used. This This platform platform has has more more than than 5000 5000 active active users users around around the the world world who who send send data data on on their their electric electric bike bike routes routes daily. daily. Thanks Thanks to to the the data data collected collected through through the the traditional traditional approach, approach, it it is is possible possible to compare the data of the routes obtained by the users who have tried the system proposed to compare the data of the routes obtained by the users who have tried the system proposed in in this this work. First, itit isispossible possibletotocompare comparethe theresults resultsonon battery consumption system. Thanks to work. First, battery consumption byby thethe system. Thanks to the the continuous sending of the battery charge, it is possible to measure the efficiency of the system. continuous sending of the battery charge, it is possible to measure the efficiency of the system. The The categorized based ondistance the distance traveled byusers the users on route, each route, obtaining datadata havehave beenbeen categorized based on the traveled by the on each obtaining three three groups of routes: less5 than 5 km, routes between 5 and andof routes more groups of routes: RoutesRoutes of lessof than km, routes between 5 and 15 km, 15 andkm, routes moreof than 15 than 15 km. As shown in Figure 17, the battery consumption (battery of the electric bicycle plus km. As shown in Figure 17, the battery consumption (battery of the electric bicycle plus Smartphone Smartphone battery) is always the routes where the proposed system hasThis beenreduction used. This battery) is always lower in the lower routes in where the proposed system has been used. in reduction in battery consumption is mainly duethat to the that the information in the regular system is battery consumption is mainly due to the fact thefact information in the regular system is processed processed in its entirety in device, the mobile and as acommunication continuous communication of input/output in its entirety in the mobile and device, as a continuous of input/output of data within of within the cloudwhile environment; while in the proposed system,ofthe of the data is thedata cloud environment; in the proposed system, the computing thecomputing data is distributed in the distributed in the different IoT devices deployed. Likewise, communication with the agent architecture different IoT devices deployed. Likewise, communication with the agent architecture involves more involves more agile and lighter communication in the sending of data producedwith with regular regular agile and lighter communication in the sending of data thanthan thatthat produced cloud cloud environments. environments.

Sensors FOR PEER REVIEW Sensors 2018, 2019, 18, 19, x 100 Sensors 2018, 18, x FOR PEER REVIEW

21 21of of 25 25 21 of 25

Figure Figure 17. 17. Comparison Comparison of of average average battery battery consumption. consumption. Figure 17. Comparison of average battery consumption.

Other Other data data comparatively comparatively analyzed analyzed in in the the study study was was the the processing processing speed speed of of the the different different data data Other data comparatively analyzed in the study was the processing speed of the different data from the electric bicycle. It should be noted that in the traditional system, the data is sent in a from the electric bicycle. It should be noted that in the traditional system, the data is sent in a raw raw from the the electric bicycle. It should be noted that in the traditional system, the data, data is sent in aGPS raw format format to to the server server that that later later is is responsible responsible for for filtering filtering and and pre-processing pre-processing the the data, correcting correcting GPS format to the server that later is responsible for filtering and pre-processing the data, correcting GPS locations, locations, and and adjusting adjusting the the altitudes altitudes of of the the route. route. In In the the case case of of the the proposed proposed system, system, the the embedded embedded locations, and adjusting the altitudes offiltering the route. In the case of the proposed system, the embedded agent is in charge of the previous data (avoid duplicate data, null values, etc.) agent is in charge of the previous data filtering (avoid duplicate data, null values, etc.) based based on on the the agent is in charge of the previous data filtering (avoid duplicate data, null values, etc.) based on the characteristics characteristics sent sent from from the the representative representative agent agent of of the the IoT IoT device. device. Despite Despite this this preprocessing preprocessing task, task, characteristics sent from the representative agent filtered of the IoT device. Despitemore this preprocessing task, the the speed speed at at which which the the system system stores stores the the final final data data filtered from from the the route route is is more optimal optimal than than in in the the the speed at which the system final 18. data filtered from the route is more optimal than in the traditional be stores seen in inthe Figure traditional approach, approach, as as can can be seen Figure 18. traditional approach, as can be seen in Figure 18.

Figure 18. (a) Regular approach and three measured elements. (b) Proposed approach and three Figure 18. (a) Regular approach and three measured elements. (b) Proposed approach and three measured elements. (c) Regular approach and five measured elements. (d) Proposed approach and Figure 18.elements. (a) Regular approachapproach and three measured elements. (b) Proposed approach and three measured (c) Regular and five measured elements. (d) Proposed approach and five measured elements. measured elements. (c) Regular approach and five measured elements. (d) Proposed approach and five measured elements. five measured elements.

The routes that only have three measurement values (speed, assistance level, and battery) have The routes that only have three measurement values (speed, assistance level, and battery) have been The compared to those with five variables (speed, attendance level, battery, heart rate, and cadence). routesto that only have three measurement values (speed, level,rate, andand battery) have been compared those with five variables (speed, attendance level,assistance battery, heart cadence). After analyzing the average response time of both proposals, it can be observed that the proposed been compared to those with five variables (speed, attendance level, battery, heart rate, and cadence). After analyzing the average response time of both proposals, it can be observed that the proposed system provides athe significant response times.itItcan is alsoobserved possible tothat observe how the After analyzing average improvement response timeinin ofthe both proposals, the proposed system provides a significant improvement the response times. It isbealso possible to observe how system provides a significant improvement in the response times. It is also possible to observe how

Sensors 2019, 19, 100 Sensors 2018, 18, x FOR PEER REVIEW

22 of 25 22 of 25

increase of users (active(active routes)routes) does not greatly theaffect execution times, which remain practically the increase of users does not affect greatly the execution times, which remain constant, the classic practicallyunlike constant, unlikeapproach. the classic approach. As a final result of the the case case study, study, an an open open and and scalable scalable system system has has been been designed, designed, which is capable of obtaining all the data produced while performing an activity on an electric bicycle in real time. ItIt isisa asystem capable of incorporating newnew sensors to add information or to replace system capable of incorporating sensors to new add accurate new accurate information or to the sensors with different ones, without the need reprogram the system. In Figure 19, the replace the sensors with different ones, without thetoneed to reprogram the system. In Figure 19,data the obtained by a bicycle after being storedstored in the in central server,server, where where it will later analyzed in search data obtained by a bicycle after being the central it willbelater be analyzed in of possible optimizations or on which monitoring can be performed in searchinofsearch security search of possible optimizations or onreal-time which real-time monitoring can be performed of elements such as falls, or abnormal driving behavior, can be viewed. security elements suchaccidents, as falls, accidents, or abnormal driving behavior, can be viewed.

Figure Data collected collected by by the the sensorization sensorization system Figure 19. 19. Data system on on aa bicycle bicycle route. route.

5. Conclusions 5. Conclusions In this paper, an intelligent system based on agents embedded in wireless devices with reduced In this paper, an intelligent system based on agents embedded in wireless devices with reduced capacities (memory and limited computing capacity) for Internet of Things (IoT) environments has capacities (memory and limited computing capacity) for Internet of Things (IoT) environments has been presented. been presented. This system is integrated into a multi-agent architecture that will be responsible for managing the This system is integrated into a multi-agent architecture that will be responsible for managing different wireless devices that make up the IoT scenario in which the system is deployed. Two main the different wireless devices that make up the IoT scenario in which the system is deployed. Two types of wireless devices that can be deployed have been identified: Wireless devices capable of main types of wireless devices that can be deployed have been identified: Wireless devices capable exchanging information with the Internet and devices that require a gateway that acts as a link of exchanging information with the Internet and devices that require a gateway that acts as a link between the device and the Internet. These two types of devices have been called type A devices and between the device and the Internet. These two types of devices have been called type A devices and type B devices, respectively. type B devices, respectively. For each of them, a different strategy is proposed when embedding software agents on them. For each of them, a different strategy is proposed when embedding software agents on them. For type A devices, a communication middleware based on MQTT and a semi-closed agent architecture For type A devices, a communication middleware based on MQTT and a semi-closed agent has been designed, where a representative agent acting on behalf of the device is generated within architecture has been designed, where a representative agent acting on behalf of the device is the MAS architecture. For cases in which the devices do not have a direct communication channel generated within the MAS architecture. For cases in which the devices do not have a direct with the Internet (type B), it is necessary to introduce a Gateway device. In the system designed in communication channel with the Internet (type B), it is necessary to introduce a Gateway device. In this work, a mobile agent is introduced in a Smartphone device that acts as a gateway between these the system designed in this work, a mobile agent is introduced in a Smartphone device that acts as a devices and the multi-agent system. This mobile agent is responsible for collecting information from gateway between these devices and the multi-agent system. This mobile agent is responsible for external devices and then transmitting the information to an agent within the organization. collecting information from external devices and then transmitting the information to an agent within Regarding the IoT multi-agent organization designed in this work, it is worth noting that it is a the organization. semi-closed organization able to include new external agents in a controlled manner, guaranteeing Regarding the IoT multi-agent organization designed in this work, it is worth noting that it is a stability, trust, flexibility, and openness. For this, the MAS system is organized into four different semi-closed organization able to include new external agents in a controlled manner, guaranteeing layers. The first is a security layer where all the messages that arrive from the outside of the system stability, trust, flexibility, and openness. For this, the MAS system is organized into four different layers. The first is a security layer where all the messages that arrive from the outside of the system will be filtered, avoiding the malicious injection of messages or the communication with previously

Sensors 2019, 19, 100

23 of 25

will be filtered, avoiding the malicious injection of messages or the communication with previously unregistered agents. A second layer will be in charge of the management of new representative agents that act on behalf of the wireless devices. The third layer contains all the agents responsible for IoT data management and the coordination of the architecture. The service layer is open and may contain mechanisms and techniques for processing and analyzing different data, depending on the environment in which the system is deployed. Finally, in order to validate the proposed system, a case study was carried out in a real IoT environment. In the same way that the system proposed in this paper has been successfully deployed in an IoT environment, such as a connected electric bicycle, it is possible to deploy this system in other environments. The progressive success experienced by the IoT phenomenon and the connected cities, raises an endless number of possible scenarios where the integration of the proposed system in this work can mark an advance with respect to other systems proposed in the current literature. As future work, it will be possible to analyze alternatives in the security layer to include new paradigms of security and trust that improve the robustness of the system. It will also be a future line of research to implement the proposed system in massive environments where sensor systems include thousands of devices. This will allow, among other things, to check the flexibility when adding large sensor networks with important amounts of software agents embedded in the system. Another point to be addressed in future research is the combination of techniques for data monitoring, sampling, and filtering to obtain an improvement in the performance of IoT devices. As has been demonstrated in works such as [43,44] or more recently in [45], implementing adaptive algorithms of sampling and filtering for the data generated in the environment can lead to an even greater optimization in aspects such as the volume of data generated or the battery consumption. This is a very interesting field of research, and the combination of different methodologies and approaches will lead to fully intelligent environments in the near future. Author Contributions: D.H.D.L.I. and A.L.B. have developed the system; they made the test and elaborated the review of the state of the art. D.M.J.-B., A.S.M., and G.V.G. formalized the problem and the algorithms, and reviewed the work. All the authors contributed to the redaction of the paper. Funding: The research of Diego M. Jiménez-Bravo has been co-financed by the European Social Fund and Junta de Castilla y León (Operational Programme 2014-2020 for Castilla y León, EDU/574/2018 BOCYL). Conflicts of Interest: The authors declare no conflict of interest.

References 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.

Han, Q.; Liang, S.; Zhang, H. Mobile cloud sensing, big data, and 5G networks make an intelligent and smart world. IEEE Netw. 2015, 29, 40–45. [CrossRef] Smart Cities The Importance of a Smart ICT Infrastructure for Smart Cities. Available online: https://www. stokab.se/Documents/Nyheter%20bilagor/SmartCityInfraEn.pdf (accessed on 28 December 2018). Hutchison, D.; Mitchell, J.C. The Internet of Things; Springer: Zurich, Switzerland, 2008; ISBN 9783540342915. Shi, W.; Cao, J.; Zhang, Q.; Li, Y.; Xu, L. Edge Computing: Vision and Challenges. IEEE Internet Things J. 2016, 3, 637–646. [CrossRef] Patil, P.V. FOG Computing. Int. J. Comput. Appl. 2015, 1, 1–6. Chen, S.; Zhang, T.; Shi, W. Fog Computing. IEEE Internet Comput. 2017, 21, 4–6. [CrossRef] Evans, D. The Internet of Things—How the Next Evolution of the Internet is Changing Everything. CISCO White Pap. 2011, 1, 1–11. Fortino, G.; Trunfio, P. Internet of Things Based on Smart Objects: Technology, Middleware and Applications; Springer: Cham, Switzerland, 2014; pp. 1–198. Razzaque, M.A.; Milojevic-Jevric, M.; Palade, A.; Clarke, S. Middleware for Internet of Things: A Survey. IEEE Internet Things J. 2016, 3, 70–95. [CrossRef] Savaglio, C.; Calabria, U. Intelligent Distributed Computing XI; Springer International: Zurich, Switzerland, 2018; Volume 737.

Sensors 2019, 19, 100

11.

12. 13. 14.

15. 16. 17.

18. 19.

20. 21. 22. 23.

24. 25. 26.

27.

28. 29. 30. 31. 32.

24 of 25

Issarny, V.; Caporuscio, M.; Georgantas, N. A Perspective on the Future of Middleware-based Software Engineering. In Proceedings of the IEEE Future of Software Engineering (FOSE ’07), Minneapolis, MN, USA, 23–25 May 2007; pp. 244–258. Mamei, M.; Zambonelli, F. Field-Based Coordination for Pervasive Multiagent Systems; Springer: Berlin/Heidelberg, Germany, 2006; ISBN 9783540279693. Fok, C.-L.; Roman, G.-C.; Lu, C. Agilla. ACM Trans. Auton. Adapt. Syst. 2009, 4, 1–26. [CrossRef] Aiello, F.; Fortino, G.; Guerrieri, A.; Gravina, R. MAPS: A mobile agent platform for WSNs based on Java Sun Spots. In Proceedings of the Third International Workshop on Agent Technology for Sensor Networks, Budapest, Hungary, 9 May 2009. Leppänen, T.; Riekki, J.; Liu, M.; Harjula, E.; Ojala, T. Mobile Agents-Based Smart Objects for the Internet of Things; Springer: Cham, Switzerland, 2014; pp. 29–48. Ayala, I.; Amor, M.; Fuentes, L. The Sol agent platform: Enabling group communication and interoperability of self-configuring agents in the Internet of Things. J. Ambient Intell. Smart Environ. 2015, 7, 243–269. Ayala, I.; Amor, M.; Fuentes, L. Self-StarMAS: A multi-agent system for the self-management of AAL applications. In Proceedings of the Sixth International Conference on Innovative Mobile and Internet Services in Ubiquitous Computing, Palermo, Italy, 4–6 July 2012; pp. 901–906. Amor, M.; Fuentes, L. Malaca: A component and aspect-oriented agent architecture. Inf. Softw. Technol. 2009, 51, 1052–1065. [CrossRef] Zhang, X.; Adhikari, R.; Pipattanasomporn, M.; Kuzlu, M.; Bradley, S.R. Deploying IoT devices to make buildings smart: Performance evaluation and deployment experience. In Proceedings of the 2016 IEEE 3rd World Forum Internet Things (WF-IoT), Reston, VA, USA, 12–14 December 2017; pp. 530–535. Brennan, R.W. An Embedded Multi-Agent Systems Based Industrial Wireless Sensor Network. Sensors 2017, 17, 2112. Beigl, M.; Gellersen, H.W.; Schmidt, A. Mediacups: Experience with design and use of computer-augmented everyday artefacts. Comput. Netw. 2001, 35, 401–409. [CrossRef] Cook, D.J.; Das, S.K. How smart are our environments? An updated look at the state of the art. Pervasive Mob. Comput. 2007, 3, 53–73. [CrossRef] Youngblood, G.M.; Heierman, E.O.; Holder, L.B.; Cook, D.J. Automation intelligence for the smart environment. In Proceedings of the IJCAI International Joint Conference on Artificial Intelligence, Edinburgh, Scotland, 30 July–5 August 2005. Werner, E. Cooperating Agents: A Unified Theory of Communication and Social Structure. In Distributed Artificial Intelligence; Elsevier: Amsterdam, Netherlands, 1989; pp. 3–36, ISBN 9781558600928. Walter, B.; Zarnekow, R.; Wittig, H. Intelligent Software Agents. In Intelligent Software Agents; Springer: Berlin/Heidelberg, Germany, 1998; pp. 1–34, ISBN 3-540-63411-8. Decker, K.; Pannu, A.; Sycara, K.; Williamson, M. Designing behaviors for information agents. In Proceedings of the First International Conference on Autonomous Agents-AGENTS ’97, Marina del Rey, CA, USA, 5–8 February 1997; ACM Press: New York, NY, USA, 1997; pp. 404–412. Alcaraz, C.; Najera, P.; Lopez, J.; Roman, R. Wireless Sensor Networks and the Internet of Things: Do We Need a Complete Integration? In Proceedings of the 1st International Workshop on the Security of the Internet of Things (SecIoT’10), Tokyo, Japan, 29 November 2010. Wooldridge, M.; Jennings, N.R.; Kinny, D. The Gaia Methodology for Agent-Oriented Analysis and Design. Auton. Agent. Multi. Agent. Syst. 2000, 3, 285–312. [CrossRef] O’Brien, P.D.; Nicol, R.C. FIPA—Towards a Standard for Software Agents. BT Technol. J. 1998, 16, 51–59. [CrossRef] FIPA The Foundation for Intelligent Physical Agents. Available online: http://www.fipa.org/ (accessed on 7 May 2018). Bellifemine, F.; Poggi, A.; Rimassa, G. JADE–A FIPA-compliant agent framework. Proc. PAAM 1999, 99, 97–108. Davidsson, P. Categories of Artificial Societies. In International Workshop on Engineering Societies in the Agents World; Springer: Berlin/Heidelberg, Germany, 2001; pp. 1–9.

Sensors 2019, 19, 100

33.

34.

35. 36. 37.

38. 39. 40. 41. 42. 43.

44.

45.

25 of 25

Hunkeler, U.; Truong, H.L.; Stanford-Clark, A. MQTT-S—A publish/subscribe protocol for Wireless Sensor Networks. In Proceedings of the IEEE 2008 3rd International Conference on Communication Systems Software and Middleware and Workshops (COMSWARE ’08), Bangalore, India, 6–10 January 2008; pp. 791–798. Artikis, A.; Pitt, J. A formal model of open agent societies. In Proceedings of the Fifth International Conference on Autonomous Agents-AGENTS ’01, Montreal, QC, Canada, 28 May–1 June 2001; ACM Press: New York, NY, USA, 2001; pp. 192–193. Johansson, S.J.; Kummeneje, J. A preference-driven approach to designing agent systems. In Intelligent Agent Technology: Research and Development; World Scientific: Singapore, 2001; pp. 80–85. Davidsson, P. Emergen Societies of Information Agents. Int. Work. Coop. Inf. Agents 2000, 143–153. Zambonelli, F.; Jennings, N.R.; Wooldridge, M. Organisational abstractions for the analysis and design of multi-agent systems. In Lecture Notes in Computer Science (including subseries Lecture Notes in Artificial Intelligence and Lecture Notes in Bioinformatics), Proceedings of the International Workshop on Agent-Oriented Software Engineering, Toronto, Canada, 10–11 May 2010; Springer: Berlin/Heidelberg, Germany, 2001; Volume 1957, pp. 235–251. Lesser, V.R. Reflections on the Nature of Multi-Agent Coordination and Its Implications for an Agent Architecture. Auton. Agents Multi. Agent Syst. 1998, 1, 89–111. [CrossRef] Rao, A.S.; Georgeff, M.P. BDI Agents: From Theory to Practice. Proc. First Int. Conf. Multiagent Syst. 1995, 95, 312–319. O’Hare, G.M.P.; Jennings, N. Foundations of Distributed Artificial Intelligence; Wiley: Hoboken, NJ, USA, 1996; ISBN 0471006750. Cao, B.-Q.; Li, B.; Xia, Q.-M. A Service-Oriented Qos-Assured and Multi-Agent Cloud Computing Architecture; Springer: Berlin/Heidelberg, Germany, 2009; pp. 644–649. Jiang, L.; da Xu, L.; Cai, H.; Jiang, Z.; Bu, F.; Xu, B. An IoT-Oriented Data Storage Framework in Cloud Computing Platform. IEEE Trans. Ind. Inform. 2014, 10, 1443–1451. [CrossRef] Tata, S.; Mohamed, M.; Megahed, A. An Optimization Approach for Adaptive Monitoring in IoT Environments. In Proceedings of the 2017 IEEE International Conference on Services Computing (SCC), Honolulu, HI, USA, 25–30 June 2017; pp. 378–385. Trihinas, D.; Pallis, G.; Dikaiakos, M.D. ADMin: Adaptive monitoring dissemination for the Internet of Things. In Proceedings of the IEEE INFOCOM 2017—IEEE Conference on Computer Communications, Atlanta, GA, USA, 1–4 May 2017; pp. 1–9. Trihinas, D.; Pallis, G.; Dikaiakos, M. Low-Cost Adaptive Monitoring Techniques for the Internet of Things. IEEE Trans. Serv. Comput. 2018. [CrossRef] © 2018 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).