Building a Remote Data Logger
7.1 Chapter Description
This chapter presents a comprehensive example intended to provide some insight into writing powerful networked applications that take full advantage of big networking capabilities provided by this little computer. TINI will be put to work as a network status reporting device. We'll create a complete example that captures and logs data and implements a TCP/IP network server, making the data available to remote clients. Ultimately, the server will accept connections over both Ethernet and the PSTN (Public Switched Telephone Network)1 using PPP to manage dial-up connections. Support for dial-up networking is primarily what will make the data logger truly remote. This allows access to any client computer anywhere in the world with Internet access without requiring the presence of an Ethernet network at the data collection site. It assumes nothing more than a serial modem and a connection to the public phone network.
The actual data collected by the application isn't terribly important. The main point is that we can collect information from some sensor or other physical device (or possibly multiple devices) and upload it to any interested client over a TCP/IP network. For this reason we'll try to keep the framework used for data collection relatively general purpose and reusable to allow for collecting data from other types of devices. However, to make the finished example reasonably concrete, we'll need some real data to sample. For this purpose we can recycle our effort from the 1-Wire Networking chapter in which we created a humidity and temperature sensing circuit and an accompanying Java class.
The data logging application consists of several classes. The class that contains the main method is in a class named DataLogger. We will also refer to the entire application as "DataLogger," as this is the name of the binary that will be executed on TINI.
The DataLogger example will combine three different concepts from this and two previous chapters.
TCP/IP networking
Serial communications
1-Wire networking
Since the DataLogger example is rather large, it will be broken down into the following steps.
Creating the network server. The TCP/IP server will be implemented in the main class named DataLogger. The server will be implemented in a multithreaded fashion and will handle all inbound connections over an Ethernet network and eventually over the phone network using a modem.
Implementing the data collection classes. These classes will be responsible for collecting and managing the data samples as well as writing the results to an output stream to the client.
Develop a test client application. After completing these first two steps, we'll have enough functionality to test an intermediate version of the DataLogger application over an Ethernet network only.
Adding dial-up networking support. Create a class to manage PPP connections.
Managing the serial data link used for PPP communications. We'll develop a set of classes that deal with all of the issues of communicating with both a raw serial port and a modem attached to a serial port.
Testing the application. Finally we'll be able to test the entire application with a sample client downloading the data log over both an Ethernet network and the PSTN.
Because the DataLogger example is fairly large, the following sections omit portions of the source code. However, all of the source code for the DataLogger application is provided in the accompanying CD.