The Swiss Post is renowned for its efficiency in handling shipments within the country. Priority packages are delivered in any city, town, or village within Switzerland the day following the day of dispatch, even in remote valleys. This week, we decided to perform a small experiment to see how this service works by following the journey of a package with a YoctoHub-GSM-2G.
We sent a package from Cartigny, where Yoctopuce is located, to Santa Maria Val Müster, a picturesque village at the very end of Graubünden. Our package therefore had the opportunity to cross the whole country, from West to East. In the package, we simply put a YoctoHub-GSM-2G, powered by 4 NiMH batteries. We have intentionally avoided all kinds of Lithium batteries to prevent fire hazard.
We didn't include a Yocto-GPS, as it most probably would have been useless: GPS signals are very weak and had practically no chance to reach inside vehicles and buildings through which our package transited. In the opposite, GSM coverage is much better, even if there was a risk that part of the journey would be done in a metal truck where signals couldn't reach the package, we were hopeful to retrieve its trace from time to time.
The magic package contains only a YoctoHub-GSM-2G and a NiMH battery.
Indeed, each GSM base station has a unique identifier, which is transmitted to cellular phones that connect to it. On the YoctoHub-GSM-2G, you can obtain this identifier with the get_cellIdentifier function. This identifier is made of 4 numbers: the country code (MCC), the network code (MNC), the location area code (LAC), and antenna number (Cell ID). By looking up this number combination in an antenna database, you can generally find where it is located and therefore determine the approximative zone where the phone is located.
The YoctoHub-GSM-2G is configured to wake up every 5 minutes and to perform an HTTP callback on our web site to post the identifiers of the GSM antenna to which it connected itself. If there is no possible connection, it automatically goes back to sleep after 2 minutes, to save battery life.
An unusual package
On the server, a short PHP script records, for each received HTTP callback, a line in a text file with the time, the antenna identifiers, and the GSM reception quality:
include("yocto_cellular.php");
include("yocto_realtimeclock.php");
include("yocto_wakeupmonitor.php");
// API init in HTTP callback mode
if (yRegisterHub("callback",$errmsg)!=YAPI_SUCCESS) die($errmsg);
// Load current time from device (RTC)
$rtc = yFirstRealTimeClock();
$now = $rtc->get_unixTime();
$date = $rtc->get_dateTime();
// Load current cell identifier and link quality
$gsm = yFirstCellular();
$cell = $gsm->get_cellIdentifier();
$link = $gsm->get_linkQuality();
// Append information to a simple text file
file_put_contents('tracker.txt', "$now,$date,$cell,$link%\n", FILE_APPEND);
// Send the device to sleep in 3 seconds
$monitor = yFirstWakeUpMonitor();
$monitor->sleep(3);
We only have to write a short piece of code which reads this file and converts the GSM antenna identifiers into geographic coordinates to know what happened to our package. To do so, there are two services: OpenCellID.org, an Open Source project, and Google's geolocation API, because as you may guess, Google has a large data collection linking cell identifiers with their location. We decided to perform our tests with the OpenCellID database, which you can easily download for off-line use. In this way, we can easily generate using PHP a file describing the route in KML format, i.e. a list of waypoints encoded in XML. This KML file can then be imported into most mapping software, like Google Earth, or the interactive map of Switzerland below. You can zoom with your mouse if you want, and click on the points to get the time record and signal strength:
Conclusion
The experiment has worked perfectly well. We can see that, in order to reach its destination at 8AM, our package has been travelling almost without interruption during the whole night. As there is no tunnel in the Alps going from West to East, it had to travel around them by the North. By looking at the waypoints, we can also guess that most of the trip was made on the road and not by train (too bad...). And this small experiment also shows that even when you disable the GPS on your smartphone, your phone operator and your phone still know quite well where you are...
Edit: the package came back to us a few days later. The 4 small AA batteries lasted enough to keep us updated on its position every 5 minutes, almost without interruption, for 3 days and a half !