Closed ryanbarlow97 closed 1 year ago
All these works ~correctly for me on B310-22s
antenna_status()
{'antenna1_status': '0', 'antenna2_status': '0'}
antenna_type()
huawei_lte_api.exceptions.ResponseErrorNotSupportedException: 100002: No support
get_antenna_settings()
{'antenna_type': '3'}
Does you'r router support these? (Huawei firmware is a mess so it may throw incorrect errors), are you logged in correctly? (show your code)
I have this router: Huawei 5G CPE Pro 2 (H122-373)
I am logged in using the method you made, you can see from my last screenshot that it logs in and scrapes all the data correctly, so it's not a login issue?
Image of the code ^
@ryanbarlow97 code looks fine, it may be anything, how i said, Huawei REST XML API is a mess..., it can be one of these issues (or something new):
user
and admin
account so be sure you are using admin
)To debug this: 1) make sure that functionality that you want is working in your Modem/Router web interface 2) Use your browser Dev Tools to look on request/response that your web interface is sending/receiving when saving required settings or viewing required data 3) Check if what you found is implemented here &&|| check if it sending correct data to your router
I Don't have Huawei 5G CPE Pro 2
in here so i can't check it, only you can :)
It appears my ISP has literally removed everything from the API regarding bands..
Of these, I am only getting a response from:
So many disabled API things :(
Here, on Huawei 5G CPE Pro 2, official web gui does GET api/device/antenna_type (while in advanced->system->system settings) query which ends up with:
<?xml version="1.0" encoding="UTF-8"?>
<error>
<code>100010</code>
<message></message>
</error>
so maybe it's not implemented at all (here I have firmware from play.pl operator).
If you do
$('div:not(:visible)').show();
in browser inspector you will find that there is even gui part for antenna settings:
Antenna Settings
Expand
Please use the external antennas provided with the device. If you experience any issues using third-party antennas please contact the company you purchased them from.
Status Settings
Auto
When only one antenna is used, it is recommended to use antenna port 1
Please use antenna port 1. Antenna port 2 does not support connecting to external antennas.
Antenna 1Antenna 2
Antenna 1Antenna 2
Antennas
Antenna 1 status
Antenna 2 status
and also:
Antenna optimization
Expand
Optimize antenna settings for a better signal.
Note: Changing the settings may interrupt the network.
Mode
Cycle
Cycle range: 1 to 720 hours
Antenna group index
Index range: 1 to 10
Tx antenna
Optimize now
Save
Also randomly checked, check_notifications works here:
connection = AuthorizedConnection('http://admin:....@ip/')
client = Client(connection)
pprint.pprint(client.monitoring.check_notifications())
{'OnlineUpdateStatus': '14',
'SimOperEvent': '0',
'SmsStorageFull': '0',
'UnreadMessage': '0'}
I found that if you continue to use the same connection to the modem ( mine is a B535-333) ... that after a few minutes (maybe 300 seconds or calling the API a certain number of times?), one gets the above mentioned CSRF error and needs to log in with a new again to continue. It is true that quite a few parts of the API can be read without login.
I ended up needing to figure out how to trap the exception the relevant bits from my solution are below.
In reality, if you make calls over an extended period of time, it's probably best to close and make a new connection.
By the way, thank you @Salamek for this great library!! After too much time messing with curl, bash and sed to monitor my modem, I figured it's about time to sit down, read the python tutorial and documentation and hope for the object oriented lightning bolt to hit me in the head. :-)
from huawei_lte_api.Client import Client #https://github.com/Salamek/huawei-lte-api
from huawei_lte_api.Connection import Connection
from huawei_lte_api.exceptions import \
ResponseErrorException, \
ResponseErrorLoginRequiredException, \
ResponseErrorNotSupportedException, \
ResponseErrorSystemBusyException, \
ResponseErrorLoginCsrfException, \
ResponseErrorWrongSessionToken, \
RequestFormatException
import sys #might be necessary to get info for some errors?
SNIP... Initializing some super secret variables...
with Connection(modem_url) as connection:
client = Client(connection)
SNIP... some irrelevant or not so interesting stuff...
while( True ):
try:
stuff = client.device.signal()
except ( ResponseErrorException, ResponseErrorLoginCsrfException, ResponseErrorLoginRequiredException ) as err:
print('WARN: Reconnecting due to error: {0}'.format(err))
reconnect_count += 1
print('WARN: Reconnect count:' ,reconnect_count )
with Connection(modem_url) as connection:
client = Client(connection)
stuff = client.device.signal()
except:
print("ERROR: Unexpected error:", sys.exc_info()[0])
raise```
for k,v in stuff.items():
if k in interesting: #interesting is a list of the api suffixes one is interested in.
print( k,v) #or do more interesting stuff
I found that if you continue to use the same connection to the modem ( mine is a B535-333) ... that after a few minutes (maybe 300 seconds or calling the API a certain number of times?), one gets the above mentioned CSRF error and needs to log in with a new again to continue. It is true that quite a few parts of the API can be read without login.
I ended up needing to figure out how to trap the exception the relevant bits from my solution are below.
In reality, if you make calls over an extended period of time, it's probably best to close and make a new connection.
By the way, thank you @Salamek for this great library!! After too much time messing with curl, bash and sed to monitor my modem, I figured it's about time to sit down, read the python tutorial and documentation and hope for the object oriented lightning bolt to hit me in the head. :-)
from huawei_lte_api.Client import Client #https://github.com/Salamek/huawei-lte-api from huawei_lte_api.Connection import Connection from huawei_lte_api.exceptions import \ ResponseErrorException, \ ResponseErrorLoginRequiredException, \ ResponseErrorNotSupportedException, \ ResponseErrorSystemBusyException, \ ResponseErrorLoginCsrfException, \ ResponseErrorWrongSessionToken, \ RequestFormatException import sys #might be necessary to get info for some errors?
SNIP... Initializing some super secret variables...
with Connection(modem_url) as connection: client = Client(connection)
SNIP... some irrelevant or not so interesting stuff...
while( True ): try: stuff = client.device.signal() except ( ResponseErrorException, ResponseErrorLoginCsrfException, ResponseErrorLoginRequiredException ) as err: print('WARN: Reconnecting due to error: {0}'.format(err)) reconnect_count += 1 print('WARN: Reconnect count:' ,reconnect_count ) with Connection(modem_url) as connection: client = Client(connection) stuff = client.device.signal() except: print("ERROR: Unexpected error:", sys.exc_info()[0]) raise``` for k,v in stuff.items(): if k in interesting: #interesting is a list of the api suffixes one is interested in. print( k,v) #or do more interesting stuff
Yeah i managed to handle the CSRF token error, here is my code:
@Regis-Loyaute hmm i think that you have ~duplicated functionality of https://github.com/Salamek/netkeeper in your project BTW...
@Salamek i improved the reboot script
So, I am testing things around the antenna, and it keeps getting login fails, but I know for a fact the password is correct.
(Some of the things I have tested give the same error).
It does work for things like signal() though. See below;