diff --git a/index.js b/index.js index 3434744..7437f24 100755 --- a/index.js +++ b/index.js @@ -4,6 +4,8 @@ const express = require('express'); const app = express(); const fileUpload = require('express-fileupload'); +const fetch = require('node-fetch'); + app.use(express.json()); app.use(fileUpload()); @@ -141,6 +143,24 @@ app.post("/playoverlay", (req, res) => { res.json({ status: 'ok' }); }); +app.post("/startprojector", (req, res) => { + require('child_process').spawn('sudo', ['/home/pi/video-player/start-projector.sh']); + res.json({ status: 'ok' }); +}); + +app.post("/stopprojector", (req, res) => { + require('child_process').spawn('sudo', ['/home/pi/video-player/stop-projector.sh']); + res.json({ status: 'ok' }); +}); + +app.get("/projectorstatus", async (req, res) => { + const res1 = await fetch('http://192.168.1.93/api/v01/control/escvp21?cmd=PWR?'); + const status1 = await res1.text(); + const res2 = await fetch('http://192.168.1.67/api/v01/control/escvp21?cmd=PWR?'); + const status2 = await res2.text(); + res.json({ status1, status2 }); +}); + app.post('/upload', function (req, res) { if (!req.files || Object.keys(req.files).length === 0) { diff --git a/package.json b/package.json old mode 100644 new mode 100755 index 7e4cfda..38b39c9 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "express": "^4.18.3", - "express-fileupload": "^1.5.0" + "express-fileupload": "^1.5.0", + "node-fetch": "^2.7.0" } } diff --git a/public/index.html b/public/index.html index 26ba665..834841a 100755 --- a/public/index.html +++ b/public/index.html @@ -33,6 +33,12 @@