Commit 1d6334a9bf44e972f534cb11fd6552c5329477be
1 parent
fded2e0c7f
Exists in
master
Coba sms error
Showing 3 changed files with 18 additions and 2 deletions Side-by-side Diff
lib/modem-commands/index.js
... | ... | @@ -245,7 +245,12 @@ function sendCMGSPdu(pduLength) { |
245 | 245 | |
246 | 246 | exports.sendSMS = function sendSMS(destination, msg) { |
247 | 247 | return new Promise(async (resolve) => { |
248 | + async function responseHandler(data) { | |
249 | + logger.verbose('SMS sent callback called', { data }); | |
250 | + } | |
251 | + | |
248 | 252 | await mutex.lock(MUTEX_COMMAND, 'sendSMS'); |
253 | + parsers.setSmsSentCallback(responseHandler); | |
249 | 254 | |
250 | 255 | if (!destination || !destination.trim()) { |
251 | 256 | resolve(false); |
... | ... | @@ -268,7 +273,7 @@ exports.sendSMS = function sendSMS(destination, msg) { |
268 | 273 | submit.getType().setSrr(0); |
269 | 274 | |
270 | 275 | await sendCMGSPdu(Math.floor(submit.toString().length / 2) - 1); |
271 | - await writeToPort(`${submit.toString()}${CTRLZ}`); | |
276 | + await writeToPortAndWaitForOkOrError(`${submit.toString()}${CTRLZ}`, MUTEX_SUBCOMMAND); | |
272 | 277 | |
273 | 278 | mutex.unlock(MUTEX_COMMAND, 'sendSMS'); |
274 | 279 | resolve(true); |
lib/serialport-parsers.js
... | ... | @@ -29,6 +29,12 @@ function setUssdCallback(cb) { |
29 | 29 | } |
30 | 30 | exports.setUssdCallback = setUssdCallback; |
31 | 31 | |
32 | +let smsSentCallback = null; | |
33 | +function setSmsSentCallback(cb) { | |
34 | + smsSentCallback = cb; | |
35 | +} | |
36 | +exports.setSmsSentCallback = setSmsSentCallback; | |
37 | + | |
32 | 38 | function isAlphaNumeric(str) { |
33 | 39 | const len = str.length; |
34 | 40 | // eslint-disable-next-line no-plusplus |
... | ... | @@ -156,12 +162,15 @@ parserReadline.on('data', (data) => { |
156 | 162 | logger.verbose('Got a new message notification report', { data: data.toString() }); |
157 | 163 | } else if (isResultCodeIs(data, 'CUSD')) { |
158 | 164 | logger.verbose('Got a USSD command response', { data: data.toString() }); |
159 | - if (ussdCallback && typeof ussdCallback === 'function') { | |
165 | + if (typeof ussdCallback === 'function') { | |
160 | 166 | logger.verbose('Calling USSD callback'); |
161 | 167 | ussdCallback(data.toString()); |
162 | 168 | } else { |
163 | 169 | logger.verbose('Skip unwanted USSD response'); |
164 | 170 | } |
171 | + } else if (isResultCodeIs(data, 'CMGS')) { | |
172 | + logger.verbose('Got CMGS report', { data: data.toString() }); | |
173 | + if (typeof smsSentCallback === 'function') smsSentCallback(data.toString()); | |
165 | 174 | } |
166 | 175 | }); |
167 | 176 |
modem-tester.js
... | ... | @@ -36,6 +36,8 @@ const port = new SerialPort(config.modem.device, { baudRate: 115200 }, async (er |
36 | 36 | // await modemCommands.sendSMS('628128364883', `coba pakai pdu ${new Date()}`); |
37 | 37 | // await modemCommands.sendSMS('+6282210008543', `coba pakai pdu ${new Date()}`); |
38 | 38 | // await modemCommands.sendSMS('6281809903333', `coba pakai pdu ${new Date()}`); |
39 | + await modemCommands.sendSMS('999', `coba pakai pdu ${new Date()}`); | |
40 | + | |
39 | 41 | // const ussdResponse = await modemCommands.executeUSSD('*888#', 2); |
40 | 42 | // logger.info('USSD RESPONSE', { ussdResponse }); |
41 | 43 |