Last active
August 29, 2015 14:03
-
-
Save ersatzavian/44d0562ab043aff963ca to your computer and use it in GitHub Desktop.
Read temperature with Thermistor on imp001, show on small agent webpage
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
// agent code: | |
body <- "No value yet"; | |
http.onrequest(function(request,res){ | |
local html = @"<html><meta http-equiv=""refresh"" content=""5""> | |
<body>" + body + "</body></html>"; | |
res.send(200,html); | |
}); | |
device.on("temp", function(t){ | |
body = format("Temperature: %0.1f C", 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
temp_enable <- hardware.pin2; | |
temp_enable.configure(DIGITAL_OUT); | |
temp_enable.write(1); | |
temp_pin <- hardware.pin5; | |
temp_pin.configure(ANALOG_IN); | |
function read_temperature() { | |
local vdda = hardware.voltage(); | |
local v_therm = temp_pin.read() * (vdda / 65535.0); | |
return (298.15 * 3380.0) / | |
(3380.0 - 298.15 * math.log(10000.0 / ((vdda - v_therm) * | |
(10000.0 / v_therm)))) - 273.15; | |
} | |
function loop(){ | |
local t = read_temperature(); | |
server.log(format("Temperature: %0.1f°C", t )); | |
agent.send("temp",t); | |
imp.wakeup(1, loop); | |
} | |
loop(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment