Skip to content

Commit

Permalink
Added sysinfo variables for use with supportconfig plan on #377
Browse files Browse the repository at this point in the history
  • Loading branch information
petervanderwalt committed Dec 5, 2024
1 parent 84c1707 commit bee5e52
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 30 deletions.
7 changes: 6 additions & 1 deletion app/js/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var grblParams = {}
var smoothieParams = {}
var nostatusyet = true;
var safeToUpdateSliders = false;
var laststatus
var laststatus, lastsysinfo
var simstopped = false;
var bellstate = false;
var toast = Metro.toast.create;
Expand Down Expand Up @@ -555,6 +555,11 @@ function initSocket() {
}
});

socket.on('sysinfo', function(sysinfo) {
console.log(sysinfo)
lastsysinfo = sysinfo;
});

socket.on('status', function(status) {

if (nostatusyet) {
Expand Down
121 changes: 94 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ var lastCommand = false
var gcodeQueue = [];
var queuePointer = 0;
var statusLoop;
var frontEndUpdateLoop
var frontEndUpdateLoop, sysinfoUpdateLoop

var queueCounter;
var listPortsLoop;
Expand Down Expand Up @@ -680,47 +680,27 @@ io.on("connection", function(socket) {

debug_log("New IO Connection ");

io.sockets.emit("sysinfo", systemInformation);

iosocket = socket;

if (status.machine.firmware.type == 'grbl') {

debug_log("Is Grbl");


// // handle Grbl RESET external input
// if (status.machine.inputs.length > 0) {
// for (i = 0; i < status.machine.inputs.length; i++) {
// switch (status.machine.inputs[i]) {
// case 'R':
// // debug_log('PIN: SOFTRESET');
// safetosend = true;
// break;
// }
// }
// } else {
// setTimeout(function() {
debug_log("Emit Grbl: 1");
io.sockets.emit('grbl', status.machine.firmware)
// }, 10000);
// }
//
// if (safetosend != undefined && safetosend == true) {
// setTimeout(function() {
// debug_log("Emit Grbl: 2");
// io.sockets.emit('grbl', status.machine.firmware)
// }, 10000);
// }

}


// Global Update loop
clearInterval(frontEndUpdateLoop);
frontEndUpdateLoop = setInterval(function() {
io.sockets.emit("status", status);
}, 100);

clearInterval(sysinfoUpdateLoop);
sysinfoUpdateLoop = setInterval(function() {
io.sockets.emit("sysinfo", systemInformation);
}, 1000 * 60);

socket.on("scannetwork", function(data) {
scanForTelnetDevices(data)
})
Expand Down Expand Up @@ -3948,5 +3928,92 @@ function friendlyPort(port) {

// End USB Port details

// System Info on startup

const os = require('os');
const si = require('systeminformation');

var systemInformation;

async function getSystemInfo() {
// Basic OS and hardware details
const osType = os.type(); // 'Linux', 'Darwin' (Mac), 'Windows_NT'
const osPlatform = os.platform(); // 'win32', 'linux', 'darwin', etc.
const osRelease = os.release(); // OS version
const arch = os.arch(); // 'x64', 'arm', 'arm64', etc.
const totalMemory = os.totalmem();
const networkInterfaces = os.networkInterfaces();
const cpu = os.cpus();

// Additional system information using systeminformation
const [baseboard, graphics, osInfo] = await Promise.all([
si.baseboard(),
si.graphics(),
si.osInfo()
]);

// Prepare systemInformation JSON object
systemInformation = {
operatingSystem: {
type: osType,
platform: osPlatform,
release: osRelease,
arch: arch,
distro: osInfo.distro || "N/A",
version: osInfo.release || "N/A",
codename: osInfo.codename || "N/A",
},
hardware: {
cpu: cpu.map(core => ({
model: core.model,
speed: core.speed, // in MHz
times: core.times
})),
motherboard: {
manufacturer: baseboard.manufacturer,
model: baseboard.model,
version: baseboard.version,
serialNumber: baseboard.serial,
},
gpu: graphics.controllers.map(gpu => ({
model: gpu.model,
vendor: gpu.vendor,
vram: gpu.vram, // in MB
bus: gpu.bus
})),
memory: {
total: (totalMemory / 1024 / 1024 / 1024).toFixed(2) + " GB",
free: (os.freemem() / 1024 / 1024 / 1024).toFixed(2) + " GB",
},
},
network: Object.keys(networkInterfaces).map(iface => ({
interface: iface,
addresses: networkInterfaces[iface].map(addr => ({
address: addr.address,
family: addr.family,
internal: addr.internal,
})),
})),
};

// Timer to update free memory every minute
setInterval(() => {
systemInformation.hardware.memory.free = (os.freemem() / 1024 / 1024 / 1024).toFixed(2) + " GB";
}, 60000); // 60,000 ms = 1 minute

// Log the initial systemInformation object
console.log(JSON.stringify(systemInformation, null, 2));

// Return the systemInformation object (if needed for further use)
io.sockets.emit("sysinfo", systemInformation);

return systemInformation;
}

// Call the function
getSystemInfo().catch(err => console.error("Error retrieving system information:", err));


// End system info on startup

process.on('exit', () => debug_log('exit'))
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"node-gyp": "^9.3.1",
"serialport": "^12.0.0",
"socket.io": "^4.6.1",
"systeminformation": "^5.23.5",
"xmodem.js": "^0.1.0"
},
"main": "index.js",
Expand Down Expand Up @@ -58,7 +59,7 @@
"category": "public.app-category.graphics-design",
"entitlements": "build/entitlements.mac.plist",
"entitlementsInherit": "build/entitlements.mac.plist",
"hardenedRuntime":true,
"hardenedRuntime": true,
"gatekeeperAssess": false,
"notarize": false,
"target": {
Expand Down Expand Up @@ -138,7 +139,9 @@
],
"win": {
"sign": "./signWin.js",
"signingHashAlgorithms": ["sha256"],
"signingHashAlgorithms": [
"sha256"
],
"target": [
{
"target": "nsis",
Expand Down

0 comments on commit bee5e52

Please sign in to comment.