public
Created

Electric Imp TMP36 Thermometer Thingspeak Logger

  • Download Gist
TMP36.device.nut
Squirrel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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();
thingspeak.agent.nut
Squirrel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
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);
});

Hello , can you provide more details on how to setup the Agent parameter with the Thingspeak channel...what part of the code gets substituted..

Issue resolved.
for the future..
fill the "KEY" with the API provided by Thingspeak number this should be a 16 digit number.
"X-THINGSPEAKAPIKEY":"XXXXXXXXXXXXXXXX"}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.