Entries in mifi.net (3)

Monday
07Dec2009

Retrieving modem information from the MiFi with C#

The Novatel Wireless MiFi Mobile Hotspot offers up a surprising amount of diagnostic and status information. My own MiFi.NET library can retrieve most of this information with the MiFi's API. One thing it doesn't offer through the API is the modem's RSSI value, or Received Signal Strength Indication. This value is a negative number expressed in dBm (or decibels per milliwatt) and represents the amount of power in the radio signal. A low RSSI value represents a strong signal (-100 dBm is stronger than -20 dBm, for example).

The API offers signal strength as a value between 1 and 5. If you're looking for the optimal position for your MiFi, however, this just isn't accurate enough. Verizon users can see this value in their web admin portal, but Sprint users don't have this functionality. Fortunately, the page that actually serves up this data is still accessible with a direct URL.

I'm going to show you a simple class that retrieves and parses this information for use in your own applications. Along the way, I'll also explain the different values and what they mean. Note that I will not be including this functionality in MiFi.NET, because it is not part of the official API specification.

To get started, we need a model to represent the modem status information.

public class MiFiModemStatus {
	public string Mdn { get; set; }
	public string Esn { get; set; }
	public string EsnHex { get; set; }
	public int Channel { get; set; }
	public int PRev { get; set; }
	public int PrlId { get; set; }
	public int BandClass { get; set; }
	public int EriVersion { get; set; }
	public bool Dormant { get; set; }
	public int SignalEvdo { get; set; }
	public int Signal1X { get; set; }
	public int BatteryLevel { get; set; }
	public bool BatteryCharging { get; set; }
}

But what do these values mean?

  • MDN - Mobile Directory Number. This is the phone number assigned to your MiFi device.
  • ESN - Electronic Serial Number. This is the unique identifier for your device. All wireless phones are assigned an ESN by the FCC. The MiFi offers this value as both a decimal and in hex format.
  • Channel - The frequency on which the device is operating. Note that this is different from the WiFi channel that you can change in the web admin.
  • P_REV - Interim Standard 95 (also known as IS-95, cmdaOne, or TIA-EIA-95) protocol revision. P_REV 6 is part of the CDMA2000 (3G) standard.
  • PRL ID - Preferred roaming list version. The MiFi maintains an internal list of frequency bands on which it can operate, called the PRL. This number represents the current version of that list.
  • Band Class - The frequency band that the device is operating in.
  • ERI Version - Enhanced roaming indicator version. This value varies between companies, so I can't really tell you exactly what it means.
  • Dormant - If no data is being transferred, the modem will go into a dormant state to save power and this value will be true.
  • EVDO Signal - The current EVDO RSSI value.
  • 1X Signal - The current 1xRTT RSSI value.
  • Battery Level - The battery's current charge level. This value is also available with the API.
  • Battery Charging - True if the battery is currently charging. This value is also available with the API.

To get this information, we need to download and parse the modemstatus.html page. Before doing that, let's write a method to grab the value of each of those fields.

private static string ParseValue(string s, string field) {
	Regex regex = new Regex(string.Format(
		@"<td nowrap>{0}:</td> <td nowrap>(-?\w+)(?: dBm)?</td>", field));
	Match match = regex.Match(s);
	return match.Success ? match.Groups[1].Value : string.Empty;
}

Here, we're using a regular expression to search for the field. We capture the value and also handle the special case for RSSI values (-? allows the negative number to be properly captured, and (?: dBm)? allows for the dBm suffix).

Now we need a method to parse the page as a whole and return a populated model.

private static MiFiModemStatus Parse(string s) {
	return new MiFiModemStatus {
		Mdn = ParseValue(s, "MDN"),
		Esn = ParseValue(s, @"ESN \(decimal\)"),
		EsnHex = ParseValue(s, @"ESN \(hex\)"),
		Channel = int.Parse(ParseValue(s, "Channel")),
		PRev = int.Parse(ParseValue(s, "P_REV Indicator")),
		PrlId = int.Parse(ParseValue(s, "PRL ID")),
		BandClass = int.Parse(ParseValue(s, "Band Class Type")),
		EriVersion = int.Parse(ParseValue(s, "ERI Version")),
		Dormant = ParseValue(s, "Dormancy") == "TRUE",
		SignalEvdo = int.Parse(ParseValue(s, "Signal - EVDO")),
		Signal1X = int.Parse(ParseValue(s, "Signal - 1X")),
		BatteryLevel = int.Parse(ParseValue(s, "Battery Level")),
		BatteryCharging = ParseValue(s, "Battery Charging") == "1"
	};
}

With this method, we simply use the method we wrote earlier to grab each value. Note that we had to escape the parentheses because the field name gets inserted into the regular expression. Without escaping them, (decimal) and (hex) would be read as capture groups.

Finally, we have to actually download the page itself. We'll do this with a static Read method.

public static MiFiModemStatus Read(IPAddress ipAddress) {
	string uri = string.Format("http://{0}/modemstatus.html", ipAddress);
	string text;

	HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
	HttpWebResponse response = (HttpWebResponse)request.GetResponse();
	using (StreamReader reader = new StreamReader(response.GetResponseStream())) {
		text = reader.ReadToEnd();
	}

	return Parse(text);
}

If you're ever done any work with HTTP requests, then this will be familiar. The method just builds a URL from the given IP address and downloads the modem status information. Then, it calls out to our Parse method and returns the populated MiFiModemStatus class.

Easy, huh? Hopefully this will be useful to you, especially in conjunction with MiFi.NET!

Sunday
15Nov2009

MiFi.NET Release: v1.0.0 Beta

I've released MiFi.NET v1.0.0 Beta on CodePlex. It comes as either a binary archive or a source archive. Please report any bugs you happen to find. It works on my local system with a Sprint MiFi 2200, but I haven't been able to test it on the Verizon or HSPA models (as I don't own any).

Tuesday
27Oct2009

MiFi.NET for the Novatel MiFi Mobile Broadband router

I just made my little side project public at CodePlex.com. It's called MiFi.NET and provides a simple yet complete interface to the webservices exposed by the Novatel MiFi Mobile Broadband router.

It's based on the latest specification available from the Novatel Wireless Developer Lounge and I intend to add new features as Novatel makes them available.

Here's a quick shot of the included sample application to give you an idea of the kind of data you can retrieve using MiFi.NET. (Note that the GPS data is missing in this shot because I didn't have it enabled on my device at the time.)

Here's an example showing how to get the current signal strength:

MiFiDevice device = new MiFiDevice(IPAddress.Parse("192.168.1.1"));
MiFiStatus status = device.GetStatus();
Console.WriteLine("Signal Strength: " + status.SignalStrength);