Wednesday 9 August 2017

"3G MiFi Modem Car Wifi Router", Lithium Batteries and the Internet of Things

The Internet of Things quite simply is when your devices (TV, house alarm, automatic gate, refrigerator, etc) get on the Internet.

The official definition doesn't seem to sound as pithy: "the inter-networking of physical devices, vehicles (also referred to as "connected devices" and "smart devices"), buildings, and other items embedded with electronicssoftwaresensorsactuators, and network connectivity which enable these objects to collect and exchange data".

This post is about the "inter-networking" portion, where your house devices use a gateway to get on the Internet. A "cookie-cutter" gateway can be made very cheaply by using a tiny Linux computer connected via WiFi to your house broadband (ADSL) modem.

I like the Raspberry Pi and the beaglebone. Both are capable of running standard, full-size Linux, especially the Slackware Linux distribution (OK, so I am an old geezer).

These computers are powered from your smartphone charger, and by extension the power bank. Best of all they are cheap. Technically they are overkill as IoT controllers, but they are fun and they are full Linux (you get python!) and hardware gets cheaper every year so unless you cannot afford the electrical power do try them out.

Beaglebone White (left) and Raspberry Pi with PiFace cape
For sustained (and I mean months on end) use, I prefer the beaglebone. The Raspberry Pi despite its many improvements and upgrades use the Broadcom chipsets which have USB ports that are much less reliable. And the Pi uses Broadcom USB for both its copper LAN and its WiFi interface which no amount of clever software can work around.

For some 3 years now I have been running IoT systems at remote sites. This lets me remotely access my systems from my study or my office. It is not always possible to get telephone landline ADSL, but usually there is a cellphone reception that is good enough. I just need to change my gateway to a 3G modem-router.

The first 3G modem routers I used had lithium batteries in them. I did not need the batteries as I had mains power, but they would not start up without the batteries. These batteries tend to fail, often because I had them on all the time in non-airconditioned places.

The D-Link DWR-730 with battery dismounted(top). Notice it is bulging in the middle 
TP-Link TL-MR3040 with attached 3G dongle. Notice the failed battery, which overheated whenever in use.

It was time to get one which did not have a lithium battery and I settled on the no-brand "3G Mifi Modem Car Wifi Router Mini Wireless Routers Unlock Modem with SIM Card Slot". The English seemed a little dodgy but hey, it was cheap (only RM78) and it did not have a lithium battery.


3G Mifi, reallr a WR-706

It arrived without a manual but had a crumpled scrap of paper with 2 lines scribbled on it.



I removed the cover and installed the SIM card with some difficulty: there were 4 positions that fit but only 1 correct position.

3G Mifi with SIM card installed. This is the only correct position
I powered it on from my smartphone charger cable, pressed the power button and ... nothing. But we engineers are bigger than mere manuals, and after much tinkering found that I had to hold down the power button for a few seconds before it will turn on.

From my laptop I looked for a new WiFi hotspot using the command 'iwlist wlan0 scan'

iwlist wlan0 scan
          Cell 03 - Address: 02:03:7F:95:6E:E5
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=68/70  Signal level=-42 dBm
                    Encryption key:on
                    ESSID:"MIFI_WR706_EE5"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 6 Mb/s; 9 Mb/s
                              11 Mb/s; 12 Mb/s; 18 Mb/s
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=0000000001c2176f
                    Extra: Last beacon: 5273ms ago
                    IE: Unknown: 000E4D4946495F57523730365F454535
                    IE: Unknown: 010882848B0C12961824
                    IE: Unknown: 030106
                    IE: Unknown: 0706555320010B1B
                    IE: Unknown: 2A0100
                    IE: Unknown: 32043048606C
                    IE: WPA Version 1
                        Group Cipher : TKIP
                        Pairwise Ciphers (2) : CCMP TKIP
                        Authentication Suites (1) : PSK
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : TKIP
                        Pairwise Ciphers (2) : CCMP TKIP
                        Authentication Suites (1) : PSK
                    IE: Unknown: DD180050F2020101000003A4000027A4000042435E006232
2F00
                    IE: Unknown: DD640050F204104A0001101044000102103B000103104700
101AFAD653631652ECB2FC1CF677E2E230102100085155414C434F4D4D10230006415236303078102
400012010420001201054000800060050F2040001101100074152364B2D415010080002010E

Aha, MIFI_WR706_EE5 was exactly what was scribbled on that scrap of paper. The next line was 1234567890 which I took to be the password. This lets me produce a wifi configuration file /etc/wpa_supplicant.conf as:

cat /etc/wpa_supplicant.conf
ctrl_interface_group=0
eapol_version=1
ap_scan=1
fast_reauth=1
#country=US
# WPA protected network, supply your own ESSID and WPAPSK here:
network={
  scan_ssid=1
  ssid="MIFI_WR706_EE5"
  proto=WPA RSN
  key_mgmt=WPA-PSK
  pairwise=CCMP TKIP
  group=CCMP TKIP
  psk="1234567890"
  priority=10
}

Next you run the command:
wpa_supplicant -d -Dwext -iwlan0 -c/etc/wpa_daisy.conf -B

You check the results with
wpa_cli -iwlan0 status

And you get:

bssid=02:03:7f:95:6e:e5
freq=0
ssid=MIFI_WR706_EE5
id=0
mode=station
pairwise_cipher=CCMP
group_cipher=TKIP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
ip_address=192.168.1.32
address=c8:ff:28:27:7d:2b
uuid=29de4b6d-135e-5be0-a3c3-0db44f618230

Next you do:

dhclient -v -1 wlan0
Listening on LPF/wlan0/c8:ff:28:27:7d:2b
Sending on   LPF/wlan0/c8:ff:28:27:7d:2b
Sending on   Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 6
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 14
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 18
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 16
DHCPREQUEST on wlan0 to 255.255.255.255 port 67
DHCPOFFER from 192.168.1.1
DHCPACK from 192.168.1.1
bound to 192.168.1.32 -- renewal in 33585 seconds.

And we have liftoff! The last output showed us that the 3G Mifi's IP address was 192.168.1.1, so I fired up my firefox browser and typed into it:
http://192.168.1.1

And got a rude shock- it's setup screen was in Chinese! Engineer or not, it is time to RTFM

Screenshot of the language change screen

That explains the dodgy English. If you moved the mouse around the browser screen it sometimes tells you(at the bottom of the browser) what is clickable. For example right at the top, the white-and-green icon resulted in  'http://192.168.1.1/Userguide_zh_v2.pdf'. Clicking on that produced a manual, but in in Chinese. 

Now websites (specifically HTML) often use languages codes to tell the browser what language to use, and 'zh' means Chinese, so I typed into the browser 'http://192.168.1.1/Userguide_en_v2.pdf' and sure enough an English manual popped up. You can download it here.

From there I discovered that the admin password was 'password', and this unlocked the other screens for me. Now with the manual, I calmed down enough and remembered I am Chinese too: the bit you want to click on is the third horizontal white bar from the top. That is a drop-down menu with 3 selections. Select the topmost one for English. Next press the left button at the bottom of the screen. It should now look like this:


And this is what the main screen should have looked like:


And there you have it. Set the hotspot name and password you want and you have a WiFi gateway for your beaglebone IoT, which is the subject of a later post, so do check in here again.

Happy trails.