diff --git a/Dockerfile.template b/Dockerfile.template index 9d65db0..cd843e3 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -12,6 +12,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ x11-xserver-utils \ scrot \ wget \ + jq \ + htop \ + nmap \ snmp snmpd \ dbus && \ apt-get clean && rm -rf /var/lib/apt/lists/* diff --git a/app/hwcontrol.js b/app/hwcontrol.js index af1c074..8dfc464 100644 --- a/app/hwcontrol.js +++ b/app/hwcontrol.js @@ -84,6 +84,27 @@ function getBalenaRelease() { }); } +function getBalenaName() { + return new Promise((resolve, reject) => { + exec( + 'curl -X GET --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/device/name?apikey=$BALENA_SUPERVISOR_API_KEY"', + (error, stdout, stderr) => { + if (error) { + //console.log(`error: ${error.message}`); + resolve(false); + return; + } + if (stderr) { + //console.log(`stderr: ${stderr}`); + //resolve(stderr); + //return; + } + resolve(IsJsonString(stdout)); + } + ); + }); +} + function pjlinkSet(ip, command) { return new Promise(async (resolve, reject) => { const projector = new PJLink(ip, 4352); @@ -170,6 +191,12 @@ module.exports = { resolve(result); }); }, + getBalenaName: async function () { + return new Promise(async (resolve, reject) => { + let result = await getBalenaName(); + resolve(result); + }); + }, setBalenaRestart: async function (timeout) { //todo: add timeout as delay diff --git a/app/routes.js b/app/routes.js index 9181d59..da55696 100644 --- a/app/routes.js +++ b/app/routes.js @@ -6,10 +6,14 @@ module.exports = function (app) { app.get("/status", async function (req, res) { if (DEBUG) console.log("[API] get status"); var balenaData = await control.getBalenaData(); - var screenData = await control.getMonitorStatus(); - var sleepState; - var displayState; //on,off,mixed - res.send({ success: true, error: null, data: { balenaData, screenData } }); + var deviceName = await control.getBalenaName(); + if (deviceName.hasOwnProperty("deviceName")) deviceName = deviceName.deviceName; + //var screenData = await control.getMonitorStatus(); + var appName = process.env.BALENA_APP_NAME; + var deviceType = process.env.BALENA_DEVICE_TYPE; + var deviceUUID = process.env.BALENA_DEVICE_UUID; + + res.send({ success: true, error: null, data: { balenaData, appName, deviceName, deviceType, deviceUUID } }); }); app.post("/shutdown", async function (req, res) { if (DEBUG) console.log("[API] post shutdown");