zabsalahid / serialport-gsm

SerialPort-GSM is a simplified plugin for communicating with gsm modems. (Primarily for sms) (Focused in PDU mode)
MIT License
88 stars 46 forks source link

sendSMS stuck in 1st callback when no load? #119

Open k3ndro opened 1 year ago

k3ndro commented 1 year ago

Using Globe sim card in PH, when I ran out of load, it does not call the 2nd callback with result.status == 'fail' anymore. Instead, it is just stuck and won't trigger 2nd callback result.request = 'SendSMS' forever.

Any ideas?

This was perfectly working a few months ago until now. Is it a network thing? Also updating to 4.0.1 did not fix it either.

Using Sim800L V2

Really appreciate any response. Thank you 🙏

Apollon77 commented 1 year ago

Please add a logger to the call and provide a log

k3ndro commented 1 year ago

Hi thanks for your attention @Apollon77

| Modem Received: 
| Ignore Data: 
| Modem Received: OK
| Ignore Data: OK
| Signal S: 53 - Q: 30
| Modem Received: AT+CNUM
| Activate Message Processing for: AT+CNUM
| Modem Received: 
| Modem Received: +CNUM: "","+639662539476",145,0,4
| Call callback for: AT+CNUM
| Modem Received: 
| Modem Received: OK
| Own number: +639662539476

Callback Send: Message ID: {"status":"success","request":"sendSMS","data":{"messageId":"KC8wwXyyIsgqrFaYCorBKYaTr","response":"Successfully Sent to Message Queue"}}
 Modem Write: AT+CMGD=1,4

| Modem Received: AT+CMGD=1,4
| Activate Message Processing for: AT+CMGD=1,4
| Modem Received: 
| Modem Received: OK
| Call callback for: AT+CMGD=1,4
| Modem Write: AT+CMGS=117
| Modem Received: AT+CMGS=117
| Activate Message Processing for: AT+CMGS=117
| Modem Received: 
| Modem Write: 0001000B919071553809F800007631500B046ABFE565101D1D76836236980BD40CE7C565101D9D9E83DEEE32E89E66B341EDF0BA0C4AD3413218EC5D77D341E3307B5C6787E96F39888E0ED34F73D01C549F975DA0106024286D2826152A1593CD6A341B2E77836D7A5FDD89C5F3B15CAFDFAA158900
| Modem Received: > 0001000B919071553809F800007631500B046ABFE565101D1D76836236980BD40CE7C565101D9D9E83DEEE32E89E66B341EDF0BA0C4AD3413218EC5D77D341E3307B5C6787E96F39888E0ED34F73D01C549F975DA0106024286D2826152A1593CD6A341B2E77836D7A5FDD89C5F3B15CAFDFAA158900
| Modem Received: > 
| Modem Received: +CMS ERROR: 17

`

Looks like CMS ERROR: 17.

But when I start loading this sim and then reinitialize, it's back to sending successfully.

Apollon77 commented 1 year ago

Can you please also show the relevant piece of javascript code?

k3ndro commented 1 year ago

Yes, this is the method where I call on sendSMS.

  sendMessage(item: ISMS, modem: IModem) {
        return new Promise((resolve, reject) => {
            try {
                modem.gsmModem.deleteAllSimMessages();
            } catch (e) {
                console.log(`delete error: ${e}`);
            }
            // Finally send an SMS

            try {
                console.log(`phone ${item.phone} msg: ${item.message}`);

                modem.gsmModem.sendSMS(item.phone, `${item.message}`, false, (result: any) => {
                        // console.log(`Callback Send: Message ID: ${result.data.messageId},` +
                        //     `${result.data.response} To: ${result.data.recipient} ${JSON.stringify(result)}`);

                        console.log(`Callback Send: Message ID: ${JSON.stringify(result)}`);

                        // this callback is called twice
                        // if result.request == 'sendSMS' <- means it's still preparing to send (queued for sending), result.request == 'SendSMS' is expected, means message is sent
                        // if result.data.response == "Message Failed +CMS ERROR: 515", then no load
                        // if result.data.response == "Message Failed +CMS ERROR: 302", more than 140 characters

                        // done sending
                        if (result.request == this.globalsService.DONE_PROCESS_SMS) { // 'SendSMS'
                            if (result.status == this.globalsService.SUCCESS) { // 'success'
                                console.log(`Message SENT! ${item.idstamp}`);

                                if (result.data.response) resolve(result.data.response);
                                else resolve('');
                            } else {
                                // if failed, then just repeat sending.
                                console.log(`Message FAILED! ${item.idstamp}`);
                                reject(result.data.response);
                            }

                            // if stored messageID is detected here, then naay load
                            // delete
                        }
                    },
                );
            } catch (e) {
                console.log(`caught error: ${e} - maybe re-initialize?`);
            }
        });
    }
k3ndro commented 1 year ago

Based on the logs, it looks like sendSMS cannot get to the second callback if the error is CMS ERROR 17. Maybe we can do some sort of handling? Thanks

blackchineykh commented 1 year ago

Any updates on this?

Apollon77 commented 1 year ago

@blackchineykh Are you affected too? Same error? log?

Apollon77 commented 1 year ago

Ok @k3ndro here we go :-) Please try my fork branch where I did a fix. I was able to test it with a success case but I cannot test with an error befause no idea how to force one :-)

Please use npm i Apollon77/serialport-gsm#sendfix to install the version from my branch and give feedback. in all cases (also if it works) a full debug log like above would be interesting to check everything

Apollon77 commented 1 year ago

@k3ndro @blackchineykh Hello, Any chance that you check if my branch fixed the issue?

k3ndro commented 1 year ago

Hi @Apollon77, sorry for the late reply. Really appreciate the follow-up. I stopped working on the project since it looks like new sim card laws in the Philippines are restricting us from moving forward with GSM modules. :(

Yes, I did try this branch, but still the same. A CMS Error 34 still does not trigger the second callback.

Apollon77 commented 1 year ago

Could you please post the full debug log again? (with the version from the branch)

Apollon77 commented 1 year ago

@k3ndro did you had any chance to get a nNEW debug log with the branch version?

blackchineykh commented 10 months ago

@k3ndro did you had any chance to get a nNEW debug log with the branch version?

I tried but it made things worse for me and doesnt send and just eventually has a timeout

Modem Write: AT+CMGS=18
Modem Write Data: 0001000B918167747074F8000005C8329BFD06
Modem Received: AT+CMGS=18
Activate Message Processing for: AT+CMGS=18
Modem:18763617900:COM10 - Modem event Sending Message: {"status":"Sending SMS","request":"sendingSMS","data":{"messageId":"V000QV3GZa6QNa3m3C6sb3H25","message":"Hello","recipient":"12341234567","response":"Message Currently Sending"}}
Modem Received:
Command Response timed out: AT+CMGS=18
Apollon77 commented 10 months ago

@blackchineykh ok with these infos. I can not do anything honestly. Please provide more log and also what you expected and what it did