-
-
Save kd8bxp/e3fed8b3a4f8f4c6fe63 to your computer and use it in GitHub Desktop.
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
local thingspeakUrl = "http://api.thingspeak.com/update"; | |
local headers = {"Content-Type": "application/x-www-form-urlencoded", | |
"X-THINGSPEAKAPIKEY":"KEY"}; | |
local field = "field1"; | |
function httpPostToThingspeak (data) { | |
local request = http.post(thingspeakUrl, headers, data); | |
local response = request.sendsync(); | |
return response; | |
} | |
device.on("updateTemp", function(temp) { | |
local response = httpPostToThingspeak(field +"="+temp); | |
server.log(response.body); | |
}); |
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
hardware.pin9.configure(ANALOG_IN); | |
function getTemp() { | |
local supplyVoltage = hardware.voltage(); | |
local voltage = supplyVoltage * hardware.pin9.read() / 65535.0; | |
local c = (voltage - 0.5) * 100 ; | |
local c_str = format("%.01f", c); | |
server.log("Current temp is "+c_str+" °C"); | |
agent.send("updateTemp", c_str); | |
imp.wakeup(600, getTemp); | |
} | |
imp.configure("TMP36 Thermometer Thingspeak Logger", [], []); | |
getTemp(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment