Skip to content

Instantly share code, notes, and snippets.

@danimaciasperea
Created June 22, 2018 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danimaciasperea/7f0f85db8d870b654469463bcc94a741 to your computer and use it in GitHub Desktop.
Save danimaciasperea/7f0f85db8d870b654469463bcc94a741 to your computer and use it in GitHub Desktop.
PHP Wrapper to send RF 433 Mhz commands using rpi-rf_send module.
<?php
function sendRF($lightId, $lightStatus) {
// 0, 1, 2, 3, 4, 5, 6
// entrada, lectura, tv, calduino, verde, deshumidificador, multiusos
$lightCode= array( 6, 10, 14, 83028, 86100, 70740, 21588);
$lightCodeDuration= array(205, 205, 205, 355, 355, 355, 355);
$sem_id = sem_get(RF_SEMAPHORE);
while (!sem_acquire($sem_id));
{
usleep(100);
}
$unixCommand = "sudo rpi-rf_send -g 22 -p ".$lightCodeDuration[$lightId]." -t 1 ".($lightCode[$lightId]+$lightStatus). " 2>&1";
for ($i = 1; $i < RESEND_TIMES; $i++) {
shell_exec ($unixCommand);
}
sem_release($sem_id);
}
define('RF_SEMAPHORE', 30);
define('RESEND_TIMES', 3);
/* if started from commandline, wrap parameters to $_POST */
if (!isset($_SERVER["HTTP_HOST"])) {
parse_str($argv[1], $_POST);
}
if (isset($_POST["parameter"]))
{
$parameter = $_POST["parameter"];
} else {
$parameter = null;
}
switch ($parameter) {
case "sendToRF":
$lightId = $_POST["lightId"];
$lightStatus = $_POST["lightStatus"];
sendRF($lightId, $lightStatus);
break;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment