Premium Only Content

Controlling a HVAC Relay With a NodeJS Web Server and a Raspberry Pi
In this video I control a HVAC relay using a Raspberry Pi and a NodeJS web server.
Prerequisite:
https://rumble.com/v4auyje-controlling-a-type-b-plug-with-a-hvac-relay-and-a-raspberry-pi.html
Run your server at start up:
https://rumble.com/v4ayapn-how-to-run-a-command-at-start-up-on-raspberry-pi-os.html
<code>
#!/home/william/.nvm/versions/node/v20.11.0/bin/node
const http = require('http');//require HTTP
const querystring = require('querystring');//require query string
const url = require('url');//require url
const { exec } = require("child_process");//require EXEC
http.createServer((req, res) => {//CREATE WEB SERVER
let runcommand = (command) => {//CREATE A FUNCTION THAT CAN BE CALLED TO RUN COMMANDS
exec(`${command}`, (error, stdout, stderr) => {
if (error) {///CONSOLE LOG ERRORS
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
});
}
let htmlMessage = '';//THIS VARIABLE WILL CONTAIN THE MESSAGE THAT WILL BE DISPLAYED TO THE USERS
let getValues = querystring.parse(url.parse(req.url).query);
if(getValues.onoff == "on")//IF /?onoff=on is sent then run the code in the if block that will call the runcommand function
{
runcommand('echo "The pin was turned on "`date` >> ./log');//THIS COMMAND WILL LOG THE ACTION TAKEN USING THE ECHO COMMAND
runcommand('./on.py');//THIS COMMAND WILL TURN ON THE GPIO PIN
htmlMessage = "<h1>The pin was turned on!</h1>";//THIS IS THE MESSAGE THAT WILL BE SENT TO THE USER
} else if(getValues.onoff == "off"){//IF /?onoff=off is sent then run the code in the if block that will call the runcommand function
runcommand('echo "The pin was turned off "`date` >> ./log');//LOG THE ACTION WITH THE ECHO COMMAND
runcommand('./off.py');//THIS COMMAND WILL TURN OFF THE GPIO PIN
htmlMessage = "<h1>The pin was turned off!</h1>";//THIS IS THE MESSAGE THAT WILL BE SENT TO THE USER
}
res.setHeader('Content-Type', 'text/html');//SET THE HEAD FOR HTML
res.writeHead(200, { 'Content-Type': 'text/html' });//WRITE THE HEAD
console.log(htmlMessage);
//BELOW IS THE SIMPLE HTML IT ONLY HAS TWO LINKS, A H1 ELEMENT AND A LITTLE CSS. THE LINKS WILL SEND THE GET INFO TO TURN ON AND OFF THE PINS
let html = `
<!DOCTYPE html>
<html>
<head>
<style>
a {
display: block;
padding: 10px;
margin: 10px;
size: 70px;
background-color: pink;
}
</style>
</head>
<body>
${htmlMessage}
<a href="?onoff=on">ON</a>
<a href="?onoff=off">OFF</a>
</body>
</html>
`;
res.write(html);//WRITE THE HTML
res.end();//END
}).listen(3000);
</code>
-
2:00:36
BEK TV
1 day agoTrent Loos in the Morning - 9/11/2025
12.6K1 -
22:25
DeVory Darkins
1 day ago $21.86 earnedTrump issues statement to the nation as FBI drops shocking update about shooter
99.1K143 -
10:55
Nate The Lawyer
2 days ago $2.11 earnedPortland's WOKE Laws Stop ALL Arrests to Help Illegal Migrants Fight ICE.
38.1K30 -
3:06:32
Price of Reason
16 hours agoCharlie Kirk Investigation Continues | Remembering 9-11 | Robert Downey Jr. Doctor Doom Look Reveal
281K71 -
2:12:26
Inverted World Live
12 hours agoManhunt for Suspect in Charlie Kirk's Assassination Continues, NASA Reveals "Life" on Mars | Ep. 107
264K58 -
2:44:02
TimcastIRL
13 hours agoMedia Warns Of Civil War Following Charlie Kirk Assassination | Timcast IRL
503K380 -
2:59:56
Laura Loomer
14 hours agoEP143: Remembering Charlie Kirk (1993–2025)
125K89 -
58:04
Man in America
17 hours agoCharlie Kirk’s Assassination—An URGENT WARNING for America
141K193 -
1:22:15
Glenn Greenwald
15 hours agoCharlie Kirk Assassination Fallout: U.S. Reps Call for Censorship; Do Graphic Videos Serve the Public Interest? Plus: WIRED Reporter on the Dark Side of Surrogacy | SYSTEM UPDATE #513
239K222 -
1:48:36
Right Side Broadcasting Network
21 hours agoLIVE: President Trump Attends the Yankees Baseball Game - 9/11/25
217K31