Saturday, October 20, 2018

Update #2: SMS with a Huawei E8372

This is the next edition of the series of posts about interfacing with the Huawei E8372 Cellular Dongle, sometimes called the Wingle for WiFi-Dongle. This device is really a cool little device that can both provide internet access through USB and also through the WiFi network it can host.



I am using this device to supply internet to a remote island in Canada by pairing it with a directional antenna mounted on an antenna tower. I started out interfacing with this device very simply. (See the two previous posts on this subject) This dongle has the ability to send and receive SMS messages over the cell network, so I decided that I needed to be able to access those capabilities. Very quickly it became clear that using the scripts I was developing would not work so I started searching for a library or other software that could help me.

Wednesday, May 16, 2018

Update: Getting Status Data from a Huawei E8372 USB Dongle

In my previous post, I describe a script for getting the status from a Huawei dongle. Since I wrote that, I have improved the script that I wrote. Here is the updated script:

#!/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!

Wednesday, March 7, 2018

Getting Status Data from a Huawei E8372 USB Dongle

I am working on creating a remote solar-powered station that will report weather data from a location in Canada using a cellular connection. At the heart of it will be a Raspberry Pi Zero W running in headless mode. It connects to the weather station and then will send the data to the Weather Underground over the internet. The location is on a pretty remote island; it is just withing cell coverage, but with no commercial services at all, particularly no power. The location is occupied much of the time in summer, but during the winter - from about October until May there will be no one at the location at all.

This presents a number of problems for a system that has to function without any local interaction; there will be no one to power cycle the devices, look to see if any lights are lit, and there will be no one to push a reset button if that is needed. The entire system has to be setup so that it can do these things and act autonomously to recover from all sorts of situations that might arise. For instance, after the snow falls, the solar panel may get covered and stop producing power; weather may also cause it to lose connection to the cellular internet.

This means adding some smarts to the system to detect when these states might happen. To those ends, I have purchased a current and voltage monitor board, a solar charge controller, a real time clock module and a USB extension board for the Zero. For cellular connectivity, I will be using a link to the T-Mobile coverage in Canada - on the island it is limited to 3G, but since the data being transmitted is simple weather data, it should work fine.