MeltingDog Posted March 16, 2015 Share Posted March 16, 2015 Hi all, Sorry if this isnt the right place to ask this. I have tried many other forums and have had no luck. I am learning programming for Raspberry Pi. Currently, I can read the output of a pin (GPIO) on the circuit board as such: <?php exec ( "gpio read 7", $status ); print_r ( $status ); ?> That works fine - it prints the status to the screen. However, if I put this in an 'if' statement, eg: <?php if (isset($_GET['trigger']) && $_GET['trigger'] == 1) { exec ( "gpio read 7", $status ); print_r ( $status ); exec ( "gpio write 7 1" ); } ?> It no longer works. I know the if statement is correct as exec ( "gpio write 7 1" ); produces results. Would anyone know what I have done wrong here or why I would not be able to read the status? Many thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/295300-why-can-i-not-return-a-gpios-status-from-within-a-php-if-statement/ Share on other sites More sharing options...
iarp Posted March 17, 2015 Share Posted March 17, 2015 Are you sure you're adding ?trigger=1 to the url? http://localhost/index.php?trigger=1 You may also need to use == '1' instead of just a plain 1, PHP is weird sometimes with comparisons. Quote Link to comment https://forums.phpfreaks.com/topic/295300-why-can-i-not-return-a-gpios-status-from-within-a-php-if-statement/#findComment-1508272 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.