LoRa-Based Traffic Flow Detection for Smart-Road

This paper presents a wireless traffic flow detection system, mainly focused on conditions in which the traffic flow is slow or stopped, which increases the risk of highway accidents. To achieve this goal, a Low Power Wide Area Network (LPWAN) based on LoRa called Short LoRa has been developed. This LoRa sub-network complies with the European Telecommunications Standards Institute (ETSI) harmonized standard for its compatibility in Europe countries. In addition, the development of the devices has allowed them to also work on a LoRaWAN network. The introduced development has been compared to a reference system mounted with laser barriers that provided a high accurate comparison. Field tests of the system have been carried out and the data obtained in the measurement has been analyzed with two different methods, and both of them were valid for the application. The results can determine vehicle speed with adequate precision at low speeds. The attenuating behavior of the communication signal is also analyzed through the Radio Signal Strength Indicator (RSSI). The relationship between vehicle speed, gate distances and RSSI attenuation has been studied. The system is proven to have efficient results in detecting traffic flow under the conditions for which it has been developed.


Introduction
In recent years, continuous advances have been made in radio frequency communications that allow low-power communications to cover long distances. This has caused the development of the Internet of Things (IoT), new low cost and energy efficient devices, using different new communication technologies. LoRa is a new promising (Low Power Wide Area Network) LPWAN, that permits communication in distances up to a few kilometers to not require the complex deployment and maintenance of multi-hop technologies [1]. LoRa-based networks have been set up and deployed in different applications from indoor [2] and urban [3] environments, to maritime [4] and mountain scenarios [5].
Nowadays, a growing research has focused on IoT based-applications, such as smart cities and smart roads. One application that is currently being researched currently is traffic flow detection.
In this last case, several sensor and detection techniques with specific advantages and disadvantages are used. A frequent approach for vehicle detection and classification is camera-based systems, which achieve a high classification success rate. This technique often requires a number of cameras to analyze the scenario from different angles and perspectives. In contrast, Hsieh et al. in [6] present an enhanced visual system which is able to arrange vehicles into distinct vehicle classes using a single camera. Regardless of the lower number of cameras, the use of these devices requires an additional effort in terms of installation, maintenance and privacy-related problems in real-world scenarios. Moreover, the success rate of these systems significantly decreases when the weather conditions impede the visibility. In order to improve the successful detection rate mixed camera systems have been developed, there are approaches using laser scanners [7], acoustic sensors [8], magnetometers [9] or accelerometers [10]. The first three approaches present On the other hand, the network topology is important to ensure a robust and simple communication protocol. The package integrity in this application it is very important for detect any stopped vehicle on the highway as soon as possible and give the corresponding advice. In addition, the road section be covered could have a few hundred of meters. To ensure the coverage, the transmission range should be greater than a kilometer. In this way, technologies as ZigBee and BLE are not appropriate since their transmission range is around a few hundred of meters.
In [19] the authors present a review of long-range technologies for IoT and the Table  1 shown a resume of the main attributes for each technology. LTE is adequate for a high bandwidth and high data transmission ratio out of low power requirements. NB IoT, Sigfox and LoRa are LPWAN where these networks have a long-range data transmission also presents a low-power consumption. These protocols are suitable for the monitoring and signaling of highways.
NB-IoT can be deployed in different modes of operation. If deployed in guard band operation mode, it works in a frequency band similar to LTE, as indicated in Table 1. NB-IoT has a higher power consumption than LoRa.
Sigfox works well for simple devices and low data rate, as in this case. This protocol is not deployed everywhere, making it difficult to use. In addition, communication is better directed from the end point to the base station, and as it will be seen later in the work development, the application also requires communication between network nodes and the possibility of both uplink and downlink communication from the server or the gate- In [19] the authors present a review of long-range technologies for IoT and the Table 1 shown a resume of the main attributes for each technology. LTE is adequate for a high bandwidth and high data transmission ratio out of low power requirements. NB IoT, Sigfox and LoRa are LPWAN where these networks have a long-range data transmission also presents a low-power consumption. These protocols are suitable for the monitoring and signaling of highways.
NB-IoT can be deployed in different modes of operation. If deployed in guard band operation mode, it works in a frequency band similar to LTE, as indicated in Table 1. NB-IoT has a higher power consumption than LoRa.
Sigfox works well for simple devices and low data rate, as in this case. This protocol is not deployed everywhere, making it difficult to use. In addition, communication is better directed from the end point to the base station, and as it will be seen later in the work development, the application also requires communication between network nodes and the possibility of both uplink and downlink communication from the server or the gateway. Additionally, it has a small data rate and a short bandwidth.
LoRa allows you to configure and manage your own network, being a good option when bi-directionality is required because it has a symmetrical uplink and downlink connection. It also enables communication between nodes, although LoRaWAN does not contemplate it because LoRaWAN network topology is star. Lora allows an intermediate data transfer rate in comparison with the previous two. These characteristics make it appropriate for the application, so LoRa has been selected for the development of this work. LoRa device architecture consists of the high-performance microcontroller, it is a low-power ARM ® Cortex ® -M0 + based ATSAMD21G18 with 256 kB of flash, 32 KB of SRAM and operating frequency up to 48 MHz. It implements the LoRaWAN stack.
The long range transceiver is the module RFM95 with a frequency of 868 MHz. Its main features are its high sensitivity below −148 dBm combined with the +20 dBm integrated power amplifier. Its modulation modes are FSK, GFSK, MSK, GMSK, LoRaTM and OOK. The connection interface between the microcontroller and the transceiver is SPI (Serial Peripheral Interface). Finally, the whole system is finished with an omnidirectional antenna of 1dBi gain. In addition, the module incorporates a triaxial MEMS lis3dh accelerometer and a general-purpose input-output connector. Lastly, the Power Supply consisting of a TPS7A05 low quiescent current low drop regulator. Figure 2 shows the block diagram of the module.
nection. It also enables communication between nodes, although LoRaWAN does template it because LoRaWAN network topology is star. Lora allows an intermed transfer rate in comparison with the previous two. These characteristics make it a ate for the application, so LoRa has been selected for the development of this wo LoRa device architecture consists of the high-performance microcontrolle low-power ARM ® Cortex ® -M0 + based ATSAMD21G18 with 256 kB of flash, 3 SRAM and operating frequency up to 48 MHz. It implements the LoRaWAN sta The long range transceiver is the module RFM95 with a frequency of 868 main features are its high sensitivity below −148 dBm combined with the +20 d grated power amplifier. Its modulation modes are FSK, GFSK, MSK, GMSK, LoR OOK. The connection interface between the microcontroller and the transceiver is rial Peripheral Interface). Finally, the whole system is finished with an omnidi antenna of 1dBi gain. In addition, the module incorporates a triaxial MEMS lis3 erometer and a general-purpose input-output connector. Lastly, the Power Sup sisting of a TPS7A05 low quiescent current low drop regulator. Figure 2 shows t diagram of the module. Up to this point, the most appropriate network protocol has been selected monitoring and/or control of the intelligent signaling of a highway. For traffic d it is necessary that the network has to be able to transmit at smaller distances to correct detection through the signal transmission power. This is why a short ran less network is developed that is capable of coexisting with a LoRaWAN networ we will call Short LoRa. This network will be presented in the next subsection.

Short LoRa Network Topology
Several network topologies have been studied in Wireless Sensor Network The most promising topologies consist of a mesh where all devices are peer to there are no hierarchical relationships. This topology is very complex and prese maintenance requirements. In this way, the star topology shown in Figure 3 is v this application due to the large transmission range, it is the topology used for Lo protocol. Star topology has less versatility communication options but it has smal nance requirements, it is robust as it is not a multi-hop topology where the gat ceives the information from all End-Devices (ED) and control the network com tions. This fact gives a high robust technology. Up to this point, the most appropriate network protocol has been selected for the monitoring and/or control of the intelligent signaling of a highway. For traffic detection, it is necessary that the network has to be able to transmit at smaller distances to make a correct detection through the signal transmission power. This is why a short range wireless network is developed that is capable of coexisting with a LoRaWAN network, which we will call Short LoRa. This network will be presented in the next subsection.

Short LoRa Network Topology
Several network topologies have been studied in Wireless Sensor Networks (WSN). The most promising topologies consist of a mesh where all devices are peer to peer and there are no hierarchical relationships. This topology is very complex and presents high maintenance requirements. In this way, the star topology shown in Figure 3 is viable for this application due to the large transmission range, it is the topology used for LoRaWAN protocol. Star topology has less versatility communication options but it has small maintenance requirements, it is robust as it is not a multi-hop topology where the gateway receives the information from all End-Devices (ED) and control the network communications. This fact gives a high robust technology.
The network proposed here works under a LoRaWAN network like the one presented in Figure 4 and it is implemented so that both networks can work together.
The Short Lora subnet requires five nodes, four of them are used to detect vehicle traffic and a fifth that does the work of network coordinator, mainly responsible for sequencing and establishing the work cycles for the measurements.
Following the LoRaWAN standard implementation Short LoRa use the same star topology, where the coordinator node is the frame sender in mode multicast, and this node is responsible for network synchronization and the final collection of data for further processing. The rest of the nodes (#1, #2, #3, #4) are promiscuous mode interface network for packet sniffing so that they can also measurement RSSI with each other and be able to detect vehicles. In addition, ED nodes are defined as Class A in LoRaWAN network, that according to LoRa [20] allows for bi-directional communications. Short LoRa sub-network use a specific single channel to work, which makes it different from the channels used by LoRaWAN. The specific operation of the network for vehicle detection will be presented in Section 2.4. The network proposed here works under a LoRaWAN network like the one presented in Figure 4 and it is implemented so that both networks can work together.
The Short Lora subnet requires five nodes, four of them are used to detect vehicle traffic and a fifth that does the work of network coordinator, mainly responsible for sequencing and establishing the work cycles for the measurements. Following the LoRaWAN standard implementation Short LoRa use the same star topology, where the coordinator node is the frame sender in mode multicast, and this node is responsible for network synchronization and the final collection of data for further processing. The rest of the nodes (#1, #2, #3, #4) are promiscuous mode interface network for packet sniffing so that they can also measurement RSSI with each other and be able to detect vehicles. In addition, ED nodes are defined as Class A in LoRaWAN network, that according to LoRa [20] allows for bi-directional communications. Short LoRa sub-network   The network proposed here works under a LoRaWAN network like the one presented in Figure 4 and it is implemented so that both networks can work together.
The Short Lora subnet requires five nodes, four of them are used to detect vehicle traffic and a fifth that does the work of network coordinator, mainly responsible for sequencing and establishing the work cycles for the measurements. Following the LoRaWAN standard implementation Short LoRa use the same star topology, where the coordinator node is the frame sender in mode multicast, and this node is responsible for network synchronization and the final collection of data for further processing. The rest of the nodes (#1, #2, #3, #4) are promiscuous mode interface network for packet sniffing so that they can also measurement RSSI with each other and be able to detect vehicles. In addition, ED nodes are defined as Class A in LoRaWAN network, that according to LoRa [20] allows for bi-directional communications. Short LoRa sub-network The Figure 5 shows the LoRaWAN vs. Short Lora transmission intervals. It is observed that the idle periods of the LoRaWAN network are high, this fact is used to implement the Short LoRa network that will carry out the communications during these idle periods of LoRaWAN. To avoid data collisions, the subnet works on a different channel than LoRaWAN.
The transmission time diagram is shown in the Figure 6, in which we can see that the coordinating node of short Lora sends frame in multicast mode (a beacon signal) to synchronize the network and start the measurement, after which each of the nodes performs a multicast transmission to collect RSSI information from communication with the other nodes that are part of the subnet, sort LoRa.
in Section 2.4.
The Figure 5 shows the LoRaWAN vs. Short Lora transmission intervals. It is observed that the idle periods of the LoRaWAN network are high, this fact is used to implement the Short LoRa network that will carry out the communications during these idle periods of LoRaWAN. To avoid data collisions, the subnet works on a different channel than LoRaWAN. The transmission time diagram is shown in the Figure 6, in which we can see that the coordinating node of short Lora sends frame in multicast mode (a beacon signal) to synchronize the network and start the measurement, after which each of the nodes performs a multicast transmission to collect RSSI information from communication with the other nodes that are part of the subnet, sort LoRa.

Short Lora Network Protocol
The objective of the development of this application is the detection of stopped vehicles or slow traffic on Europe highways. The target region is important due to the restrictions presented by the regulations each one is subject to. In this case, it is regulated by EU Harmonized NRI for the 863-870 MHz band. The specific regulation for this kind of networks is given by the European Telecommunications Standards Institute (ETSI) ETSI EN 300 220-2 V3.2.1.33 [21].
On the other hand, it is necessary to establish a limit that we understand to determine a slow traffic speed. Assuming that 50 km/h (13.9 m/s) is slow traffic, and estimating the size of a vehicle of approximately 4 m. Based on these data, we can establish that the cycle time for the obstacle measurement with the radio frequency system exposed at the next point is 288 ms as seen in Equation (1).  The transmission time diagram is shown in the Figure 6, in which we can see that the coordinating node of short Lora sends frame in multicast mode (a beacon signal) to synchronize the network and start the measurement, after which each of the nodes performs a multicast transmission to collect RSSI information from communication with the other nodes that are part of the subnet, sort LoRa.

Short Lora Network Protocol
The objective of the development of this application is the detection of stopped vehicles or slow traffic on Europe highways. The target region is important due to the restrictions presented by the regulations each one is subject to. In this case, it is regulated by EU Harmonized NRI for the 863-870 MHz band. The specific regulation for this kind of networks is given by the European Telecommunications Standards Institute (ETSI) ETSI EN 300 220-2 V3.2.1.33 [21].
On the other hand, it is necessary to establish a limit that we understand to determine a slow traffic speed. Assuming that 50 km/h (13.9 m/s) is slow traffic, and estimating the size of a vehicle of approximately 4 m. Based on these data, we can establish that the cycle time for the obstacle measurement with the radio frequency system exposed at the next point is 288 ms as seen in Equation (1).

Short Lora Network Protocol
The objective of the development of this application is the detection of stopped vehicles or slow traffic on Europe highways. The target region is important due to the restrictions presented by the regulations each one is subject to. In this case, it is regulated by EU Harmonized NRI for the 863-870 MHz band. The specific regulation for this kind of networks is given by the European Telecommunications Standards Institute (ETSI) ETSI EN 300 220-2 V3.2.1.33 [21].
On the other hand, it is necessary to establish a limit that we understand to determine a slow traffic speed. Assuming that 50 km/h (13.9 m/s) is slow traffic, and estimating the size of a vehicle of approximately 4 m. Based on these data, we can establish that the cycle time for the obstacle measurement with the radio frequency system exposed at the next point is 288 ms as seen in Equation (1).
where: v is velocity, x is space and t is time.
Following the nodal distribution presented in [15] which has shown good results for other wireless communication technologies, but maintaining the LoRaWAN structure (for which 5 devices are required which will be justified later), it is necessary that each node transmit communicates every 50 ms.
On the other hand, the use of a standard LoRaWAN network has some work cycle and transmission power requirements that make it impossible to use this protocol in a standard way, as can be seen in Table 2. Parameters given in Table 2, determine the minimum network transmission period. The theoretical analysis starts defining the time on the air, T on-the-air (2), or packet transmission duration. This time determines in turn the minimum time that the network should remain without transmitting information.
T on-the-air = n preamble + n payload ·T symbol = n symbols ·T symbol (2) T on-the-air depends on the number of symbols transmitted, including those of the preamble and the payload, whose sum is the number of symbols transmitted; and from the time necessary to transmit each of these symbols (T symbol ). T symbol is obtained from the rate of sending of symbols (R Symbol ) which depends on the Spreading Factor (SF) and the signal bandwidth (BW).
With these equations, the time on the air and transmission periods are shown in Table 3 for 6 bytes and the different network parameters. As a result, the needs for traffic detection with a speed below 50 km/h, and considering the network limitations, in terms of the duty cycle and sampling period observed in Table 3, we can conclude that it is necessary to implement a subnetwork that can live with LoRaWAN. This subnetwork will work with 869.85 MHz, 125 kHz of modulation and SF7 5 mW (7 dBm) and a duty 100%, complying with the regulations indicated in ERC [21]. This network works out of LoRaWAN specifications but inside of ETSI EN 300 220-2 V3.2.133 regulation for Short Range Devices (SRD) [24].
In order to have disposable all channel time and not to affect the compatibility of the system with LoRaWAN, a subnetwork compatible has been implemented. To meet this requirement, the new network will base its implementation of the LoRaWAN protocol. Short LoRaWAN implementation vs. standard LoRaWAN are compared below. Figure 7 shown the standard LoRaWAN Radio PHY layer message structure in order to establish a comparison line with the protocol proposed in this paper. mW (7 dBm) and a duty 100%, complying with the regulations indicated in ERC [21]. Thi network works out of LoRaWAN specifications but inside of ETSI EN 300 220-2 V3.2.13 regulation for Short Range Devices (SRD) [24].
In order to have disposable all channel time and not to affect the compatibility of th system with LoRaWAN, a subnetwork compatible has been implemented. To meet thi requirement, the new network will base its implementation of the LoRaWAN protoco Short LoRaWAN implementation vs. standard LoRaWAN are compared below. Figure 7 shown the standard LoRaWAN Radio PHY layer message structure in orde to establish a comparison line with the protocol proposed in this paper. The LoRaWAN standard has a preamble value of 0 × 34, this parameter is used t establish a synchronized LoRaWAN network. The subnetwork proposed requires a di ferent preamble, it is 0 × 12. The following parameters, PHDR and PHDR are used in ex plicit mode, default configuration for LoRa devices, but are transparent to the user an not used by them. For this reason, PHDR and PHDR_CRC have been simplified in Shor LoRa, in the same way as MIC.
MHDR is made up of MType, RFU and Major. MHDR has been reduced only to simplified MType, since the proposed network does not perform a negotiated networ The LoRaWAN standard has a preamble value of 0 × 34, this parameter is used to establish a synchronized LoRaWAN network. The subnetwork proposed requires a different preamble, it is 0 × 12. The following parameters, PHDR and PHDR are used in explicit mode, default configuration for LoRa devices, but are transparent to the user and not used by them. For this reason, PHDR and PHDR_CRC have been simplified in Short LoRa, in the same way as MIC.
MHDR is made up of MType, RFU and Major. MHDR has been reduced only to a simplified MType, since the proposed network does not perform a negotiated network join or require an access code. The Table 4 shows differences between Standard LoRa MType and Short LoRa MType.
The next LoRaWAN parameter, FHDR, is composed by 4 bytes of device address, 1 byte of Frame Control, 2 bytes of Frame Counter and up to 15 bytes of frame options. In Short LoRa, these requirements have been reduced, FHDR is composed for 4 bits address (16 nodes), 2 bits for control (FCrtl) and 4 bits for count the payload length (FCnt). The 2 bits of control (FCtrl) are: the first one is the acknowledge (ACK) and the second is Reserved for Future Usage (RFU). In addition, Frame Options (FOpt) have been removed in order to simplify the network protocol. The ADR and ADRACKReq fields within FCtrl are suppressed respect to the LoRaWAN standard because this subnet works by setting the data rate and transmission power.
The FOptsLen field within FCtrl and FOpts is suppressed because MAC commands can be sent in the FRMPayload field if the FPort field is set to 0.
Lastly, the payload frame (FRMPayload) contained the data collection that could be sent through the network, that could have up to 14 bytes. In this way using the encryption given by Advanced Encryption Standard (AES), we match the data packet sent to the minimum packet encoded by AES 128 bits. They must always be encrypted and must not exceed the maximum length of FRMPayload.
The Figure 8 shows graphically the Radio PHY layer message structure proposed for Short LoRa.
The network nodes have been developed to work in Class A in order to they can be used for a standard LoRaWAN network when it is required by the application and the rest of the time you can work in the proposed low consumption network.
Under the proposed configuration, 869.85 MHz, 125 kHz of modulation and SF7, the different times in the air of the transmitted information have been calculated and it is shown in Table 5.
Although 50 km/h may seem like a low speed for detecting traffic on a highway, but this limit is justified below.
European ETSI regulation establishes a single channel to work on FSK within the LoRaWAN specification. It is true that working in FSK would allow the detection and measurement of higher circulation speeds corresponding to the Data Rate 7 (DR7) of the LoRa FSK specification with 50 kbit/s [22] compared to 11 kbit/s in LoRa SF7 (DR6) in the EU 863-870 MHz ISM Band. This limitation found for LoRa in speed measurement improves regulation in other countries such as the United States where using DR13 and SF7 the data rate is 21.9 kbit/s in US 902-928 MHz ISM Band.
Furthermore, analyzing the information presented in [25] where the LoRa communication is compared with the FSK communication, it can be deduced that as the bit rate increases, the LoRa sensitivity decreases, approaching the FSK sensitivity. Although, in this same document, we note that immunity against noise produced by other radio frequency signals is better in LoRa than in FSK. This is an important factor since it is intended to detect communication disturbances caused by obstacles in the direct line of sight and not by other RF signals.
On the other hand, in the datasheet of the RF transceiver used [26] explains the difference in the way of calculating the RSSI in both LoRa and FSK. In LoRa we have access to an average RSSI value of the sent packet while in FSK the RSSI value is smoothed on a user defined number of measured RSSI samples, the greater the number of samples, the greater the precision but the greater the delay in the measurement. This feature of LoRa is interesting since it allows us to work independently for each data packet, improving the robustness in the detection of obstacles. Sensors 2021, 21, x FOR PEER REVIEW 10 of 26 . The network nodes have been developed to work in Class A in order to they can be used for a standard LoRaWAN network when it is required by the application and the rest of the time you can work in the proposed low consumption network.
Under the proposed configuration, 869.85 MHz, 125 kHz of modulation and SF7, the different times in the air of the transmitted information have been calculated and it is shown in Table 5. Although 50 km/h may seem like a low speed for detecting traffic on a highway, but this limit is justified below.
European ETSI regulation establishes a single channel to work on FSK within the LoRaWAN specification. It is true that working in FSK would allow the detection and measurement of higher circulation speeds corresponding to the Data Rate 7 (DR7) of the LoRa FSK specification with 50 kbit/s [22] compared to 11 kbit/s in LoRa SF7 (DR6) in the EU 863-870 MHz ISM Band. This limitation found for LoRa in speed measurement improves regulation in other countries such as the United States where using DR13 and SF7 the data rate is 21.9 kbit/s in US 902-928 MHz ISM Band.  Lastly, 50 km/h or lower speed on a high-speed traffic lane is considered a particularly risky situation. For this reason and given the results of the theoretical analysis carried out on the subnet protocol, where it is shown that the temporal conditions to detect vehicles at speeds of 50 km/h or less are given, and that therefore the proposed network is suitable for the application objective.

Short Lora Network for Traffic Flow Detection
The vehicle detection is based on the transmission losses or attenuation on communication transmissions. LoRa, and Short Lora send the Radio Signal Strength Indicator (RSSI) in each transmission. Therefore, it is assumed that the value of this signal will decrease when there is an obstacle in the direct transmission line or Line Of Sight (LOS).
Starting from the topology and the network protocol presented in Sections 2.2 and 2.3, the operation of the vehicle detection system is developed, being the following: 1.
The coordinator node sends a multicast synchronous service frame each 250 ms because the data transmission package is 6 bytes with a time on air of 36.10 ms, then a time slot of 50 ms is given to each node for its own communication avoiding collisions in this process. The system has a cycle frequency of 4 Hz. The beacon is the signal indicator to start the vehicle detection process.

2.
When EDs receive the multicast synchronous service frame signal, the Node #1 time slot of 50 ms is opened. Node #1 sends a broadcast of 2 bytes and saves the RSSI given by the node coordinator, Node #2, Node #3 and Node #4. Afterwards, to save all the RSSI information, it is sent to the network coordinator in order to be processed when the detection cycle finished. 3.
Next, Node #2 transmits in their time slot. First, it sends a multicast synchronous service frame, and after save the RSSI information and sends it to the coordinator node. This process is repeated for all End-Devices.
Finally, the information is collected by the LoRaWAN Gateway node, which works as the Short Lora coordinator in the interval that LoRaWAN is not transmitting. The collected information is processed on a personal computer. Processing techniques will be presented in the next section.

Testbed
Different tests have been carried out in order to verify and validate the operation of the proposed system. The diagrams in the Figure 10 shows the configurations and the arrangement of the different elements of the vehicle circulation detection system on the road.
The tests represented in Figures 10a-d

Testbed
Different tests have been carried out in order to verify and validate the operation of the proposed system. The diagrams in the Figure 10 shows the configurations and the arrangement of the different elements of the vehicle circulation detection system on the road.
The tests represented in Figure 10a-d have been carried out in both directions of circulation since they are situations that can occur in roads in both directions.
All test have been carried out for several velocities: 10, 20, 30, 40 and 50 km/h and for two distances between the nodes that are in the same lane 10 and 20 m (Parameter V and L, respectively, in Figure 10).
In addition to these parameters and the tests carried out, it is necessary to explain the physical arrangement of the system and the nomenclature used in the description of the analysis. Both the communication and the spatial relationship between nodes #1-#2 (Gate 1) and #3-#4 (Gate 2), will be called gates, because these pairs of nodes are the "gates" through which the vehicle accesses the detection system. Similarly, the relations of both communication and spatial level of the connections of nodes #1-#4 (Crosses 1) and #2-#3 (Crosses 2) will be called "crosses" since they determine the X-shaped junction of the communication. Two more wireless connections are evaluated, nodes #1-#3 and #2-#4, these will be used later to determine miscellaneous communication losses, to determine the detection of the passage of vehicles in the controlled zone. arrangement of the different elements of the vehicle circulation detection system on the road.
The tests represented in Figures 10a-d have been carried out in both directions of circulation since they are situations that can occur in roads in both directions.
All test have been carried out for several velocities: 10, 20, 30, 40 and 50 km/h and for two distances between the nodes that are in the same lane 10 and 20 m (Parameter V and L, respectively, in Figure 10). In addition to these parameters and the tests carried out, it is necessary to explain the physical arrangement of the system and the nomenclature used in the description of the analysis. Both the communication and the spatial relationship between nodes #1-#2 (Gate 1) and #3-#4 (Gate 2), will be called gates, because these pairs of nodes are the "gates" through which the vehicle accesses the detection system. Similarly, the relations of both communication and spatial level of the connections of nodes #1-#4 (Crosses 1) and #2-#3 (Crosses 2) will be called "crosses" since they determine the X-shaped junction of the communication. Two more wireless connections are evaluated, nodes #1-#3 and #2-#4, these will be used later to determine miscellaneous communication losses, to determine the detection of the passage of vehicles in the controlled zone.
The picture in Figure 11a shows the actual deployment made to carry out the implementation verification; while Figure 11b shows the detail of one of the deployed nodes. In it you can see that the electronics are inside a tube that is typically used in civil works on highways.
It should be noted that the communication links between the nodes that make up the gates include a laser-type optical path detector. This laser sensor allows us to compare the data that it provides us with the information extracted from power losses communication between nodes that form the pairs of each of the gates, to validate with greater precision the passage of a vehicle. The picture in Figure 11a shows the actual deployment made to carry out the implementation verification; while Figure 11b shows the detail of one of the deployed nodes. In it you can see that the electronics are inside a tube that is typically used in civil works on highways.
It should be noted that the communication links between the nodes that make up the gates include a laser-type optical path detector. This laser sensor allows us to compare the data that it provides us with the information extracted from power losses communication between nodes that form the pairs of each of the gates, to validate with greater precision the passage of a vehicle.
Another important point is the height at which sensor nodes have been placed. This should be above the height of the guardrail, typically 75 cm. To be able to adjust both the height to this requirement, and the alignment of the installed laser sensors to verify the passage of vehicles through the entrance gates to the LoRa detection system, topographic tripods have been used, as can be seen in Figure 6.
With this test setup, the data is acquired for subsequent analysis which is presented in the following section. To passes have been made for each of the speeds previously described in each of the configurations presented in Figure 10, at distances of 10 and 20 m between the gates, in order to have sufficient system information that allows checking viability of proposed system. Another important point is the height at which sensor nodes have been placed. This should be above the height of the guardrail, typically 75 cm. To be able to adjust both the height to this requirement, and the alignment of the installed laser sensors to verify the passage of vehicles through the entrance gates to the LoRa detection system, topographic tripods have been used, as can be seen in Figure 6.
With this test setup, the data is acquired for subsequent analysis which is presented in the following section. To passes have been made for each of the speeds previously described in each of the configurations presented in Figure 10, at distances of 10 and 20 m between the gates, in order to have sufficient system information that allows checking viability of proposed system.

Power Consumption Analysis
The measurement of the consumption of the network nodes shown in Figure 12, has been carried out with the devices working as described in Section 2.2 There are three different states. The Standby state, which we can define as the base current level with the MCU active and the LoRa modem in standby. The TX state, which corresponds to the

Power Consumption Analysis
The measurement of the consumption of the network nodes shown in Figure 12, has been carried out with the devices working as described in Section 2.2 There are three different states. The Standby state, which we can define as the base current level with the MCU active and the LoRa modem in standby. The TX state, which corresponds to the consumption when transmitting whose difference value, is 53 mA at a power of 7 dB. Lastly, the Rx state that corresponds to the LoRa modem in receive mode with differential value is 10.2 mA.
The total average consumption of the entire cycle is 26.8 mA. It should be noted that this application works a duty of almost 100%. Furthermore, the transmission consumption is higher since the RFM95W module uses the RF output PA_BOOST and the consumption at this power is not optimized. consumption when transmitting whose difference value, is 53 mA at a power of 7 dB. Lastly, the Rx state that corresponds to the LoRa modem in receive mode with differential value is 10.2 mA.
The total average consumption of the entire cycle is 26.8 mA. It should be noted that this application works a duty of almost 100%. Furthermore, the transmission consumption is higher since the RFM95W module uses the RF output PA_BOOST and the consumption at this power is not optimized. Generally, the consumption of a bright traffic sign with small LED diodes has a consumption of 5 W, while the application proposed here with 3.3 V of supply voltage and an approximate average consumption of 29 mA, give a lower power consumption at 0.1 W. This average consumption and the measured values presented in the graph of Figure  12 are within the ranges presented in [27]. We can conclude that the energy consumption that the proposed application adds to a luminous traffic sign does not significantly increase its consumption. Currently, the bottleneck in terms of consumption for luminous traffic signs is in the LED diodes.

Data Analysis and Results
Two methods of analysis have been proposed. The first of these is based on the detection of the derivative of signal loss, RSSI, when a vehicle passes. This method is relatively simple, but a priori it appears to be a fairly viable detection system.
The second method is more elaborate. It uses the loss of the RSSI value and the communication losses produced in what we will call free links, since there are not obstructions due to the movement of vehicles, to establish a base level on which to detect variations in transmission power. Free links correspond to communications between nodes #1-#2 and #3-#4.
The operation of both methods is detailed below in their corresponding subsections.

Derivative Data Analysis Method for Vehicule Detection
This method takes the RSSI data of the communications between the gates to the detection zone, Gate 1 formed by nodes #1-#2, and Gate 2 by nodes #3-#4. In addition, the differences in crosses will also be detected, that is, between the communications of nodes #1-#4 and #3-#2.
The acquisition of RSSI information is carried out as described in Section 2.3. As it is represented in Figures 3 and 4, the communication and sending of the RSSI is bidirectional between each pair of nodes, this is shown in the Simulink analysis system diagram shown in Figure 13. Generally, the consumption of a bright traffic sign with small LED diodes has a consumption of 5 W, while the application proposed here with 3.3 V of supply voltage and an approximate average consumption of 29 mA, give a lower power consumption at 0.1 W. This average consumption and the measured values presented in the graph of Figure 12 are within the ranges presented in [27]. We can conclude that the energy consumption that the proposed application adds to a luminous traffic sign does not significantly increase its consumption. Currently, the bottleneck in terms of consumption for luminous traffic signs is in the LED diodes.

Data Analysis and Results
Two methods of analysis have been proposed. The first of these is based on the detection of the derivative of signal loss, RSSI, when a vehicle passes. This method is relatively simple, but a priori it appears to be a fairly viable detection system.
The second method is more elaborate. It uses the loss of the RSSI value and the communication losses produced in what we will call free links, since there are not obstructions due to the movement of vehicles, to establish a base level on which to detect variations in transmission power. Free links correspond to communications between nodes #1-#2 and #3-#4.
The operation of both methods is detailed below in their corresponding subsections.

Derivative Data Analysis Method for Vehicule Detection
This method takes the RSSI data of the communications between the gates to the detection zone, Gate 1 formed by nodes #1-#2, and Gate 2 by nodes #3-#4. In addition, the differences in crosses will also be detected, that is, between the communications of nodes #1-#4 and #3-#2.
The acquisition of RSSI information is carried out as described in Section 2.3. As it is represented in Figures 3 and 4, the communication and sending of the RSSI is bidirectional between each pair of nodes, this is shown in the Simulink analysis system diagram shown in Figure 13.
Using the transmission power measurement bi-directionally allows both RSSI data to be used, as seen in the figure above for each pair of nodes, making the possibility of detection more robust. Figure 13 shows how the RSSI data of all bidirectional communications between pairs of nodes is processed and its discrete derivative is calculated. The value obtained from the derivative is entered in a comparator that when the derivative reaches a value of −5 dB, activates its output, giving it a '1', otherwise the output is '0' otherwise; Thus obtaining a digital encoding that with the '1' indicates the presence of an obstacle in the transmission line and a '0' when there is none.
The comparison value of -5 dB is established based on the collected experimental data, this being sufficient to detect the passage of vehicles without possible disturbances due to any noise or unwanted disturbance that modifies the RSSI value. Sensors 2021, 21, x FOR PEER REVIEW 16 of 26 Figure 13. Simulink diagram for derivative data analysis method.
Using the transmission power measurement bi-directionally allows both RSSI data to be used, as seen in the figure above for each pair of nodes, making the possibility of detection more robust. Figure 13 shows how the RSSI data of all bidirectional communications between pairs of nodes is processed and its discrete derivative is calculated. The value obtained from the derivative is entered in a comparator that when the derivative reaches a value of −5 dB, activates its output, giving it a '1′, otherwise the output is '0′ otherwise; Thus obtaining a digital encoding that with the '1′ indicates the presence of an obstacle in the transmission line and a '0′ when there is none.
The comparison value of -5 dB is established based on the collected experimental data, this being sufficient to detect the passage of vehicles without possible disturbances due to any noise or unwanted disturbance that modifies the RSSI value.
The results of the discrete derivatives of the pair-correlated transmissions of both the gates and the crosses in each direction are operated using the operation AND of Boolean logic, therefore, the passage of vehicles will only be detected if both results are '1′, that is, if the power losses in transmission are produced in both signals. This avoids errors in detection due to the power loss in only one of the signals produced by possible anomalous behaviors.
The results achieved are presented in Section 3.3, where they will also be compared with the other method of analysis proposed.

Link Budget Compensated Data Analysis Method for Vehicule Detection
This method is based on the detection of the difference of the communication signal of gates and crosses with a base level and reference level of bias. The method works as described below.
First, at the top of Figure 14, we can see the first two subsystems. These from the RSSI values and the theoretical losses obtained for communications between the free links or obstacle-free nodes #1-#3 and #2-#4, allow obtaining the existing losses due to other pa- The results of the discrete derivatives of the pair-correlated transmissions of both the gates and the crosses in each direction are operated using the operation AND of Boolean logic, therefore, the passage of vehicles will only be detected if both results are '1 , that is, if the power losses in transmission are produced in both signals. This avoids errors in detection due to the power loss in only one of the signals produced by possible anomalous behaviors.
The results achieved are presented in Section 3.3, where they will also be compared with the other method of analysis proposed.

Link Budget Compensated Data Analysis Method for Vehicule Detection
This method is based on the detection of the difference of the communication signal of gates and crosses with a base level and reference level of bias. The method works as described below.
First, at the top of Figure 14, we can see the first two subsystems. These from the RSSI values and the theoretical losses obtained for communications between the free links or obstacle-free nodes #1-#3 and #2-#4, allow obtaining the existing losses due to other parameters that may intervene in communication and they are not controlled. This information will be used to compensate for these losses in communications at gates and crosses and to have an adequate base level or bias level.
For the theoretical calculation of communication losses, both the initial transmission power level and the elements that contribute gain to communication, such as antennas, and those that produce losses, such as cables and connectors, are taken into account. Free space losses have also been taken into account and are related to the distance that separates emitter and receiver as seen in Equation (5).
where L FS is path loss, usually free space loss (dB), λ is the signal wavelength and d is the distance between the antennas in the same units as wavelength. rameters that may intervene in communication and they are not controlled. This information will be used to compensate for these losses in communications at gates and crosses and to have an adequate base level or bias level. For the theoretical calculation of communication losses, both the initial transmission power level and the elements that contribute gain to communication, such as antennas, and those that produce losses, such as cables and connectors, are taken into account. Free space losses have also been taken into account and are related to the distance that separates emitter and receiver as seen in Equation (5).
where is path loss, usually free space loss (dB), is the signal wavelength and is the distance between the antennas in the same units as wavelength.
This value of the power losses in the communication that we will call miscellaneous losses as seen in Equation (6), due to the possibility that they are produced by elements of unknown nature, is calculated in both directions of the same, that is, in the communication from node #1 to #3 and from #3 to #1, to later average it. The same is done for the communication of nodes #2 and #4.
where: is miscellaneous losses (dB), is transmitter output power (dBm), is transmitter antenna gain (dBi), is transmitter losses (dB), is path loss, usually free space loss (dB), is receiver antenna gain (dBi), is receiver losses (coax,connectors...) (dB) and is received power RSSI (dBm). Figure 15 shows the rest of the detection algorithm. In it we can see how the miscellaneous loss data calculated using the blocks in Figure 14 is entered into a new block. In This value of the power losses in the communication that we will call miscellaneous losses as seen in Equation (6), due to the possibility that they are produced by elements of unknown nature, is calculated in both directions of the same, that is, in the communication from node #1 to #3 and from #3 to #1, to later average it. The same is done for the communication of nodes #2 and #4.
where: L M is miscellaneous losses (dB), P Tx is transmitter output power (dBm), G TX is transmitter antenna gain (dBi), L TX is transmitter losses (dB), L FS is path loss, usually free space loss (dB), G RX is receiver antenna gain (dBi), L RX is receiver losses (coax,connectors...) (dB) and P RX is received power RSSI (dBm). Figure 15 shows the rest of the detection algorithm. In it we can see how the miscellaneous loss data calculated using the blocks in Figure 14 is entered into a new block. In this calculation block, the theoretical calculation of communication losses between gates or between crosses is obtained, taking into account the free space losses for the separation distance of these communications or these nodes. Miscellaneous losses are added to this calculation, which are assumed to be the same for all communications in the system, since they are within the same environment. With this, a base band or bias level is established on which to compare fluctuations in the reception power.
where: P RX is received power RSSI (dBm), P Tx is transmitter output power (dBm), G TX is transmitter antenna gain (dBi), L TX is transmitter losses (dB), L FS is path loss, usually free space loss (dB), L M is miscellaneous losses (dB), G RX is receiver antenna gain (dBi) and L RX is receiver losses (coax, connectors...) (dB).   Finally, this bias reception power (P RX ) is subtracted from the RSSI values received at each of the bidirectional gates and crosses reception values, as appropriate. With this compensated base level the new base level is around zero, two limits are set, one upper and one lower. The chosen limit values have been obtained experimentally for each communication pair. When one of the signals crosses the lower limit it produces a logical '1 . In this method, unlike the previous one, the output value of the comparison is passed through an OR logic gate so that when one of the two RSSI signals produces a positive, it is detected. If this detection exceeds the maximum time established based on the length of the vehicle and the minimum speed, we face slow or stopped traffic.
This detection is carried out at each of the gates and crosses. The results will be explained in the next subsection. Figure 16 shows the results of the vehicle detection algorithms. For the comparison and analysis of the results, the data obtained by means of the two laser barriers located between the links of the gates are taken as a reference. The response time of these laser barriers has a high accuracy, providing an adequate reference for system validation.

Results
the vehicle runs at 30 km/h and the distance between gates is 20 m. In the test, the car enters the detection zone twice, the first of which enters through the gate that we will now call Gate 2, formed by nodes #3 and #4, and exits through what we will call Gate 1, corresponding to nodes #1 and #2.
In the figure we can see several things, the first of which are laser barriers that provide an answer first, consistent with its use as a reference system. Next, we observe that the link budget compensated method has a faster and equal detection on both gates; while the method based on the discrete derivative responds somewhat later and with signals of non-uniform width.
Despite the differences shown, the two data processing methods are equally valid for detecting the passage of vehicles. The lower graph of Figure 16 shows the attenuations produced in the RSSI value with the passage of vehicles with respect to an attenuation level of 0dBs. The attenuations of the transmissions of both gates and of the bidirectional communication of the pairs of nodes that form each of them are presented separately. The graph refers to these signals as Gate 1 Link 1, this being the communication from node #1 to #2; Gate 1 Link 2 from #2 to #1; Gate 2 Link 1 from #3 to #4 and Gate 2 Link 2 from #4 to #3, thus representing all the detection signals present between the gates communications.
The RSSI data for this analysis is collected in Table 6, both at gate and crosslinks. Studying what this attenuation looks like shows that the gate signs are more attenuated than the crossing signals. This reduction in attenuation is due to the fact that in the crossings there are more deflations, more rebounds and; therefore, less attenuation and less sensitivity. The case presented in Figure 16 corresponds to one of the tests carried out in which the vehicle runs at 30 km/h and the distance between gates is 20 m. In the test, the car enters the detection zone twice, the first of which enters through the gate that we will now call Gate 2, formed by nodes #3 and #4, and exits through what we will call Gate 1, corresponding to nodes #1 and #2.
In the figure we can see several things, the first of which are laser barriers that provide an answer first, consistent with its use as a reference system. Next, we observe that the link budget compensated method has a faster and equal detection on both gates; while the method based on the discrete derivative responds somewhat later and with signals of non-uniform width.
Despite the differences shown, the two data processing methods are equally valid for detecting the passage of vehicles.
The lower graph of Figure 16 shows the attenuations produced in the RSSI value with the passage of vehicles with respect to an attenuation level of 0dBs. The attenuations of the transmissions of both gates and of the bidirectional communication of the pairs of nodes that form each of them are presented separately. The graph refers to these signals as Gate 1 Link 1, this being the communication from node #1 to #2; Gate 1 Link 2 from #2 to #1; Gate 2 Link 1 from #3 to #4 and Gate 2 Link 2 from #4 to #3, thus representing all the detection signals present between the gates communications.
The RSSI data for this analysis is collected in Table 6, both at gate and crosslinks. Studying what this attenuation looks like shows that the gate signs are more attenuated than the crossing signals. This reduction in attenuation is due to the fact that in the crossings there are more deflations, more rebounds and; therefore, less attenuation and less sensitivity. On the other hand, the average gate attenuation is at least 15 dB, and this RSSI attenuation value occurs in both directions of communication. These two characteristics make the system very robust.
Crossings can be used to sense the direction of the vehicle or to make the gate detection algorithm more robust. Although the detection system works satisfactorily using only the gate signals.
Based on the RSSI information processed and the corresponding digital signal obtained for each data analysis method, together with the reference laser system, the time it takes for a vehicle to pass from one gate to the next has been measured. From the information shown in Figure 16 the pulse instants are obtained for the calculation of the time difference. Since the distance between the gates is known, which is fixed for each case study (10 and 20 m), and the time it takes for the vehicle to travel that gap is measured, the speed of the car can be calculated. Table 7 shows these results. In the table, when the vehicle enters through Gate 1 and exits through Gate 2, it is considered positive. The opposite direction is considered negative (Gate 2 to Gate 1).
From the information presented, both for 10 and 20 m of gate distances, it is observed that for low speeds of 10 to 30 km/h the measurement through the wireless network is quite accurate and its response time is quite fast compared to the reference measurement obtained using the laser barriers. The accuracy decreases as the speed increases and this is due to the sampling time with which the network works. This aspect can be improved, but it would be necessary to enter an operating mode outside the ETSI EN 300 220-2 standard. The other option is to work in FSK mode that conflicts with the working modes of LoRaWAN gateways, compromising compatibility between LoRaWAN and Short LoRa. With the data shown in Table 7, the absolute and relative errors in the measurement were calculated for both methods, always taking as a reference the measurement obtained from the laser barriers. The error values are shown in Table 8.
In general, it can be seen that the error increases with speed and is greater when the distance between gates is 10 m, since the time it takes for the vehicle to cross both tares is less than in the case of 20 m. As already mentioned, this is produced by the sampling time. It can also be seen that the error in the derivative method is generally less than in the link budget compensated method.

Dicussion
We can find in the literature different communication protocols for the Intelligent Transport System (ITS). Two of these protocols, perhaps the most relevant in this area are: 6LoWPAN and IEEE 802.11p. In [28,29] the authors talk about the use of the 6LoWPAN and IEEE 802.11p protocols, respectively, in ITS applications.
Both protocols have greater potential for these applications, as they allow Vehicle-to-Vehicle (V2V), Vehicle-to-Infrastructure (V2I) communication, as well as global communication via the Internet of Things (IoT). On the other hand, these protocols require a greater infrastructure and that the vehicles have a compatible communication system.
The implementation of this type of system is much more complex and at present in the target country of the project, it is not feasible to develop a communication network of this type, involving both the road communication/monitoring infrastructure and the vehicles that circulate through it. The objective of the proposed work is much more modest, in this sense, and aims to monitor the condition and climate of a highway, leaving aside the information from the vehicles. The main objective is to be able to detect an accident or a situation of collapse on a motorway, with extreme importance in circumstances in which weather conditions can hinder visibility during traffic on the road, increasing the risk of an accident. This is without the need for vehicles to carry a communication system compatible with that installed on the road, that is, it is a system solely intended to monitor the condition and environment of the road that uses the communication signal itself to detect circumstances in which may be a vehicle stopped or moving slowly on the road. This work presents a traffic detection system based on a LoRa network that works with a communication frequency of 868 MHz. We can find in the literature other works of a similar nature that use WiFi communication technologies, IEEE 802.11b [14,15], IEEE 802.11n [13] or Low Power Wireless Sensor Networks (LPWN) as IEEE 802.15.4 [16] with communication frequencies in the 2.4 GHz band. Both communication frequencies are within the Industrial, Scientific and Medical (ISM) bands.
These works are oriented for application in cities, places where 2.4 GHz wireless networks are abundant and whose infrastructure can be exploited. The results presented by the cited authors are promising. The problem with this frequency is its short range, such networks are no longer available on a highway, and due to their short range they present certain problems.
In this work, the design of a network system based on LoRa with a communication frequency of 868 MHz is proposed, this allows communication over long distances, although in the work a short-range subnet based on LoRa is proposed, its capacity coexisting and working with LoRaWAN means that these small subnets can be distributed and controlled by a single LoRa Gateway.
Regarding the algorithms in the treatment of the data, they use Support Vector Machines (SVM) [14][15][16] and machine learning algorithms such as k-Nearest Neighbors (k-NN) [13]. These algorithms for data analysis allow them to classify the type of vehicle is going. The algorithms proposed in the article are simpler but just as effective in detecting the passage of vehicles. Table 9 shown a comparative summary of different communication protocols discussed in this subsection.