Hilink API
Hilink API
Release 0.0.1
chanakalin
1 Index 3
2 HiLinkAPI module 5
4 Declaimaire 17
Index 21
i
ii
HiLink API for Python 3, Release 0.0.1
This documentation will provide you a guide to integrate HiLink API for Python 3. This is a Python 3 module which
can use to manipulate data/internet connection related operations for Huawei HiLink modems which are having WebUI
versions,
• 17.x.x.x
• 21.x.x.x
• 10.x.x.x
and I have tested successfully with,
• E8372h-320
• E8372h-155
• E3372h-320
• E3372h-153
modems.
CONTENTS: 1
HiLink API for Python 3, Release 0.0.1
2 CONTENTS:
CHAPTER
ONE
INDEX
3
HiLink API for Python 3, Release 0.0.1
4 Chapter 1. Index
CHAPTER
TWO
HILINKAPI MODULE
Parameters
5
HiLink API for Python 3, Release 0.0.1
getDeviceName()
This method will return the device name (model) from API end point /api/device/information.
Returns Return device name
Return type string
getKnownErrors()
This method will return all known errors
Returns Return {“<error code>”:”<error message>”. . . }
Return type dictionary
getLoginRequired()
This method will return either login/authentication required or not which will be updated after calling
initialize().
Returns Return login required or not
Return type bool
getLoginWaitTime()
This method will return waittime for next login attemp
If session need a refresh validateSession() before calling device information API end point.
Returns Login wait time
Return type int
getMaxIdleTime()
This method will return max idle time out of the data connection.
Mandatory to update by data configuration info by calling queryDataConnection() prior to call this
method
Returns Return max data connection idle time
Return type int
getNetwokModes()
Get primary and secondary network modes
Returns {“primary”:<<Primary networn mode>>,”secondary”:<<Secondary networn mode>>}
Return type dictionary
getNetwork()
This method will return the name of Carrier Network.
Carrier Network name can update by calling queryNetwork() and required only to call one time after the
first time after a possible WAN IP change like,
1. Connection switch on/off event after calling switchConnection().
2. Switching between LTE and WCDMA even after calling switchLTE().
7
HiLink API for Python 3, Release 0.0.1
getSessionRefreshInteval()
This method will return the session refresh interval while in idle without any operation. Use
setSessionRefreshInteval()
Returns Session refresh interval in seconds
Return type int
getValidSession()
This method will return if the session is valid for querying and operations or not
Returns Return a valid session or not
Return type boolean
getWANIP()
This method will return the WAN IP.
WAN IP can update by calling queryWANIP() and call this when after a possible WAN IP change like,
1. Connection switch on/off event after calling switchConnection().
2. Switching between LTE and WCDMA even after calling switchLTE().
getWebUIVersion()
This method will return WebUI version either 10, 17 or 21.
Returns Return WebUI version
Return type int
getWorkmode()
This method will return the work mode.
Mandatory to update by device work mode by calling queryDeviceInfo() prior to call this method
Returns Return network name
Return type string
httpGet(endpoint, cookies=None, headers=None)
Call an API end point using a HTTP GET request. If cookies are not provided (when defaulted to None)
will build cookies by calling buildCookies(). At the end of each call processHTTPHeaders() will call
to retrieve SessionID and __RequestVerificationToken.
Parameters
• endpoint (string) – API end point (eg:- /api/device/information)
• cookies (dictionary) – cookies, defaults to None
• headers (dictionary) – HTTP headers, defaults to None
Returns Return the HTTP response as a requests.Response
Return type requests.Response
9
HiLink API for Python 3, Release 0.0.1
setNetwokModes(primary='LTE', secondary='WCDMA')
Set primary and secondary network modes respectively with primary and secondary.
Parameters
• primary (String) – Either “LTE”,”WCDMA” or “GSM” as primary network mode
• secondary (String) – Either “LTE”,”WCDMA” or “GSM” as secondary network mode
Returns Return network mode configuration success or not
Return type bool
setSessionRefreshInteval(interval)
This method will set the session refresh interval while in idle without any operation.
Parameters interval (int) – Session refresh interval in seconds
start()
This method will start the thread.
stop()
This method will initialize thread stop.
switchConnection(status=True)
Switch on or off data connection based on status.
Parameters status (bool) – Either set status of the connection On or Off
Returns Return either requested connection switching succeeded or failed
Return type bool
switchDHCPIPBlock(gateway)
This methos will change DHCP IP block and gateway(modem) IP based on provided gateway.
All existing connections will drop and probably a soft reboot will performed after calling this method.
Use only gateway in 192.168.X.1 format (eg:- 192.168.2.1, 192.168.20.1). So the DHCP offering IP block
will be 192.168.x.100-192.168.x.199.
Parameters gateway (string) – Gateway or IP of the modem
switchNetworMode(primary=True)
Switch network between primary and secondary network modes based on primary. If primary is True
network mode switch to the primary or else to the secondary.
Primary network mode and secondary network mode can be set using setNetwokModes()
Parameters primary (bool) – Primary network mode or secondary network mode
Returns Return either requested network mode switching succeeded or failed
Return type bool
validateSession()
This method will validate session
• Check if a valid authenticated session
• If authentication required will login
11
HiLink API for Python 3, Release 0.0.1
THREE
Following is the example code from apiTest.py which can be used to test API compatibility of your modem. Here an
array of modems using with authentication and without authentication.
try:
webUIArray = [
# webui("E3372h-153", "192.168.18.1", "admin", "admin", logger=logging),
webui("E3372h-320", "192.168.8.1", "admin", "abcd@1234", logger=logging),
# webui("E8372h-320", "192.168.10.1", "admin", "abcd@1234",logger=logging),
]
13
HiLink API for Python 3, Release 0.0.1
print("****************************************\n\n")
###################
# stop
webUI.stop()
while(not webUI.isStopped()):
webUI.stop()
print(f"Waiting for stop")
sleep(1)
except Exception as e:
print(e)
except Exception as e:
print(e)
# End of the test
print("\n")
15
HiLink API for Python 3, Release 0.0.1
FOUR
DECLAIMAIRE
This software is free to use, re-distribute and provided without any warranty. Users are liable to take responsibility of
any action, misuse or damage. Refer the license for more information.
Huawei and HiLink are registered trademarks/products of Huawei Technologies Co. Ltd and/or its parents organiza-
tions.
17
HiLink API for Python 3, Release 0.0.1
18 Chapter 4. Declaimaire
PYTHON MODULE INDEX
h
HiLinkAPI, 5
19
HiLink API for Python 3, Release 0.0.1
B M
buildCookies() (HiLinkAPI.webui method), 5 module
HiLinkAPI, 5
C
configureDataConnection() (HiLinkAPI.webui P
method), 5 processHTTPHeaders() (HiLinkAPI.webui method), 9
E Q
errorCodes (HiLinkAPI.webui attribute), 6 queryDataConnection() (HiLinkAPI.webui method), 9
queryDeviceInfo() (HiLinkAPI.webui method), 10
G queryNetwork() (HiLinkAPI.webui method), 10
getActiveError() (HiLinkAPI.webui method), 6 querySupportedNetworkMethods()
getDataRoaming() (HiLinkAPI.webui method), 6 (HiLinkAPI.webui method), 10
getDeviceInfo() (HiLinkAPI.webui method), 6 queryWANIP() (HiLinkAPI.webui method), 10
getDeviceName() (HiLinkAPI.webui method), 7
getKnownErrors() (HiLinkAPI.webui method), 7 R
getLoginRequired() (HiLinkAPI.webui method), 7 reboot() (HiLinkAPI.webui method), 10
getLoginWaitTime() (HiLinkAPI.webui method), 7 resetActiveErrorCode() (HiLinkAPI.webui method),
getMaxIdleTime() (HiLinkAPI.webui method), 7 10
getNetwokModes() (HiLinkAPI.webui method), 7 run() (HiLinkAPI.webui method), 10
getNetwork() (HiLinkAPI.webui method), 7
getSessionRefreshInteval() (HiLinkAPI.webui S
method), 8 sessionErrorCheck() (HiLinkAPI.webui method), 10
getValidSession() (HiLinkAPI.webui method), 8 setCredentials() (HiLinkAPI.webui method), 10
getWANIP() (HiLinkAPI.webui method), 8 setNetwokModes() (HiLinkAPI.webui method), 10
getWebUIVersion() (HiLinkAPI.webui method), 8 setSessionRefreshInteval() (HiLinkAPI.webui
getWorkmode() (HiLinkAPI.webui method), 8 method), 11
start() (HiLinkAPI.webui method), 11
H stop() (HiLinkAPI.webui method), 11
HiLinkAPI switchConnection() (HiLinkAPI.webui method), 11
module, 5 switchDHCPIPBlock() (HiLinkAPI.webui method), 11
hilinkException, 5 switchNetworMode() (HiLinkAPI.webui method), 11
httpGet() (HiLinkAPI.webui method), 8
httpPost() (HiLinkAPI.webui method), 8 V
validateSession() (HiLinkAPI.webui method), 11
I
initialize() (HiLinkAPI.webui method), 9 W
isStopped() (HiLinkAPI.webui method), 9 webui (class in HiLinkAPI), 5
L
login_b64_sha256() (HiLinkAPI.webui method), 9
21