Commit d59f00d514b8def0ad3c2f0e161d1e622662374b
1 parent
9375bab1c4
Exists in
master
coba minimalisir regex
Showing 4 changed files with 57 additions and 1 deletions Side-by-side Diff
lib/modem.js
... | ... | @@ -2,7 +2,8 @@ |
2 | 2 | |
3 | 3 | const INTERVAL_BEETWEN_SIGNAL_STRENGTH_MS = 60000; |
4 | 4 | const MAX_LAST_DATA_AGE_MS = 3 * 60 * 1000; |
5 | -const REGEX_WAIT_FOR_OK_OR_ERROR = /\n(?:OK|ERROR)\r\n/; | |
5 | +// const REGEX_WAIT_FOR_OK_OR_ERROR = /\n(?:OK|ERROR)\r\n/; | |
6 | +const REGEX_WAIT_FOR_OK_OR_ERROR = /(?:OK|ERROR)\r/; | |
6 | 7 | |
7 | 8 | const moment = require('moment'); |
8 | 9 | const SerialPort = require('serialport'); |
package-lock.json
... | ... | @@ -80,6 +80,11 @@ |
80 | 80 | "resolved": "https://registry.npmjs.org/@serialport/parser-delimiter/-/parser-delimiter-2.0.2.tgz", |
81 | 81 | "integrity": "sha512-zB02LahFfyZmJqak9l37vP/F1K+KCUxd1KQj35OhD1+0q/unMjVTZmsfkxFSM4gkaxP9j7+8USk+LQJ3V8U26Q==" |
82 | 82 | }, |
83 | + "@serialport/parser-inter-byte-timeout": { | |
84 | + "version": "1.1.0", | |
85 | + "resolved": "https://registry.npmjs.org/@serialport/parser-inter-byte-timeout/-/parser-inter-byte-timeout-1.1.0.tgz", | |
86 | + "integrity": "sha512-FHJGjRzgnNsMP2mzyfnbFBd0Kh6abyXX4e0zwVfN1zmeIPc05CjXSomuy9c8qH4EzaASHosNGjDpisw/aL+53g==" | |
87 | + }, | |
83 | 88 | "@serialport/parser-readline": { |
84 | 89 | "version": "2.0.2", |
85 | 90 | "resolved": "https://registry.npmjs.org/@serialport/parser-readline/-/parser-readline-2.0.2.tgz", |
package.json
tools/parser-test.js
... | ... | @@ -0,0 +1,49 @@ |
1 | +'use strict'; | |
2 | + | |
3 | +/* eslint-disable no-console */ | |
4 | + | |
5 | +const devicePath = '/dev/ttyUSB0'; | |
6 | + | |
7 | +const moment = require('moment'); | |
8 | +const SerialPort = require('serialport'); | |
9 | + | |
10 | +console.log(Buffer.from('OK')); | |
11 | +console.log(Buffer.from('\r')); | |
12 | +console.log(Buffer.from('\n')); | |
13 | +console.log(Buffer.from('\x1a')); | |
14 | +console.log(Buffer.from([0x1A])); | |
15 | + | |
16 | +const InterByteTimeout = require('@serialport/parser-inter-byte-timeout') | |
17 | +// const Delimiter = require('@serialport/parser-delimiter'); | |
18 | +const ParserReadline = require('@serialport/parser-readline'); | |
19 | + | |
20 | + | |
21 | +const port = new SerialPort(devicePath, { baudRate: 115200 }); | |
22 | + | |
23 | +const parserReadline = new ParserReadline(); | |
24 | +parserReadline.on('data', (data) => { | |
25 | + console.log(`READLINE: ${data}`); | |
26 | +}); | |
27 | + | |
28 | +port.pipe(parserReadline); | |
29 | + | |
30 | +const parserInterByteTimeout = new InterByteTimeout({ interval: 1000 }); | |
31 | +parserInterByteTimeout.on('data', (data) => { | |
32 | + console.log('INTERBYTETIMEOUT:'); | |
33 | + console.log(data); | |
34 | +}); | |
35 | +// port.pipe(parserInterByteTimeout); | |
36 | + | |
37 | + | |
38 | +port.on('open', () => { | |
39 | + console.log('====='); | |
40 | + port.write('ATE0\r') | |
41 | + // port.write('AT+CIMI\r'); | |
42 | + // port.write('OK'); | |
43 | + port.write('AT\r'); | |
44 | + port.write('AT+CMGF=1\r'); | |
45 | + port.write('AT+CMGS="+6282210008543"\r'); | |
46 | + port.write(`Coba dari parser-test ${moment().format('HHmmss')}`); | |
47 | + port.write(Buffer.from('\x1a')); | |
48 | + | |
49 | +}); |