Skip to content

openenergymonitor/huawei-hilink-status

 
 

Repository files navigation

Huawei-HiLink

Setup Huawei-HiLink USB modem to work on a RaspberryPi and view it's status

Install Requirements

Requires python 2.7.9 & python pip

Install

$ pip install schedule datetime paho-mqtt xmltodict
$ git clone https://github.com/openenergymonitor/huawei-hilink-status

Create config

$ cd huawei-hilink-status
$ cp default.config.ini config.ini
$ nano config.ini

Run

Test with:

$ ./hilink-mqtt.py

Run as service:

Create systemd service, assuming repo was cloned to /home/pi folder on a RaspberryPi, adjust paths if needed

$ sudo ln -s /home/pi/huawei-hilink-status/hilink-status.service /etc/systemd/system/hilink-status.service

Set permissions:

sudo chmod 644 /etc/systemd/system/hilink-status.service

Reload systemd then enable the service at startup:

$ sudo systemctl daemon-reload
$ sudo systemctl enable hilink-status.service
$ sudo systemctl start hilink-status.service

Check service status and view log snippet with:

sudo systemctl status hilink-status.service


Huawei Hi-Link 3G Modem Raspberry Pi Setup

Tested with Huawei E3231 and E3131

* Caution: the E3131 comes in several different hardware variants, make sure your hardware can support Hi-Link mode.

Setup power supply

If using a newer Raspberry Pi (B+,2 or 3) the Pi should be able to power the USB modem direclty without a y-cable ot usb hub if max power mode is tured on. Ensure a decent 2A PSU is used:

sudo nano /boot/config.txt

Add the following at bottom of file then save and reboot:

max_usb_current=1

For more info on what this does see forum post

  1. Install sg3-utils:

    sudo apt-get install sg3-utils

  2. Change Huawei Hi-Link USB mode

$ lsusb will probably return 12d1:1f01 Huawei Technologies Co., Ltd. this is mass storage mode. We need Hi-Link USB modem mode. To switch modes enter command:

sudo /usr/bin/sg_raw /dev/sr0 11 06 20 00 00 00 00 00 01 00

$ lsusb should now return 12d1:14db Huawei Technologies Co., Ltd.

See here for more information on Huawei USB modes and AT commands.

  1. Set USB mode at boot

To ensure correct USB mode is set on each boot, create the following file:

sudo nano /etc/udev/rules.d/10-Huawei.rules

copy and paste this line in to it.

SUBSYSTEMS=="usb", ATTRS{modalias}=="usb:v12D1p1F01*", SYMLINK+="hwcdrom", RUN+="/usr/bin/sg_raw /dev/hwcdrom 11 06 20 00 00 00 00 00 01 00"

Open the network interfaces file to edit:

sudo nano /etc/network/interfaces

and add the following lines:

allow-hotplug eth1
iface eth1 inet dhcp

Note: on newer version of Debian e.g Bullseye the network setting are now in /etc/systemd/network

Create the followng file:

sudo nano /etc/systemd/network/05-eth1.network

With the content:

[Match]
Name=eth1
[Network]
DHCP=yes
MulticastDNS=yes
[DHCPv4]
ClientIdentifier=duid

Now try and start the interface

sudo ifup eth1

Give the system an IP address:

sudo ifconfig eth1 192.168.1.47

ifconfig should now show that eth is connected to gateway 192.168.1.1. This is the default IP of the Hi-Link modem. If the gateway of eth0 (your router) is also this same IP this will cause and issue for testing.

Or on newer Debian

sudo ip link set dev eth1 up

or

sudo sudo networkctl up eth1

Check status with

networkctl status eth1

You may need to reboot the Pi.

Status Utility Installation

The utility uses the xmltodict module which can be installed using pip:

apt-get install python-pip
pip install xmltodict
pip install requests

Usage example

$ python ./hstatus.py
Huawei E3276 LTE Modem (IMEI: 861711012616361)
  Hardware version: CH2F4276GM
  Software version: 22.250.04.00.186
  Serial: B3A3TC2313833197
  MAC address (modem): 00:0D:87:22:34:AC
  Connection status: Connected
    Network type: W-CDMA (3G)
    Signal level: ***** (92%)
    Roaming: Enabled
    Modem WAN IP address: 10.197.32.60
    Public IP address: 32.131.81.221
    DNS IP addresses: 212.113.0.4, 66.28.0.61
    Network operator: Swisscom
    Connected for: 00:49:33 (hh:mm:ss)
    Downloaded: 737.0 KB
    Uploaded: 178.0 KB
  Total downloaded: 47.69 MB
  Total uploaded: 19.86 MB

About

Query Huawei HiLink modems for status information.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%