cmaion / huawei_router

A shell script to interact with Huawei 4G routers
10 stars 3 forks source link

"Read SMS" issue #4

Open osering opened 5 months ago

osering commented 5 months ago

Hello.

Great peace of code - clear, concise, accurate and fresh! Moreover pure shell - not requiring any other dependencies. Best one of those including SMS send/receive functionality.


Most commands I tried - worked like a charm (sms sending as well), except this:

./huawei_router.sh read_sms

[huawei_router] Connecting [huawei_router] Requesting api/sms/sms-count [huawei_router] 169 message(s) in the inbox [huawei_router] Requesting api/user/login [huawei_router] Requesting api/sms/sms-list \>\encoding="UTF-8"?>

Another way was not successful as well: ./huawei_router.sh login_request api/sms/sms-list

[huawei_router] Connecting [huawei_router] Requesting api/user/login [huawei_router] Requesting api/sms/sms-list \<?xml version="1.0" encoding="UTF-8"?> \ \100005\ \\ \

Not sure what's the problem.

P.S. README has no info about parameters which can be used for SMS reading (how many to show - the newest/oldest X ones, or which one - number X starting count from last one, or just from unread, or by time frame / sms_id, etc.)

Device specs: 'DeviceName': 'B525s-23a' 'SerialNumber': 'YQD7N19612003409' 'HardwareVersion': 'WL1B520FM' 'SoftwareVersion': '11.190.65.00.00' customized by Dinis.ru 'WebUIVersion': '81.100.31.02.1134'

P.S. Thanks for your contribution to FLOSS!

cmaion commented 5 months ago

Did you set the admin account credentials, either in the script itself or in a ~/.huawei_router file?

osering commented 5 months ago

Sure. I suppose that sending SMS (and some other functions) also requires right credentials (and those works).

Found the problem: It is in the line: sms_list_xml="\<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\1\\$count\\1\\0\\0\\0\\" Variable \$count\ in my case is 169. if I replace $count in it with smaller value, it works - gives xml dump of mails. Value 50 is max accepted.

Proposal; let to enter this value at least as argument to shell script (like $1) with default value: 1 Argument values: 1, 2, 3 - means first, second, third (not one, two, three messages) message - so cut off just last one. But if variable value is -3 (-2), it would mean three (two) messages from last one)

Second argument $2 would be 0 - if mark sms as unread, 1 - if mark sms as read, 2 - leave read/unread mark as is. Default - 1. Value which have to be changed in email is: \0\ from \ \0\ \40364\ \ZZ Info \HERE IS CONTENT.\ \2024-03-25 00:55:29\ \\ \0\ \0\ \1\ \

cmaion commented 5 months ago

It should be kept as simple as possible. You can simply paginate by looping over the following code, by reading 50 SMS max at the time, and incrementing the page number, until the last page.

        sms_list_xml="<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><PageIndex>1</PageIndex><ReadCount>$count</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>0</UnreadPreferred></request>"
        request api/sms/sms-list "$sms_list_xml"
        echo $response

Or just limit $count to 50 then delete the SMS you have already read. After a few run you should not have any SMS left.