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>
-
1:19:14
JULIE GREEN MINISTRIES
3 hours agoCOVID KILLED MANY AROUND THE WORLD AND JUSTICE IS COMING FOR THOSE DEATHS
76K148 -
1:03:06
Game On!
16 hours ago $3.15 earnedThe BIGGEST Plays From NFL Week 1!
19.1K4 -
13:27
Clownfish TV
15 hours agoSydney Sweeney Backlash BACKFIRES! American Eagle Stock UP 38%! | Clownfish TV
42.7K11 -
18:55
AndresRestart
16 hours ago $0.84 earnedSomething Key We Keep Missing About Metroid Prime 4 Beyond...
18.5K1 -
8:06
China Uncensored
16 hours agoThis Could Be China’s LAST CHANCE To Save Its Economy
22.7K29 -
LIVE
The Bubba Army
2 days agoDocumentary Premiere, A HUGE SUCCESS! - Bubba the Love Sponge® Show | 9/08/25
1,322 watching -
32:15
DeVory Darkins
10 hours ago $7.80 earnedDemocrats PAINFULLY WRECKED by Tom Homan as paid protesters ERUPT in Chicago
25.5K66 -
16:59
Degenerate Jay
15 hours ago $2.92 earnedIs Metal Gear Solid Delta: Snake Eater Worth Buying?
44.4K2 -
4:26:28
Flex011
7 hours ago $0.86 earnedCronos: The New Dawn – Brutal Time-Travel Horror Survival
17.3K2 -
33:11
The Finance Hub
19 hours ago $2.55 earnedBREAKING: JD VANCE JUST RELEASED A MASSIVE BOMBSHELL!!! OMG!!
18K31