zabsalahid / serialport-gsm

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

CPIN stalls on E173 modem - with possible fix. #98

Closed ieb closed 2 years ago

ieb commented 2 years ago

https://github.com/zabsalahid/serialport-gsm/blob/4fc08fb8874b48e6b714631884efab3493c6c45a/lib/functions/modem.js#L948

adding item.inProgress = true; just before this line seems to ensure that responses where the command is not echoed and is not immediately OK work on a E173 modem.

Without this fix:

Modem Sucessfully Opened
Modem Write: ATZ
Modem Received: 
Modem Received: OK
Call callback for: ATZ
Modem Write: ATE1
Modem Received: 
Modem Received: OK
Call callback for: ATE1
Checking PIN
Modem Write: AT+CPIN?
Modem Received: 
Ignore Data: 
Modem Received: +CPIN: READY
Ignore Data: +CPIN: READY
Modem Received: 
Ignore Data: 
Modem Received: OK
Ignore Data: OK
Failed Initialise modem Error: timeout: 
{"_events":{},"_eventsCount":1,"command":"AT+CPIN?","add_time":"2022-01-13T08:41:12.984Z","id":4,"timeout":60000,"execute_time":"2022-01-13T08:41:12.985Z"}
Modem Errror Error: timeout: 
{"_events":{},"_eventsCount":1,"command":"AT+CPIN?","add_time":"2022-01-13T08:41:12.984Z","id":4,"timeout":60000,"execute_time":"2022-01-13T08:41:12.985Z"}
    at EventEmitter.<anonymous> (/home/pi/tracker/node_modules/serialport-gsm/lib/functions/modem.js:864:27)
    at EventEmitter.emit (events.js:314:20)
    at Timeout._onTimeout (/home/pi/tracker/node_modules/serialport-gsm/lib/functions/modem.js:944:14)

After patching

Modem Sucessfully Opened
Adding Logic for  ATZ
Modem Write: ATZ
Modem Received: 
Modem Received: OK
Call callback for: ATZ
Adding Logic for  ATE1
Modem Write: ATE1
Modem Received: 
Modem Received: OK
Call callback for: ATE1
Checking PIN
Adding Logic for  AT+CPIN?
Modem Write: AT+CPIN?
Modem Received: 
Modem Received: +CPIN: READY
Call callback for: AT+CPIN?
Modem Received: 
Modem Received: OK
Adding Logic for  AT+CMEE=1;+CREG=2
Adding Logic for  AT+CLIP=1
InitModemResponse: {"status":"success","request":"modemInitialized","data":"Modem Successfully Initialized"}
Adding Logic for  AT+CMGF=1
Modem Write: AT+CMEE=1;+CREG=2
Modem Received: 
Modem Received: OK
Call callback for: AT+CMEE=1;+CREG=2
Modem Write: AT+CLIP=1
Modem Received: 
Modem Received: OK
Call callback for: AT+CLIP=1
Modem Write: AT+CMGF=1
Modem Received: 
Modem Received: OK
Call callback for: AT+CMGF=1
Set Modem Mode Modem Result: {"status":"success","request":"modemMode","data":"SMS_Mode"}
Adding Logic for  AT
Modem Write: AT
Modem Received: 
Modem Received: OK
Call callback for: AT
Check Modem Result: {"status":"success","request":"checkModem","data":"Modem Available"}

If the E173 had echoed the command, I think it would have not stuck and timed out, the E173 doesn't appear to echo commands, hence the hang.

ieb commented 2 years ago

Modem was in a bad state, after powering down and up again it didn't need the fix. Please ignore the noise.