What are common methods to execute Linux commands in PHP, specifically for Raspberry Pi GPIO control?
To execute Linux commands in PHP for Raspberry Pi GPIO control, you can use the `shell_exec()` function. This function allows you to run shell commands and get the output. You can use it to interact with the GPIO pins on the Raspberry Pi by running commands like `gpio read` or `gpio write`.
// Example code to read from GPIO pin 4
$output = shell_exec("gpio read 4");
echo "GPIO pin 4 value: " . $output;
// Example code to write to GPIO pin 4
shell_exec("gpio mode 4 out");
shell_exec("gpio write 4 1");
echo "GPIO pin 4 set to HIGH";
Keywords
Related Questions
- What are the potential pitfalls of executing multiple UPDATE queries in PHP?
- How can you ensure proper communication between PHP and an external program when using ssh2_exec?
- How should variables be declared and named in PHP scripts to ensure clarity and avoid errors, especially in terms of alphanumeric characters and case sensitivity?