|
|
@ -10,6 +10,8 @@ var port = 8000;
|
|
|
|
const { SerialPort } = require('serialport')
|
|
|
|
const { SerialPort } = require('serialport')
|
|
|
|
const { ReadlineParser } = require('@serialport/parser-readline')
|
|
|
|
const { ReadlineParser } = require('@serialport/parser-readline')
|
|
|
|
const sport = new SerialPort({ path: '/dev/ttyACM0', baudRate: 115200 })
|
|
|
|
const sport = new SerialPort({ path: '/dev/ttyACM0', baudRate: 115200 })
|
|
|
|
|
|
|
|
const five = require('johnny-five');
|
|
|
|
|
|
|
|
const board = new five.Board();
|
|
|
|
|
|
|
|
|
|
|
|
const parser = sport.pipe(new ReadlineParser({ delimiter: '\r\n' }))
|
|
|
|
const parser = sport.pipe(new ReadlineParser({ delimiter: '\r\n' }))
|
|
|
|
parser.on('data', console.log)
|
|
|
|
parser.on('data', console.log)
|
|
|
@ -20,7 +22,27 @@ server.listen(port, () => {
|
|
|
|
|
|
|
|
|
|
|
|
app.use(express.static(path.join(__dirname, "public")));
|
|
|
|
app.use(express.static(path.join(__dirname, "public")));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
board.on('ready', function() {
|
|
|
|
|
|
|
|
const led = new five.Led(13); // Assuming LED connected to GPIO 13 (D13)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Emit 'blink' event to clients when the LED turns on
|
|
|
|
|
|
|
|
led.on('on', function() {
|
|
|
|
|
|
|
|
io.emit('blink');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Emit 'stop' event to clients when the LED turns off
|
|
|
|
|
|
|
|
led.on('off', function() {
|
|
|
|
|
|
|
|
io.emit('stop');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Function to blink the LED
|
|
|
|
|
|
|
|
function blinkLed() {
|
|
|
|
|
|
|
|
led.blink(500); // Blink every 500 milliseconds
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start blinking the LED
|
|
|
|
|
|
|
|
blinkLed();
|
|
|
|
|
|
|
|
});
|
|
|
|
// var server = http.createServer(function(req, res){
|
|
|
|
// var server = http.createServer(function(req, res){
|
|
|
|
|
|
|
|
|
|
|
|
// res.writeHead(200, {'Content-Type':'text/html'});
|
|
|
|
// res.writeHead(200, {'Content-Type':'text/html'});
|
|
|
@ -42,7 +64,7 @@ io.on('connection', function(socket){
|
|
|
|
console.log('Node.js is listening!!');
|
|
|
|
console.log('Node.js is listening!!');
|
|
|
|
socket.on("hello", (arg, callback) => {
|
|
|
|
socket.on("hello", (arg, callback) => {
|
|
|
|
console.log("hellohelo"); // "world"
|
|
|
|
console.log("hellohelo"); // "world"
|
|
|
|
io.emit('world');
|
|
|
|
io.emit('blink');
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|