Wondering if anyone has a minute and can tell me how to modify this code to send multiple temperatures to Thingspeak?
I have working the Electric Imp code to send 1 temperature, but have not been able to modify it to send 6 temperatures. The temperatures are stored in an array. I'm getting datapoint.temp[1] through to Thingspeak, but don't know how I would also send in the same message datapoint.temp[0], datapoint.temp[2], datapoint.temp[3] and datapoint.temp[5].
The Device Code I have now is:
local datapoint = {
"id" : id,
"temp" : [ format("%.2f",myThermistor0.read_f()),
format("%.2f",myThermistor1.read_f()),
format("%.2f",myThermistor2.read_f()),
format("%.2f",myThermistor3.read_f()),
format("%.2f",myThermistor4.read_f()),
format("%.2f",myThermistor5.read_f()),]
}
agent.send("thing1", datapoint.temp[1]);
The Agent Code (online Web-IDE) I have now is:
local thingSpeakUrl = "http://api.thingspeak.com/update";
local headers = {
"Content-Type" : "application/x-www-form-urlencoded",
"X-THINGSPEAKAPIKEY" : "MY KEY IS HERE"
};
local field = "field1";
function httpPostToThingSpeak (data) {
local request = http.post(thingSpeakUrl, headers, data);
local response = request.sendsync();
return response;
}
device.on("thing1", function(analog_value) {
local response = httpPostToThingSpeak(field+"="+analog_value);
server.log("House Temp Samples: " + response.body);
});
Thanks in advance for pointers on how to proceed.
G