Retrieving modem information from the MiFi with C#
Monday, December 7, 2009 at 4:31PM
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) Apparently I was dead wrong on that one and -20dBm is actually a stronger signal than -100dBm. Sorry for the confusion.
The API offers signal strength as a value between 0 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!
Reader Comments (9)
Just wondering where you found out about the modemstatus.html direct URL? Is there a document describing all the available web services/URLs/XML config file settings for the mifi?
Thanks, Great article.
the mifi is reachable via the mifi.admin and admin.mifi hostnames resolved by the internal dns server in the mifi. The XML config file allows you to customize some more hostnames for the mifi web interface.
<DNS>
<enable>1</enable>
<url1>mifi.admin</url1>
<url2>admin.mifi</url2>
<url3>myownmifi</url3>
<url4>0</url4>
<httpredirect>0</httpredirect>
</DNS>
I honestly don't remember where I found the modemstatus.html URL. It was probably in a forum post somewhere. Sorry.
Cool tip with the custom DNS configuration, as well!
Have you figured out a way to grab modemstatus without first doing a manual login to the admin interface? For instance, if I turn on the mifi, and try to download modemstatus, I get the "login required first" or similar message.
Which mobile broadband provider do you have? My Sprint MiFi serves it up without requiring credentials. I haven't been able to try this with any other model.
Sprint here as well. hmm. I wonder if it's a different firmware version or something.
The following is from my "system status" page on the mifi:
Version
Manufacturer: Novatel Wireless AP: 11.47.17
Model: MiFi2200 SPRINT Router: 018.0101
Serial No: ******************* Modem: 142
We appear to have the same firmware version and everything. That's very strange. I wish I could be of more help. :(
Am researching some way to sutomize the mifi DNS IPs to use OpenDNS or similiar. I know verizon allows that to happen (with mifi plugged into a computer and the networking settings changed). It seems that there woudl be a way to modify the config file to force the mifi to use cusotm DNS when in wifi mode. Any idea?
Warezone Christian Louboutin Shoes and Pandora Jewelry, lets you send Pandora charm, you may need to Zumba Fitness DVD or P90X or Insanity Workout DVDvideo tutorial, creating unique Fitness.Christian Louboutin Knockoffs,Christian Louboutin Wedding Shoes,
Christian Louboutin Boots,Christian Louboutin Sandals,Christian Louboutin Wedges,Christian Louboutin Platform,P90X DVD,DVD Sales,Vibram Five Fingers,Herve Leger,Cheap Christian Louboutin,Alexander Wang Dress,Alexander Wang Shoes,Alexander Mcqueen Shoes,Giuseppe Zanotti Shoes,ED Hardy Shoes,Jimmy Choo Shoes,Chanel Shoes,YSL Shoes,Manolo Blahnik Shoes,Vivienne Westwood Shoes,Tory Burch Shoes,Louis Vuitton Shoes,Miu Miu Shoes,Salvatore Ferragamo Shoes,Marc Jacobs Shoes,Christian Dior Shoes,Herve Leger,Sergio Rossi Shoes,Lanvin Shoes,Coach Shoes,Prada Shoes,Gucci Shoes,Moncler Jackets,MBT Shoes