I have the following code on the Agent side:
// Define an HTTP request handler
function requestHandler(request, response) {
try {
if (“limit” in request.query) {
// ‘limit’ is a URL-encoded parameter, ie. ‘?limit=4’
local uuid, minor, major, power, totalBeacons = null
local settingValue = request.query.limit.tointeger();
local starterFlag = “We have just started!”
device.send(“begin”, starterFlag)
device.on(“retrieve”, function(myBeacon) {
//Make sure we turned on the device:
server.log(“device on”);
totalBeacons = myBeacon.len();
if (settingValue > totalBeacons) {response.send(200, ("Amount of Beacons is: " + totalBeacons + ", which is lower than the amount of beacons requested (" +settingValue+")" )) for (local i = 0 ; i < totalBeacons ; i++) { uuid = myBeacon[i].slice(0, 32); major = myBeacon[i].slice(33,34); minor = myBeacon[i].slice(35,36); power = myBeacon[i].slice(37,40); server.log(("This is beacon ID number "+(1+i)+":")) server.log(("UUID is: " + uuid)) server.log(("Major is: " + major)) server.log(("Minor is: " + minor)) server.log(("Power is: " + power)) server.log(("End of description of beacon ID number "+(1+i)+":")) } } if (settingValue <= totalBeacons) { if (settingValue ==0){ response.send(200, ("Please change the amount of beacons requested in the query, currently is " + settingValue + " (zero)" )) } else if (settingValue!=0){ response.send(200, ("Amount of Beacons is: " + totalBeacons + ", the amount of beacons requested is " +settingValue+", will only print as requested" )) for (local i = 0 ; i < settingValue ; i++) { uuid = myBeacon[i].slice(0, 32); major = myBeacon[i].slice(33,34); minor = myBeacon[i].slice(35,36); power = myBeacon[i].slice(37,40); server.log(("This is beacon ID number "+(1+i)+":")) server.log(("UUID is: " + uuid)) server.log(("Major is: " + major)) server.log(("Minor is: " + minor)) server.log(("Power is: " + power)) server.log(("End of description of beacon ID number "+(1+i))) } } } }); // Use the 'response' object to acknowledge reception of the request // to the request's source. '200' is HTTP status code for 'OK' } } catch (error) { // Something went wrong; inform the source of the request // '500' is HTTP status code for 'Internal Server Error' response.send(500, error); }
}
// Register the handler function as a callback
http.onrequest(requestHandler);
This gets executed when I run the following URL: https://agent.electricimp.com/[API KEY]/closestIBeacons?limit=1 (limit can be set to any integer I like). The outcome is as the log shows:
I would like to upload this data (the info I’m printing with server.log()) to the URL from which I’m initiating my application.
Is there any way how? I’d like to know please.
Thanks in advance!