Jump to content

I am stuck, please someone help

LuukvanA

Hey guys, so i am trying to make it so that if I visit a PHP page on my Raspberry Pi (set up as PHP server and a RF remote), the Pi notices that and runs a command (sudo ./action 511 A on).

If i run that command from the command line (connected with SSH->Putty) it works fine, also if I go to the example page that i edited visiually everything works fine but I can't figure out how to make the PHP page to run a command by just going to the page.

I am literrally trying for 6 hours straight now but nothing seems to work...

 

I'm sorry if I say something stupid, i;m a real noob at this...

 

I would really appriciate it if someone would help me!

 

How it looks now:

 

2198mxe.png

 

 

 

WORKING CODE:

 

<?php$data = 'sudo /root/wiringPi/examples/lights/./action ';$knop=$_POST['button'];$channel=$_POST['dipchannel']; if ( isset($_POST['button']) ) {shell_exec(''.$data.' '.$channel.' '.$knop.'');}?> <!DOCTYPE html><!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]--><!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]--><!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]--><!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]--><head> <!-- Basic Page Needs  ================================================== --><meta charset="utf-8"><title>Remote</title><meta name="description" content=""><meta name="author" content=""> <!-- Mobile Specific Metas  ================================================== --><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <!-- CSS  ================================================== --><link rel="stylesheet" href="stylesheets/base.css"><link rel="stylesheet" href="stylesheets/skeleton.css"><link rel="stylesheet" href="stylesheets/layout.css"> <!--[if lt IE 9]><script src="[url=http://html5shim.googlecode.com/svn/trunk/html5.js]http://html5shim.googlecode.com/svn/trunk/html5.js"></script>[/url]<![endif]--> <!-- Favicons================================================== --><link rel="shortcut icon" href="images/favicon.ico"><link rel="apple-touch-icon" href="images/light.png"><link rel="apple-touch-icon" sizes="72x72" href="images/light.png"><link rel="apple-touch-icon" sizes="114x114" href="images/light.png"> </head><body>   <!-- Primary Page Layout================================================== --> <!-- Delete everything in this .container and get started on your own site! --> <div class="container"><div class="sixteen columns"><h1 class="remove-bottom" style="margin-top: 40px"><img src="./images/light.png"> Remote</h1><hr/><h3>Lights </h3><p>Washing Table</p><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">              <button class="button" type="submit" name="button" value="511 A on" />                            aan              </button>              <button class="button" type="submit" name="button" value="511 A off" />                            uit              </button>            </form>            <p>Middle of the Room</p>            <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">            <button class="button" type="submit" name="button" value="511 B on" />aan</button>            <button class="button" type="submit" name="button" value="511 B off" />uit</button> </form>            <p>LED Strip</p>            <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">              <button class="button" type="submit" name="button" value="511 C on" />                            aan              </button>              <button class="button" type="submit" name="button" value="511 C off" />                            uit              </button>            </form>            <p>Desk</p><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">           <button class="button" type="submit" name="button" value="510 A on" />aan</button>         <button class="button" type="submit" name="button" value="510 A off" />uit</button> </form>            <hr/> <h3>Music</h3><p>Speakers</p>     <legend></legend>     <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">           <button class="button" type="submit" name="button" value="511 D on" />aan</button>         <button class="button" type="submit" name="button" value="511 D off" />uit</button> </form>      <legend></legend>     <p>Subwoofer</p>     <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">           <button class="button" type="submit" name="button" value="511 E on" />aan</button>         <button class="button" type="submit" name="button" value="511 E off" />uit</button> </form><hr/>                  <h3>Tech</h3><p>Monitor</p>     <legend></legend>     <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">           <button class="button" type="submit" name="button" value="510 B on" />aan</button>         <button class="button" type="submit" name="button" value="510 B off" />uit</button> </form>      <legend></legend>     <hr/></div>  </div><!-- container -->  <!-- End Document================================================== --></body></html>
Edited by alpenwasser
added code tags

|| CPU: Core i7 3770k @ 4.6gHz || RAM: Corsair Vengeance 2x4GB 1600mHz || GPU: nVidia GTX 670 ||

 

Link to comment
Share on other sites

Link to post
Share on other sites

WORKING CODE:

does it work?

shell_exec(''.$data.' '.$channel.' '.$knop.'');
if you print the parameter, does it look like it should?

did you verify that php has the privileges to run that script?

Link to comment
Share on other sites

Link to post
Share on other sites

Yes it does work, when i go to the page and press aan (on) or uit (off), the switches react as they should, I am sure the php file has the right privilages, I only need some sort of direct link to the buttons, so i will have 10 links, so that if i visit the page the button is pressed automatically.

That is probably not possible, i know, but do you know an easy way to do this?

 

Privilages:

Capture1.jpg

 

Thanks in advance 

|| CPU: Core i7 3770k @ 4.6gHz || RAM: Corsair Vengeance 2x4GB 1600mHz || GPU: nVidia GTX 670 ||

 

Link to comment
Share on other sites

Link to post
Share on other sites

Yes it does work, when i go to the page and press aan (on) or uit (off), the switches react as they should, I am sure the php file has the right privilages, I only need some sort of direct link to the buttons, so i will have 10 links, so that if i visit the page the button is pressed automatically.

That is probably not possible, i know, but do you know an easy way to do this?

i think i'm missing something

so, you want that your pages executes that command whenever it's viewed? don't you just need to take the shell_exec out of the if statement?

Link to comment
Share on other sites

Link to post
Share on other sites

i think i'm missing something

so, you want that your pages executes that command whenever it's viewed? don't you just need to take the shell_exec out of the if statement?

 

I want to have links i can go to, to turn on/off the lights, instead of 1 webpage with all of them. the page doesn't have to say anything, just make sure that it triggers the lightswitch

 

Taking out shell_exec didn't help, it only made the buttons stop working:(

|| CPU: Core i7 3770k @ 4.6gHz || RAM: Corsair Vengeance 2x4GB 1600mHz || GPU: nVidia GTX 670 ||

 

Link to comment
Share on other sites

Link to post
Share on other sites

I want to have links i can go to, to turn on/off the lights, instead of 1 webpage with all of them. the page doesn't have to say anything, just make sure that it triggers the lightswitch

 

Taking out shell_exec didn't help, it only made the buttons stop working:(

you just have to work on it a bit instead of violently taking it out of its beloved if statement

 

so, to run commands you need to execute this

shell_exec(''.$data.' '.$channel.' '.$knop.'');

you can observe that

  1. data is constant (also, there is a not-necessary dot in the location)
  2. channel has no reason to exist, it's never used and it doesn't come from anywhere
  3. knop is the actual action to perform

so, if you want to write a page that turns on the LED strip, you need to link to a php page that is just like this

<?php           shell_exec('sudo /root/wiringPi/examples/lights/action 511 C on');?>

you can manage to do it with just one PHP page to save time, passing the command via GET method in the link

 

 

isn't it better to have buttons though? i think it's more fancy and user friendly

Link to comment
Share on other sites

Link to post
Share on other sites

you just have to work on it a bit instead of violently taking it out of its beloved if statement

 

so, to run commands you need to execute this

shell_exec(''.$data.' '.$channel.' '.$knop.'');

you can observe that

  1. data is constant (also, there is a not-necessary dot in the location)
  2. channel has no reason to exist, it's never used and it doesn't come from anywhere
  3. knop is the actual action to perform

so, if you want to write a page that turns on the LED strip, you need to link to a php page that is just like this

<?php           shell_exec('sudo /root/wiringPi/examples/lights/action 511 C on');?>

you can manage to do it with just one PHP page to save time, passing the command via GET method in the link

 

 

isn't it better to have buttons though? i think it's more fancy and user friendly

Thank you very much!!! That worked, i tried exactly that but I didn't remove the ''s stupid me, also thank you very much for explaining, now I understand what i am doing...

Can I thank you by giving you a steam key for Hotline Miami?

 

The links are used for IFTTT-like actions, like if my phone leaves a certain gps location (my house) turn off all lights. I hope you understand what i mean;)

 

Cheers

|| CPU: Core i7 3770k @ 4.6gHz || RAM: Corsair Vengeance 2x4GB 1600mHz || GPU: nVidia GTX 670 ||

 

Link to comment
Share on other sites

Link to post
Share on other sites

Can I thank you by giving you a steam key for Hotline Miami?

thank you very much, but having a good game to distract me isn't a good idea in this period

 

The links are used for IFTTT-like actions, like if my phone leaves a certain gps location (my house) turn off all lights. I hope you understand what i mean;)

i do, and that's pretty cool

thumbs up

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×