Query Huawei HiLink modems for status information.
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 18 commits ahead, 6 commits behind trick77:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



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

Install Requirements

Requires python 2.7.9 & python pip


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

Create config

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


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:


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

Now try and start the interface

sudo ifup eth1

ifconfig should now show that eth is connected to gateway 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.

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:
  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:
    Public IP address:
    DNS IP addresses:,
    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