Last active
October 25, 2017 07:55
-
-
Save zoutepopcorn/c4fb040f1d4b3912f7aff7a957d5e1b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//nano /boot/cmdline.txt -> verander console | |
//const NR = "0600000000"; | |
const SerialPort = require('serialport'); | |
const Readline = SerialPort.parsers.Readline; | |
const port = new SerialPort('/dev/serial0', { | |
baudRate: 115200 | |
}); | |
const parser = port.pipe(new Readline({ delimiter: '\n' })); | |
const cmd = { | |
SMS_ON : "AT+CMGF=1\r\n", | |
SMS_HEAD : "AT+CMGS=", | |
CTR_Z : String.fromCharCode(0x1A), | |
BR : "\r\n" | |
} | |
const stat = { | |
INIT : 0, | |
SMS_SET : 1, | |
SMS_CMD : 2, | |
SMS_TEXT: 3, | |
SMS_SEND : 4 | |
} | |
let status = stat.INIT; | |
console.log("STARTING"); | |
wl = (cmd) => { | |
port.write(`${cmd}\r\n`) | |
} | |
sms = (nr, msg) => { | |
port.write(`${cmd.SMS_HEAD}\"${nr}\"${cmd.BR}`); | |
// port.write(msg); | |
// port.write(cmd.CTR_Z); | |
// port.write(cmd.BR); | |
} | |
port.open(function (err) { | |
console.log("OPEN"); | |
port.write(cmd.SMS_ON); | |
// wl(`ATD${NR}`); | |
}); | |
// New lines | |
parser.on('data', (data) => { | |
if(data.indexOf("OK") == 0) { | |
console.log("ok"); | |
if(status == stat.INIT) { | |
console.log("init"); | |
status = stat.SMS_SET; | |
status = stat.SMS_CMD; | |
sms(NR, "goede smooooorgenst"); | |
} | |
} | |
console.log(data); | |
}); | |
port.on('data', (data) => { | |
dat = data.toString(); | |
console.log(dat); | |
if(status == stat.SMS_CMD && dat.indexOf(">") > 0) { | |
status = stat.SMS_TEXT; | |
port.write("hallo"); | |
port.write(cmd.CTR_Z); | |
port.write(cmd.BR); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment