Created
August 6, 2014 09:17
-
-
Save jitomesky/6d58fd1ab17dfd696c27 to your computer and use it in GitHub Desktop.
BBB_Temperature_sensor_web
This file contains 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
// BeagleBone Black + Grove Base Cape + Grove Temperature Sensor | |
// Base Cape: http://www.seeedstudio.com/wiki/Grove_Cape_for_BeagleBone_Series | |
// Temperature Sensor: http://www.seeedstudio.com/wiki/Grove_-_Temperature_Sensor | |
// | |
// Written by Toshifumi Nishinaga | |
// this code is public domain | |
var b = require('bonescript'); | |
var getTemperature = function(){ | |
var AN0 = "P9_39"; | |
var B = 3975; | |
var R0 = 10000; | |
var Rs = 10000; | |
var Vref = 1.8; | |
var Ts = 25 + 273.15; | |
var a_val = b.analogRead(AN0); | |
var V = a_val * 1.8; // 0 to 1 : 0 to 1.8(V) | |
var R = R0 * V / (Vref - V); | |
var T = 1 / ( 1 / Ts - Math.log(R / Rs) / B ) - 273.15; | |
T = Math.round(T*10) / 10; | |
console.log("Temperature: " + T); | |
return T; | |
} | |
var app = require('http').createServer(handler) | |
var io = require('socket.io')(app); | |
var fs = require('fs'); | |
app.listen(5000); | |
function handler (req, res) { | |
fs.readFile(__dirname + '/index.html', | |
function (err, data) { | |
if (err) { | |
res.writeHead(500); | |
return res.end('Error loading index.html'); | |
} | |
res.writeHead(200); | |
res.end(data); | |
}); | |
} | |
io.on('connection', function (socket) { | |
t = getTemperature(); | |
socket.emit('nowTemp', { temp: t }); | |
}); |
This file contains 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
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title> tempareture </title> | |
</head> | |
<body> | |
<div id="temp">unknown</div> | |
<script type="text/javascript" src="jquery-1.9.1.min.js"></script> | |
<script src="/socket.io/socket.io.js"></script> | |
<script> | |
var socket = io('http://192.168.7.2'); | |
socket.on('nowTemp', function (t) { | |
document.getElementById("temp").innerHTML = "現在の温度は" + t.temp + "度です。"; | |
}); | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment