## 4 Software Implementation  
The framework for implementing the neural network application using microcontrollers is based on an Analog Devices wireless sensor network (WSN) for the Internet of Things (IoT), a flexible and modular solution used as a development platform. The hardware includes a base station node and several sensor nodes that support different sensors (the sensors can be connected in any combination). To implement the proposed framework, we use a WSN module [15; 23; 24; 25] (EV-ADRN-WSN1Z_BUNCH) in each vehicle and the base node (EVAL-ADuCRF101 MK) as the application server. The nodes run a firmware provided by Analog Devices (AD6 LoWPAN01 [15; 23]--that is based on the Contiki OS) [26] as follows: the base node is configured as a border router to ensure communication between WSN nodes and a data server in another IP network, responsible for IPv6 Prefix propagation within the LoWPAN, and the WSN nodes are configured as sensor nodes (read traffic data and communicate with router). The original code provided with the evaluation platform in AD6 LoWPAN01 [27] was modified to implement the proposed framework for neural network traffic forecasting applications. The modified software has the flowcharts displayed in Figures 6-8. The algorithm was implemented using Contiki operating system primitives. The parameters of the neural network were initialized with parameters obtained in the training phase and the core of the Contiki operating system was initialized, which defines the processes of reading the sensors and updating the values from the input and processing  
Figure 6: The overall framework flowchart (adapted from [23]). graphs (implementation of the neural network). Both processes are executed when an event occurs: the expiration of a timer for the reading process and the filling of a buffer for the processing process. The timer associated with the reading process expires at the sampling rate of the sensors, and the buffer has a given length chosen in such a way that the processing is performed in real time. The execution of the two processes is cyclical. In Figure 6, one can observe the main software modules of the proposed flowchart: hardware and software initialization, sensors initialization, and the two newly defined modules (implemented as protothreads), namely read process and computation process. The read process acquires traffic data sensors in a buffer at a configurable observation rate (in this paper, the observation rate is between 1 Hz and 10 Hz) and when the data buffer is full, it starts the computation process, as is illustrated in Figure 7.  
The computation process waits for a message from the read process and then tests the neural network with the parameters and weights previously configured in the developing phase and makes a prediction. The flowchart of the computation process is shown in Figure 8.  
Figure 8: The computation process flowchart (adapted from [23]). Figure 7: The read process flowchart (adapted from [23]). The read process and computation process are run cyclically at a rate given by the filling of the data buffer. The solution presented above involves the switching buffer technique [28]: two pairs of input and output buffers are switched to obtain a real time implementation (that is, without loss of input observations). Using an input buffer, it permits us to take a decision based on a large interval of time, not after a single observation. In this way, the decision accuracy is improved (for example, the decision may be taken considering the class that has a majority in the given interval of time). The sampling period may vary between tens of milliseconds and several seconds, and the input buffer maximum length may be chosen up to 100. In our evaluation, a sampling period of 1 s was chosen.