Skip to content

Instantly share code, notes, and snippets.

@evilmachina
Created September 1, 2013 07:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save evilmachina/6402955 to your computer and use it in GitHub Desktop.
Save evilmachina/6402955 to your computer and use it in GitHub Desktop.
Electric Imp TMP36 Thermometer Thingspeak Logger
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);
});
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();
@sandboard
Copy link

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

@sandboard
Copy link

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"}

@iobridge
Copy link

iobridge commented May 6, 2014

Thanks for creating your Electric Imp + ThingSpeak projects... We were inspired by your projects to create an official GitHub project for connecting the Electric Imp to ThingSpeak: https://github.com/iobridge/thingspeak-electric-imp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment