Page 231 - MDP2022-2
P. 231
rfid.PCD_StopCrypto1();
}
3. RPI 코드
const wsM = require('ws'); // WebSocket
const fs = require('fs');
const app = require('express')();
const {SerialPort} = require('serialport');
// HTTP
app.use("/site/", (req, res) => {
const data = url.decode(String(req._parsedUrl.href).slice(5));
res.sendFile(__dirname+'/'+data.substr(0,data.indexOf('?')!=-1?data.indexOf('?'):dat
a.length));
});
// WS
const wss = new wsM.Server({server: app.listen(8080)});
wss.on('connection', (ws, request)=>{
ws.on('message', (msg)=>{
msg = String(msg);
if(msg.startsWith('HELLO')){
ws.send('WORLD');
}
})
});
const STM = new SerialPort({ path: '/dev/ttyS0', baudRate: 115200 });
STM.on('open', () => {
STM.on('data', (data) => {
console.log(data);
});
});