Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject: Help with CURL
PostPosted: Sun Apr 07, 2013 9:30 am 
Offline
Senior Member

Joined: Mon Sep 01, 2008 5:14 pm
Posts: 92
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!


Top
   
 Post subject: Re: Help with CURL
PostPosted: Sun Apr 07, 2013 10:16 am 
Offline
Senior Member

Joined: Sat Nov 27, 2010 8:21 pm
Posts: 63
You need to use double equals (==) in your if tests. Single equals is used for assignment.


Top
   
 Post subject: Re: Help with CURL
PostPosted: Sun Apr 07, 2013 10:57 am 
Offline
Senior Member

Joined: Mon Sep 01, 2008 5:14 pm
Posts: 92
Nibbler wrote:
You need to use double equals (==) in your if tests. Single equals is used for assignment.


Made that change and a few others from feedback received from other members on IRC.

Solved!


Top
   
 Post subject: Re: Help with CURL
PostPosted: Mon Apr 08, 2013 9:56 am 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
There's nothing wrong with using CURL, but FYI PHP has built-in functions to do this stuff without resorting to external libraries. The most simplified one would be:

$manstatus = file_get_contents("http://XXXXXXXXXXXXXXX/digitalRead/7");


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group