Comments (9)
60 seconds is way too much in my opinion. I've used 5 seconds this time around, it was more than enough. You can see from my earlier tests that it took less than two seconds for my four-part SMS message to arrive (first part arrived at 17:58:24, fully recombined at 17:58:25 and I waited 500 ms between polls, if memory serves). It probably depends on the length and network conditions, but I doubt it would ever take more than 5 seconds.
from huawei-lte-api.
1.6.10 Implements new method Sms.get_messages that implements this fix and also yields new dataclass Message with SMS info
from huawei-lte-api.
Hmm i don't really know to be frank i have never tested this at all, how are messages marked as read? Only by polling them? Does Web UI has same issues? (we cant possibly test for that when we can't reproduce the error by our self)
First we need a reliable way how to reproduce this issue so some experimenting can be done...
from huawei-lte-api.
Okay, so I've managed to reproduce the expected behaviour, but not issue. I've polled for new SMS messages every 100 milliseconds and this is what happens - messages are assigned indexes as they arrive and once the message is recombined, the parts are deleted/de-indexed and only the complete message is available, indexed as the message which first arrived. This is a truncated log, I've excluded any repeated messages. In this instance, I haven't been marking messages as read.
2022-12-22 17:58:24 Message 1: This is a very long text message that spans multiple SMS messages, now for some padding.......................................................
{'Smstat': '0', 'Index': '40017', 'Phone': '+XXXXXXXXXXX', 'Content': 'Message 1: This is a very long text message that spans multiple SMS messages, now for some padding.......................................................', 'Date': '2022-12-22 17:58:22', 'Sca': None, 'SaveType': '0', 'Priority': '0', 'SmsType': '2'}
2022-12-22 17:58:24 ....Message 2: This is a very long text message that spans multiple SMS messages, now for some padding...................................................
{'Smstat': '0', 'Index': '40018', 'Phone': '+XXXXXXXXXXX', 'Content': '....Message 2: This is a very long text message that spans multiple SMS messages, now for some padding...................................................', 'Date': '2022-12-22 17:58:22', 'Sca': None, 'SaveType': '0', 'Priority': '0', 'SmsType': '2'}
2022-12-22 17:58:25 ........Message 3: This is a very long text message that spans multiple SMS messages, now for some padding...............................................
{'Smstat': '0', 'Index': '40019', 'Phone': '+XXXXXXXXXXX', 'Content': '........Message 3: This is a very long text message that spans multiple SMS messages, now for some padding...............................................', 'Date': '2022-12-22 17:58:23', 'Sca': None, 'SaveType': '0', 'Priority': '0', 'SmsType': '2'}
2022-12-22 17:58:25 ............Message 4: This is a very long text message that spans multiple SMS messages, now for some padding...........................................
{'Smstat': '0', 'Index': '40025', 'Phone': '+XXXXXXXXXXX', 'Content': '............Message 4: This is a very long text message that spans multiple SMS messages, now for some padding...........................................', 'Date': '2022-12-22 17:58:23', 'Sca': None, 'SaveType': '0', 'Priority': '0', 'SmsType': '2'}
2022-12-22 17:58:25 Message 1: This is a very long text message that spans multiple SMS messages, now for some padding...........................................................Message 2: This is a very long text message that spans multiple SMS messages, now for some padding...........................................................Message 3: This is a very long text message that spans multiple SMS messages, now for some padding...........................................................Message 4: This is a very long text message that spans multiple SMS messages, now for some padding...........................................................
{'Smstat': '0', 'Index': '40017', 'Phone': '+XXXXXXXXXXX', 'Content': 'Message 1: This is a very long text message that spans multiple SMS messages, now for some padding...........................................................Message 2: This is a very long text message that spans multiple SMS messages, now for some padding...........................................................Message 3: This is a very long text message that spans multiple SMS messages, now for some padding...........................................................Message 4: This is a very long text message that spans multiple SMS messages, now for some padding...........................................................', 'Date': '2022-12-22 17:58:23', 'Sca': None, 'SaveType': '0', 'Priority': '0', 'SmsType': '2'}
On my second attempt, I've tried marking the parts as read as soon as they arrive. All the parts were marked as read (including the first part)), but when they were recombined the whole message was "unread".
2022-12-22 18:01:10 Message 1: This is a very long text message that spans multiple SMS messages, now for some padding.......................................................
{'Smstat': '0', 'Index': '40018', 'Phone': '+XXXXXXXXXXX', 'Content': 'Message 1: This is a very long text message that spans multiple SMS messages, now for some padding.......................................................', 'Date': '2022-12-22 18:01:08', 'Sca': None, 'SaveType': '0', 'Priority': '0', 'SmsType': '2'}
2022-12-22 18:01:10 ....Message 2: This is a very long text message that spans multiple SMS messages, now for some padding...................................................
{'Smstat': '0', 'Index': '40019', 'Phone': '+XXXXXXXXXXX', 'Content': '....Message 2: This is a very long text message that spans multiple SMS messages, now for some padding...................................................', 'Date': '2022-12-22 18:01:08', 'Sca': None, 'SaveType': '0', 'Priority': '0', 'SmsType': '2'}
2022-12-22 18:01:11 ........Message 3: This is a very long text message that spans multiple SMS messages, now for some padding...............................................
{'Smstat': '0', 'Index': '40025', 'Phone': '+XXXXXXXXXXX', 'Content': '........Message 3: This is a very long text message that spans multiple SMS messages, now for some padding...............................................', 'Date': '2022-12-22 18:01:08', 'Sca': None, 'SaveType': '0', 'Priority': '0', 'SmsType': '2'}
2022-12-22 18:01:11 ............Message 4: This is a very long text message that spans multiple SMS messages, now for some padding...........................................
{'Smstat': '0', 'Index': '40026', 'Phone': '+XXXXXXXXXXX', 'Content': '............Message 4: This is a very long text message that spans multiple SMS messages, now for some padding...........................................', 'Date': '2022-12-22 18:01:09', 'Sca': None, 'SaveType': '0', 'Priority': '0', 'SmsType': '2'}
2022-12-22 18:01:11 Message 1: This is a very long text message that spans multiple SMS messages, now for some padding...........................................................Message 2: This is a very long text message that spans multiple SMS messages, now for some padding...........................................................Message 3: This is a very long text message that spans multiple SMS messages, now for some padding...........................................................Message 4: This is a very long text message that spans multiple SMS messages, now for some padding...........................................................
{'Smstat': '0', 'Index': '40018', 'Phone': '+XXXXXXXXXXX', 'Content': 'Message 1: This is a very long text message that spans multiple SMS messages, now for some padding...........................................................Message 2: This is a very long text message that spans multiple SMS messages, now for some padding...........................................................Message 3: This is a very long text message that spans multiple SMS messages, now for some padding...........................................................Message 4: This is a very long text message that spans multiple SMS messages, now for some padding...........................................................', 'Date': '2022-12-22 18:01:09', 'Sca': None, 'SaveType': '0', 'Priority': '0', 'SmsType': '2'}
It is possible that the issue I've raised only occurs if you mark certain parts as read as they arrive, instead of all of them or none of them, possibly because of the indexes. My old script based on the relay example did this, as it polled only one unread text at a time. I'm not sure how to reproduce the bug.
from huawei-lte-api.
I have put some thought into this, and i think this is race-condition in huawei firmware... Since it would be very hard to put a modem into this situation when using official web UI (there is very small chance that user using official web UI will be able to read one SMS of multi part SMS before it is able to recombine correctly).
So this is technically 'wontfix' since there is nothing i can do with huawei FW, BUT i think i have also came with hack how to prevent this from happening when using the huawei-lte-api
when polling SMS.
Lets say we have this untested code as a example of usage that will "trigger" this race-condition:
from huawei_lte_api.Session import Session
from huawei_lte_api.User import UserSession
from huawei_lte_api.Sms import Sms
from huawei_lte_api.enums.sms import BoxTypeEnum
while True:
try:
with Session('http://192.168.8.1') as session:
with UserSession('admin', 'admin'):
sms = Sms(session)
fetched_sms = sms.get_sms_list(1, BoxTypeEnum.LOCAL_INBOX, 1, 0, 0, 1)
# Check if we have any messages
if not fetched_sms.get('Messages'):
continue
message = fetched_sms.get('Messages', {}).get('Message', {})
message_index = int(message.get('Index'))
message_stat = int(message.get('Smstat'))
message_type = int(message.get('SmsType'))
message_content = message.get('Content')
# Skip read message
if message_stat == 1:
continue
# Process our SMS
print('You have new SMS:')
print(message_content)
# mark message read
sms.set_read(message_index)
except Exception as e:
print('Something failed: {}'.format(e))
time.sleep(60) # Check every minute
And here are changes (untested) to ~prevent that race condition by check if message is type==2 if is type 2 ignore it until is older then specified type (60 seconds) that should provide enough time for all parts to be received and merged:
import datetime
import aniso8601
from huawei_lte_api.Session import Session
from huawei_lte_api.User import UserSession
from huawei_lte_api.Sms import Sms
from huawei_lte_api.enums.sms import BoxTypeEnum
while True:
now = datetime.datetime.now()
try:
with Session('http://192.168.8.1') as session:
with UserSession('admin', 'admin'):
sms = Sms(session)
fetched_sms = sms.get_sms_list(1, BoxTypeEnum.LOCAL_INBOX, 1, 0, 0, 1)
# Check if we have any messages
if not fetched_sms.get('Messages'):
continue
message = fetched_sms.get('Messages', {}).get('Message', {})
message_index = int(message.get('Index'))
message_date = aniso8601.parse_datetime(message.get('Date'))
message_stat = int(message.get('Smstat'))
message_type = int(message.get('SmsType'))
message_content = message.get('Content')
# Skip read message
if message_stat == 1:
continue
# Check if message is possibly multipart,
# if it is ignore it if is younger then 60 seconds
# This way we provide the router with enough time to receive all possible parts and do correct rebuild
if message_type == 2 and message_date + datetime.timedelta(seconds=60) > now:
continue
# Process our SMS
print('You have new SMS:')
print(message_content)
# mark message read
sms.set_read(message_index)
except Exception as e:
print('Something failed: {}'.format(e))
time.sleep(60) # Check every minute
from huawei-lte-api.
I've figured as much, it's a very specific issue and I assume the firmware itself has similar code which will hold off triggering the "new message" flag until the message is recombined. That's why the the Type flag is there in the first place, I suppose.
I'll test out your proposed solution in coming days and report back. It wouldn't hurt to leave a note about this somewhere in the documentation.
from huawei-lte-api.
Proposed solution works as intended, the only issue is that aniso8601.parse_datetime
expects a "T" delimiter, whereas the API provides a space.
message_date = aniso8601.parse_datetime(msg_text.get('Date'), delimiter=' ')
from huawei-lte-api.
Yea i have expected there may be some small issue in datetime parsing.... hmm i think i can use simple datetime.strptime to parse this datetime format, it will save me one dependency
from huawei-lte-api.
Also is not 60 seconds too much? what delay between parted SMS did you observe?
from huawei-lte-api.
Related Issues (20)
- ResponseErrorException: 100006 for hardware CL2E3372HM HOT 8
- Reboot script HOT 1
- Switch Wifi on/off HOT 3
- Exception on log-out ResponseErrorWrongSessionToken: 125003: Wrong Session Token HOT 3
- Disabling automatic online updates HOT 3
- Quicksetup HOT 5
- Disabling IPv6 HOT 2
- Can't connect to my modem HOT 4
- Unable to connect to Huawei B535-333 with the error 125003 (Wrong token)
- Toggle VPN status HOT 7
- Can't enable telnet on device HOT 1
- Huawei E8231 also work HOT 1
- Error: 113004 HOT 1
- I ran the example but didn't work HOT 6
- Ping example?
- ussd request example HOT 6
- Accessing device remotely HOT 2
- How to make a basic mac filter ? HOT 10
- E3372 CL1E3372SM Ver.A api doesn't work HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from huawei-lte-api.