master
louisa 2 years ago
parent 59c39d7304
commit 0cb83df278

@ -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');
}); });

782
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -18,9 +18,10 @@
"homepage": "https://github.com/louisafriederike/xpub_prototype_citynet#readme", "homepage": "https://github.com/louisafriederike/xpub_prototype_citynet#readme",
"dependencies": { "dependencies": {
"express": "^4.18.1", "express": "^4.18.1",
"johnny-five": "^2.1.0",
"package.js": "^1.1.3", "package.js": "^1.1.3",
"package.json": "^2.0.1", "package.json": "^2.0.1",
"serialport": "^10.4.0", "serialport": "^10.4.0",
"socket.io": "^4.5.0" "socket.io": "^4.6.2"
} }
} }

Loading…
Cancel
Save