Skip to content

Commit

Permalink
fix(server) remove display info from status
Browse files Browse the repository at this point in the history
feat(hwcontrol) add balena name get
feat(server) status api add some device values
  • Loading branch information
smarthomeagentur committed Dec 17, 2023
1 parent e400111 commit 377f3ca
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand Down
27 changes: 27 additions & 0 deletions app/hwcontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 377f3ca

Please sign in to comment.