I have this code running on the agent:
// Log the URLs we need
server.log("check: " + http.agenturl() + “?check”);
function requestHandler(request, response) {
try {
// convert the check query parameter to an integer
local chkdoor = request.query.check;
// send “check” message to device, and send check as the data
device.send(“check”, chkdoor);
response.header(“Status”, state);
//}
// }
// send a response back saying everything was OK.
response.send(200, “OK 200”);
} catch (ex) {
response.send(500, "Internal Server Error: " + ex);
}
}
// register the HTTP handler
http.onrequest(requestHandler);
function dealwithit(data){
local state = data;
server.log(data);
return state;
}
device.on(“status”, dealwithit);
and this code running on the device:
sensor <- hardware.pin9;
function displayStatus () {
local state = sensor.read();
if (state == 1){
local now = date();
server.log("Opened!");
}
else if(state == 0){
server.log("Closed!");
}
agent.send("status", state);
}
sensor.configure(DIGITAL_IN_PULLDOWN, displayStatus)
I want to call a get request through php and display the state on a html page. Here is the php code:
<?php $response = get_web_page("http://agent.electricimp.com/9gij0qZlzR-c"); $resArr = array(); $resArr = json_decode($response); echo " ``` "; print_r($response); echo " ``` "; function get_web_page($url) { $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_MAXREDIRS => 10, // stop after 10 redirects CURLOPT_ENCODING => "", // handle compressed CURLOPT_USERAGENT => "test", // name of client CURLOPT_AUTOREFERER => true, // set referrer on redirect CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect CURLOPT_TIMEOUT => 120, // time-out on response ); $ch = curl_init($url); curl_setopt_array($ch, $options); $content = curl_exec($ch); curl_close($ch); return $content; } ?>When I run this code i get the following error on the html page: Internal Server Error: the index ‘check’ does not exist (line 7).
Any idea as to why?