Added projector start stop and status

other
Filip Borum Poulsen 1 year ago
parent 31bb849cd6
commit 5538f75472

@ -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) {

@ -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"
}
}

@ -33,6 +33,12 @@
<h2>Overlay video</h2>
<div id="overlayvideos"></div>
<button id="play" onclick="fetch(`/playoverlay`, { method: 'POST' });">Play Overlay now</button>
<h2>Projector status 1</h2>
<div id="projectorstatus1"></div>
<h2>Projector status 2</h2>
<div id="projectorstatus2"></div>
<button onclick="fetch(`/startprojector`, { method: 'POST' });">Start projectors</button>
<button onclick="fetch(`/stopprojector`, { method: 'POST' });">Stop projectors</button>
<script src="/main.js"></script>
</body>
</html>

@ -25,6 +25,15 @@ async function main() {
});
overlayVideoDiv.appendChild(overlayButton);
}
const res = await fetch('/projectorstatus');
const status = await res.json();
const status1 = document.getElementById('projectorstatus1');
const status2 = document.getElementById('projectorstatus2');
status1.textContent = status.status1;
status2.textContent = status.status2;
}
main();

Loading…
Cancel
Save