Skip to content

Instantly share code, notes, and snippets.

@akazakou
Created November 13, 2024 00:39
Show Gist options
  • Save akazakou/68eae5505f9f98ae49d014c1b9b7df7b to your computer and use it in GitHub Desktop.
Save akazakou/68eae5505f9f98ae49d014c1b9b7df7b to your computer and use it in GitHub Desktop.
There is small Node.js script to make fans on the X10DSC+ motherboard more silent to allow use servers based on that motherboard to be used in the home solutions.
#!/usr/bin/env node
const { exec } = require('child_process');
// IPMI credentials and host
const ipmiHost = '192.168.86.214';
const ipmiUser = 'ADMIN';
const ipmiPass = 'ADMIN';
// Variables to hold the average temperature and the flag for high temperature
let averageTemp = 0;
let isTempAbove80 = false; // Additional flag to check for temperatures over 80 degrees
// Function to parse the temperature from ipmiutil sensor output
function parseTemperatures(output) {
const lines = output.split('\n');
let tempSum = 0;
let tempCount = 0;
isTempAbove80 = false; // Reset the flag on each parse
lines.forEach(line => {
const match = line.match(/\|\s+OK\s+\|\s+([\d\.]+)\s+C/);
if (match) {
const temp = parseFloat(match[1]);
if (!isNaN(temp)) {
tempSum += temp;
tempCount++;
if (temp > 80) {
isTempAbove80 = true; // Update the flag if temperature exceeds 80 degrees
}
}
}
});
if (tempCount > 0) {
averageTemp = tempSum / tempCount;
console.log(`Average Temperature: ${averageTemp.toFixed(2)}°C`);
} else {
console.error('Failed to parse temperatures.');
}
}
// Function to get temperatures every 10 seconds
function updateTemperatures() {
const cmd = `ipmiutil sensor -N ${ipmiHost} -U ${ipmiUser} -P ${ipmiPass} -g temperature -c`;
exec(cmd, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing ipmiutil sensor: ${error.message}`);
return;
}
parseTemperatures(stdout);
});
}
// Function to control fans based on temperature readings
function controlFans() {
const cmdLow = 'ipmitool raw 0x30 0x70 0x66 0x01 0x00 0x10';
const cmdHigh = 'ipmitool raw 0x30 0x30 0x01 0x00';
// Command selection based on average temperature or any temperature above 80 degrees
const commandToExecute = isTempAbove80 || averageTemp >= 50 ? cmdHigh : cmdLow;
exec(commandToExecute, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing fan control command: ${error.message}`);
}
// Optional: Uncomment the line below to see fan control command outputs
// console.log(stdout || stderr);
});
}
// Initial temperature update
updateTemperatures();
// Schedule temperature updates every 10 seconds
setInterval(updateTemperatures, 10000);
// Schedule fan control every 200 milliseconds
setInterval(controlFans, 200);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment