I have a php script that runs from a cron job, it uses CURL to read a URL (hosted by my arduino) to determine if my garage door is open. It will return "D7 is ON" when the door is closed, and "D7 is off" when the door is open.
When I manually open the link in a browser, I get the correct status based on the door position. It seems that CURL is not refreshing or is caching the url so it always thinks the door is closed. When I first built the script, I tested opening and closing a hundred times and it always seemed to update, but all of a sudden it seemed to stop....
Any problems with this code?
Code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://XXXXXXXXXXXXXXX/digitalRead/7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$manstatus = curl_exec($ch);
curl_close($ch);
My test output code is:
Code:
if ($manstatus = "D7 is ON")
{
echo 'Man door is closed!';
echo '</br>';
}
else if ($manstatus = "D7 is off")
{
echo 'Man door is open!';
echo '</br>';
}
It is saying closed EVERY TIME, even when I know the URL is saying open. I cant seem to figure out why all of a sudden this changed.
This is my first time using CURL, so feel free to tell me if I am doing this all wrong!