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>
-
6:08:23
The Pascal Show
20 hours ago $4.70 earnedDIDDY TRIAL LIVE! HERE WE GO! Feds Begin Closing Arguments Trial Day 31 & MORE
27.5K3 -
3:24:49
GamerGril
9 hours agoTGI-FrightDay | A Gril Among Us
34.9K9 -
1:19:26
Man in America
15 hours agoIs MAHA Pushing the WEF’s Wearable Agenda? w/ Dr. Ealy
132K98 -
8:35:28
SpartakusLIVE
14 hours agoNEW Loadouts have DROPPED from ADVANCEDgg || !advanced
87.1K4 -
30:28
Solar Groove Muzic
1 day ago $10.28 earnedAFRO HOUSE MIX 2025 | The Best of Afro House Music
58.9K5 -
41:00
The Finance Hub
22 hours ago $8.11 earnedI CAN'T BELIEVE WHAT JUST HAPPENED TO SEN. ADAM SCHIFF!
32K23 -
3:52:16
SynthTrax & DJ Cheezus Livestreams
1 day agoFriday Night Synthwave 80s 90s Electronica and more DJ MIX Livestream HEATWAVE Edition
58.9K17 -
2:46:07
I_Came_With_Fire_Podcast
17 hours agoCHINA TRADE | RUBIO VISA | SENATE SECRETS | DEPORT BAN
56.9K9 -
8:01
MattMorseTV
12 hours ago $5.60 earnedNYC Democrat is in HOT WATER.
33.4K64 -
3:18:05
PandaSub2000
16 hours agoNYC Has Fallen, Pascal Fatigue, Trump Victory | ON FIRE!
25.3K8