Rpi camera and custom php buttons

Hi. I have a custom camera UI with camera window and two buttons. One button is for turn the IR light on and the second button is for turn the IR light off.

I need to also create some changes in the camera settings during the button click. IR on means change the Exposure mode - Night ON. IR off means turn the Exposure mode Auto.

I found in the index.php

$options_mm = array('Average' => 'average', 'Spot' => 'spot', 'Backlit' => 'backlit', 'Matrix' => 'matrix');
$options_em = array('Off' => 'off', 'Auto' => 'auto', 'Night' => 'night', 'Nightpreview' => 'nightpreview', 'Backlight' => 'backlight', 'Spotlight' => 'spotlight', 'Sports' => 'sports', 'Snow' => 'snow', 'Beach' => 'beach', 'Verylong' => 'verylong', 'Fixedfps' => 'fixedfps');

So I made this:

<!DOCTYPE html>
<?php
   define('BASE_DIR', dirname(__FILE__));
   require_once(BASE_DIR.'/config.php');
   $config = array();
   $debugString = "";
   $options_mm = array('Average' ='average', 'Matrix' ='matrix');
   $options_em = array('Auto' ='auto', 'Night' ='night');
 ?>
 
<html>
<head>
<meta charset="UTF-8" />
  <title>Camera</title>
    <script src="js/script.js"></script>

<style
input[type=button], input[type=submit], input[type=reset] {
    background-color: #595959;
    border: none;
    color: white;
    padding: 16px 32px;
    text-decoration: none;
    margin: 4px 2px;
    cursor: pointer;
    font-weight: bold;
    font-size: 25px;
    border-radius: 6px;
    width: 635px;
    border: 5px solid #A9A9A9;
}

</style>
</head>

 <body onload="setTimeout('init();', 100);" bgcolor="black">
    <center>
      <div><img id="mjpeg_dest" /></div>
    <center>

        <form method="get" action="camera.php">
                <input type="submit" value="Light on" name="on" onclick="send_cmd('em night');" >
                <input type="submit" value="Light off" name="off" onclick="send_cmd('em auto');" >

        </form>

        <?php
        $setmode17 = shell_exec("/usr/local/bin/gpio -g mode 24 out");
        if(isset($_GET['on']))
         {
                $gpio_on = shell_exec("/usr/local/bin/gpio -g write 24 1");
                sleep(120);
                $gpio_on = shell_exec("/usr/local/bin/gpio -g write 24 0");
         }     
  
        if(isset($_GET['off']))
         {
                 $gpio_on = shell_exec("/usr/local/bin/gpio -g write 24 0");
	  }		
       ?>


</body>
</html>

This works well. But I have a problem to change two items in the settings menu. I need to also change the Metering Mode. So I tried to add l this:

send_cmd('mm matrix');

So line is:

input type="submit" value="Light on" name="on" onclick="send_cmd('mm matrix');send_cmd('em night');" 

This line does not work. Only the last item in the onclick works.
I tried only Metering mode so it works. I tried only Exposure mode so it works. But it does not work together.
How to?
Thank Roman

You want to pass multiple parameters to one function, so it might be:

"send_cmd('mm matrix', 'em night')"

But to make sure you need to have a look into the send_cmd function and see what it actually does.
see: JavaScript Functions

"send_cmd('mm matrix', 'em night')"

This line also does not work. Again only one of them works.
I am beginner so I don’t understand many things
Is there any other command to call the array function?

I took this as an example

In your head section, where the <script src="js/script.js"></script> is, add:

<script>
function call_both() { 
    send_cmd('mm matrix');
    send_cmd('em night');
  }
</script>

And for the form:

<input type="submit" value="Light on" name="on" onclick="call_both();">

PS: no guarantee, I’m not a dev at all.

Do you mean inside the script src?

You can add this in the script, but also just copy it and add it in the HTML file, the first part in the <head> section below the <script src="js/script.js"></script> and the second part is the changed button.

<head>
...
<title>Camera</title>
    <script src="js/script.js"></script>
<script>
function call_both() { 
    send_cmd('mm matrix');
    send_cmd('em night');
  }
</script>
</head>
...
<input type="submit" value="Light on" name="on" onclick="call_both();">
...

This also does not work. It does again only one of them.

Ok, as I said I’m not a dev and as you can see I failed hard. :sweat_smile:
I think you have to live with clicking two buttons or you can contact the creator of the UI and ask there for help.

Hard to say without knowing what send_cmd actually does (not a standard command, is it?). For this you need to look into the script.js or ask it’s developer, indeed.

See an attachment
script.txt (20.2 KB)

function send_cmd (cmd) {
  ajax_cmd.open("GET","cmd_pipe.php?cmd=" + cmd,true);
  ajax_cmd.send();
}

So it sends it to cmd_pipe.php, like cmd_pipe?cmd=mm&nbsp;matrix
Hmm, revert every change we made and maybe try

input type="submit" value="Light on" name="on" onclick="send_cmd('mm matrix em night');"

I’m just guessing.
The best option is still to ask the dev of this WebUI control. From where did you get this??