#!/bin/bash
#Status: http://hi.link/api/monitoring/status (GET)
# ConnectionStatus:
# 112 = no autoconnect
# 113 = no autoconnect on roaming
# 114 = no reconnect
# 115 = no reconnect on roaming
# 900 = connecting
# 901 = connected
# 902 = disconnected
# 903 = disconnecting
#
# | discon | con |
# | 2G | 3G | 2G | 3G |
# NetworkType: | 3 | 4 | 3 | 4/7 |
# 3 = 2G / 4 = 3G (UMTS) / 7 = 3G+ (HSDPA)
#
# SignalStrength: strength in percent
#
# ServiceStatus: 1 = enter PIN / 2 = PIN correct
# SimStatus: 0 = no SIM access / 1 = SIM acc
site='192.168.8.1'
element_ses='response/SesInfo'
element_tok='response/TokInfo'
element_connstat='response/ConnectionStatus'
element_networktype='response/CurrentNetworkType'
element_sigicon='response/SignalIcon'
element_wanip='response/WanIPAddress'
url="http://${site}/api/webserver/SesTokInfo"
xml=$(curl -k --silent -X GET "$url")
#echo "$xml"
COOKIE=$(printf '%s\n' "$xml" | xmlstarlet sel -t -v "$element_ses")
TOKEN=$(printf '%s\n' "$xml" | xmlstarlet sel -t -v "$element_tok")
#echo "$COOKIE"
#echo "$TOKEN"
monit_url="http://${site}/api/monitoring/status"
device_url="http://${site}/api/device/basic_information"
MODEMSTATE=$(curl -k --silent -X GET "$monit_url" -H "Cookie: $COOKIE" -H "__RequestVerificationToken: $TOKEN" -H "Content-Type: text/xml")
#curl -k --silent -X GET "$url" -H "Cookie: $COOKIE" -H "__RequestVerificationToken: $TOKEN" -H "Content-Type: text/xml"
#echo "$MODEMSTATE"
CONNSTAT=$(printf '%s\n' "$MODEMSTATE" | xmlstarlet sel -t -v "$element_connstat")
NETWORKTYPE=$(printf '%s\n' "$MODEMSTATE" | xmlstarlet sel -t -v "$element_networktype")
WANIP=$(printf '%s\n' "$MODEMSTATE" | xmlstarlet sel -t -v "$element_wanip")
SIGICON=$(printf '%s\n' "$MODEMSTATE" | xmlstarlet sel -t -v "$element_sigicon")
echo "Connection State: $CONNSTAT"
echo " Network Type: $NETWORKTYPE"
echo " Signal Icon: $SIGICON"
echo " WAN IP: $WANIP"
This script works better than the old one and lets you return just the information you want. Note, in my script I return the signal strength icon because the Signal Strength value seems to always be null for this dongle. You can tell relative strength by the signal strength icon. Here is some sample output. I have since gotten a dongle that is compatible with T-Mobile networks in the USA, so the network type is 19 - I guess that means LTE since that is what the dongle's website says when I connect to it and look at the network type. Note, I replaced my IP with x's
pi@remotepi:~/modemwork $ ./get-modem-state
Connection State: 901
Network Type: 19
Signal Icon: 1
WAN IP: xx.xxx.xxx.xxx
In order to really interact with the dongle, I needed to be able to login to the web site that the dongle provides. To do that, I had to move to using a library that was written by someone else. I will make a new blog post to describe how I use it to do more with the dongle, including getting and sending SMS messages!