Created
February 17, 2020 21:24
-
-
Save erdemarslan/b0a054390bf7a496071cd5a4829785af to your computer and use it in GitHub Desktop.
Read Raspberry Pi CPU Temp with Node.js and Send to Web Page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require("http"); | |
var fs = require("fs"); | |
var server = http.createServer(function(request, response) { | |
var temp = fs.readFileSync("/sys/class/thermal/thermal_zone0/temp"); | |
var temp_c = temp/1000; | |
response.writeHead(200, {"Content-Type": "text/plain"}); | |
response.write("Raspberry Pi cpu temperature: "); | |
response.write("\n" + temp); | |
response.write("\n" + temp_c); | |
response.end(); | |
}); | |
server.listen(8080); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment