-
-
Save jamesmacwhite/66b6d75e1daea67ec64c157d2a53f2c1 to your computer and use it in GitHub Desktop.
Script to help me position my `Alcatel Linkhub HH40v` LTE modem for the best signal strength
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
<Program Name> | |
say_lte.py | |
<Authors> | |
Lukas Puehringer <luk.puehringer@gmail.com> | |
James White <james@jmwhite.co.uk> | |
<Purpose> | |
Script to help me position my `Alcatel Linkhub HH40v` LTE modem for the | |
best signal strength. | |
If a change in signal strength is detected, it uses the OS X command line | |
tool `say` to say the new signal strength. | |
<Usage> | |
1. Connect your computer to your Alcatel Linkhub's WiFi | |
2. Open a browser and go to the admin page at `192.168.1.1` | |
3. Open your browser's developer tools, go to the `network` tab and look | |
for requests to `http://192.168.1.1/jrd/webapi` | |
4. Take any request, copy the value of the header | |
`_TclRequestVerificationKey` and assign it to below variable | |
`REQUEST_KEY` | |
5. Turn up the volume of your computer and run the script | |
6. Walk your Alcatel Linkhub around your apartment (long extension cord is | |
helpful) and place it at where your computer tells you a high signal. | |
""" | |
import time | |
import requests | |
import subprocess | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('requestKey', help='_TclRequestVerificationKey header') | |
parser.add_argument('routerIPAddress', help='The LAN IP of your router', nargs='?', default='192.168.1.1') | |
parser.add_argument('jrdId', help='ID value used with JSON-RPC API calls', nargs='?', type=int, default=1) | |
args = parser.parse_args() | |
URL = 'http://' + args.routerIPAddress + '/jrd/webapi' | |
# JSON rpc request to get information such as signal strength | |
JSON_REQUEST = { | |
"id": str(args.jrdId), | |
"jsonrpc": "2.0", | |
"method": "GetSystemStatus", | |
"params": {} | |
} | |
# Headers required to authenticate with JSON rpc (assessed by trial and error) | |
HEADERS = { | |
"_TclRequestVerificationKey": args.requestKey, | |
"Referer": "http://" + args.routerIPAddress + "/index.html" | |
} | |
def main(): | |
""" Run indefinitely to (at an interval of 1 second) | |
- print requested signal strength to command line, and | |
- if signal strength changes, `say` the new strength. | |
""" | |
last = None | |
while True: | |
r = requests.post(URL, json=JSON_REQUEST, headers=HEADERS) | |
strength = r.json().get("result", {}).get("SignalStrength") | |
print "Signal Strength:", strength | |
if strength != last: | |
process = subprocess.Popen(["say", 'Signal strength is now ' + str(strength)], | |
stdout=subprocess.PIPE) | |
process.communicate() | |
last = strength | |
time.sleep(1) | |
if __name__ == "__main__": | |
main() |
Seems to work also with TCL LINKHUB HH132
<?php
$headers = [ '_TclRequestVerificationKey: XXX', '_TclRequestVerificationToken: XXX'];
$payload = array(
"id"=>"0",
"jsonrpc"=>"2.0",
"method"=>"GetUsageSettings", // traffico
// "method"=>"GetSIPAccountSettings",
"params"=>"{}"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, "http://192.168.1.1/jrd/webapi");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
$result = curl_exec($ch);
$result = json_decode($result, true);
if (isset($result["error"]["message"])) {
echo("ERROR: " .$result["error"]["message"]);
} else {
// var_dump($result);
echo $result["result"]["UsedData"] / pow(1024, 3) . "\n"; // traffico
}
?>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, I'm cannibalizing this to monitor my bandwidth usage 😄
Keywords: IK41 web api bandwidth traffic
jrdId
is theid
you see in response, so for my device I useGetUsageSettings
, which containsUsedData
and it has"id": "7.3"
.I hope
_TclRequestVerificationToken
is constant.