I am new to the Imp, Squirrel, Thingspeak and electronics in general, but seem to be learning quicker than I thought. Hopefully someone with more know-how can help me with my first Device-to-Agent-to-Thingspeak adventure.
I have created a two temperature sensor device that I plan to use Thingspeak to remotely monitor the two temperatures. Currently I am able to poll the temperatures at the same time, log them etc.
When I get the data to the Agent and I attempt to post the values to Thingspeak it appears I am forced to split my posting into staggered posts due to the Thingspeak's posting limit (1-post per Thingspeak channel every 15 seconds). That said, I got to playing with the Agent code, trying to create code that would re-combine my values into a single Thingspeak post.
So far, I have my two
"device.on" functions as follows:
device.on("updateTemp2",
function(Update_Temp2) {
server.log("Update_Temp2 Value: " + Update_Temp2 + "*");
});
device.on("updateTemp5",
function(Update_Temp5) {
server.log("Update_Temp5 Value: " + Update_Temp5 + "*");
});
The server logs for these come out with the data I want, so I know things are working up to this point. Now I need the code to combine the Update_Temp2 and the Update_Temp5 values for my Thingspeak post. What I have so far is a 3rd “device.on function that I was hoping would receive the output from the two above device.on functions.
device.on("updateTemp",
function (combined) {
local request = http.post(thingspeakUrl, headers, ("field1"+"="+Update_Temp2+"&"+"field2"+"="+Update_Temp5));
local response = request.sendsync();
return response;
server.log(response.body);
});
It seems I am struggling with the function scoping because my current error is as follows: ERROR: the index 'Update_Temp2' does not exist. I have tried a handful of things but, I cannot seem to get the information to pass to my combined function. I am sure there is a rookie mistake here, I just need someone to point it out.
Thanks,