Our teacher has a web server and we are allowed to test some things. I connected to the server with Putty and tried following command:
echo "i 4 r 255 g 0 b 0." > /dev/ttyACM0
ttyACM0
is a virtual file redirecting the stream to a serial interface. This specific command changes the color of a rgb led. But the same command doesn't work in php with exec
or shell_exec
:
<?php
// Script saved at /home/STUDENT_NAME/public_html/blink.php
echo shell_exec("echo \"i 4 r 255 g 0 b 0.\" > /dev/ttyACM0"); // Doesn't work
echo shell_exec("echo \"Hello\""); // Returns "Hello"
?>
I know that exec
and shell_exec
aren't disabled, because the second call to shell_exec
works. My next idea was to use fopen("php://memory", "a");
, but I don't know how to use these wrappers. So my questions:
- How to use these wrappers correctly? (Maybe like
"php://memory/dev/ttyACM0"
) - Is there a better solution?