[ create a new paste ] login | about

Link: http://codepad.org/CaStwXNr    [ raw code | fork ]

PHP, pasted on Jun 11:
<?php
if (isset($argv[1]) AND (!empty($argv[1]) AND $argv[1] == "cron")) {
    if (!file_exists("cron.txt")) { exit(); }
    $start = date("H:i");
    $end = file_get_contents("cron.txt");
    if (get_time_difference($start, $end) == 0) {
        if (!file_exists("/sys/class/gpio/gpio21")) {
            file_put_contents("/sys/class/gpio/export", "21");
            usleep(200000); //Programm-Verzoegerung in Mikrosekunden: 0.2s
            file_put_contents("/sys/class/gpio/gpio21/direction", "out");
        }
        file_put_contents("/sys/class/gpio/gpio21/value", "1");
    }   
    exit();
}

if (isset($_POST['end']) and !empty($_POST['end'])) {
    file_put_contents("cron.txt", $end);
    echo "OK<br/>";
}

function get_time_difference($start_time_o, $end_time_o) {
    $start_time = explode(":", $start_time_o);
    $end_time = explode(":", $end_time_o); 
    $start_time_stamp = mktime($start_time[0], $start_time[1], 0, 0, 0, 0);
    $end_time_stamp = mktime($end_time[0], $end_time[1], 0, 0, 0, 0);
    $time_difference = $end_time_stamp - $start_time_stamp;
    return $time_difference;
}
?>
<form action="zeitschaltuhr.php" method="post">
    <input type="text" name="end" required="required"><br/>
    <input type="submit" value="Erstellen">
</form>


Create a new paste based on this one


Comments: