## 4 Remote Base Unit
### Software of the Base Terminal Unit  
The same as for the RTUs, the BTU's software is programmed in C language and the C compiler from CCS is used. The embedded software performs data acquisition and communication with the RF module and with the HTTP server. The main routine configures the network parameters: IP Address, Subnet Mask and Gateway in order to establish communication from the HTTP server to the satellite modem. Then, the program waits for a query from the Central Server in form of an http request to retrieve an HTML page. Within the web page, the special formatting character \"%\" is found. When an http task is serving a webpage and finds a \"%\" it calls a function with the ID variable set to the formatting character. For example in the html code of the webpage programmed in the PIC18F6722 it can be found: _<h4>Temperature: <!- - ->%7_ \(\,\)\(\,\)\(\,\)\(\,\)\(\,\)\(\,\)\(\,\)\(\,\)\(\,\)\(\  
Remote Data Acquisition involves two main parts: the client (represented by the BTU's HTTP embedded server) and the CS, which manages the meteorological data from the remote stations and provides information to the database for further analysis and to be displayed in real-time on the web portal.  
In the central server a program in PHP language which requests the meteorological data to the base terminal units every ten minutes is stored. To achieve this, an infinite-loop routine monitors every second the time of the CS by using the conditioning sentence that is expressed as follows:  
\[\text{(min \% delay}==0)\ \&\ \text{(sec}==0)\]  
In the above line of code, \"min\" represents the minutes value from the clock of the system, the variable \"delay\" is previously set by the user and defines the sampling period in minutes (10 by default) and \"sec\" is the variable which contains the seconds value from the clock of the system. If this condition is not true, the system continues updating the variables \"min\" and \"sec\". Otherwise if the  
Figure 10: Flow diagram for the main routine in the remote base unit.  
condition in the above flow diagram is true, the program executes the acquisition routine, which performs previous corroborations before attempting to connect to the RTUs.  
1. Consults the state of the flag \"enabled\" to know if the remote station must be consulted (for example, remote stations can be disabled in case of maintenance). On the other hand, in case that the state of the flag is false, the label \"NEBLE\" will be added in all the fields of the corresponding database in the central server.
2. If the state of the flag is true, then the status of the Internet connection is checked by using a \"ping\" command to the IP address 66.102.7.99 (Google server). In other words with a ping command expects an eco response and if it is bigger than zero, the main program will try to establish connection with the RTU. Otherwise in all the fields of the corresponding RTU will be added the label \"NNET\". This means that the Internet connection has been lost.
3. An information request is sent to the BTU by using the \"get\" method, which tracks keywords or symbols along the embedded webpage in the BTU. For example to read the relative humidity in a base terminal unit, the \"get\" command \"sweeps\" the webpage content and looks for the words \"Relative\" plus \"blank space\" plus \"Humidity\". After that, the number that follows the keywords is read. The flow diagram of the requests generated by the CS is shown in Figure 11.