As usual, getting the cellular modem to startup at boot time was not as easy as expected. The behavior I wanted was simple: When windows boots up, I want the modem to turn on and provide an internet connection. The trick here is that the cellular modem acts like a modem — meaning that it doesn’t provide instant connectivity like a WiFi card does. You have to actually “dial in” manually. Usually, this is done using the little application that comes with the unit, but that requires a human to launch it. I need connectivity to happen automatically and without requiring someone to log onto the machine.
I started by looking at using the various Startup folders that Windows XP has available, but couldn’t get any of them to work before someone had logged on. In my research, I found out that windows has a command line utility called RasDial that allows you to automate logging on through a modem. Once I found that, I figured the simplest approach would simply be to have my NT Services just launch this executable with the proper command line arguments as part of their startup. Of course, I hit a few issues in doing this:
- Since the robot is a really underpowered PC, I had to set the timeout on executing that command to 6 minutes or I would constantly get timeouts launching the EXE
- Because that whole process took so long, the Service Control Manager (or SCM, the part of Windows that manages NT Services) would think the service was hung. I ended up rewriting my service to do most of its work on another thread.
- I have two services, but didn’t want both to have to do these machinations. So, I tried just doing it in one, and then telling windows that the other service depends on the first service in the startup order. I could never get that to work. The dependent service would simply never start. So, I ended up just having each reduntantly try to startup the modem in case they get loaded in a different order over time.
So now it all works: I am using a cellular modem, using the .Net ServiceBus relay to communicate to the robot, and this all starts up automatically at boot time without requiring someone to logon. However, it is very slow. Takes about 6 minutes to boot the robot now between the cost of normal windows boot, starting up the modem, and logging into the .Net ServiceBus. Pretty awful, but it is OK for my purposes for now.
Here’s the .Net code I’m using to startup the modem:
public static void EnsureNetwork()
{
ProcessStartInfo info = new ProcessStartInfo("RasDial", "\"ATT Wireless\"");
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
Process process = Process.Start(info);
if (!process.WaitForExit(360000))
{
throw new ApplicationException(string.Format("RasDial timed out:{0}", process.StandardOutput.ReadToEnd()));
}
else if (process.ExitCode != 0)
{
throw new ApplicationException(string.Format("RasDial returned exit code {0}: {1}", process.ExitCode, process.StandardOutput.ReadToEnd()));
}
}