Esempio n. 1
0
}
//
// Check which page must be displayed
//
if ($_SERVER["REQUEST_METHOD"] != "POST") {
    require_once ORVFMS_PATH . "main_page.php";
    displayMainPage($s20Table, $myUrl);
    require_once ORVFMS_PATH . "main_page_scripts.php";
} else {
    if (isset($_POST['toMainPage'])) {
        $actionValue = $_POST['toMainPage'];
        if (substr($actionValue, 0, 7) == "switch_") {
            $switchName = substr($actionValue, 7);
            $mac = getMacFromName($switchName, $s20Table);
            $st = $s20Table[$mac]['st'];
            $newSt = actionAndCheck($mac, $st == 0 ? 1 : 0, $s20Table);
            $s20Table[$mac]['st'] = $newSt;
            $swVal = $s20Table[$mac]['switchOffTimer'];
            if ($st == 0 && $newSt == 1 && $swVal > 0) {
                $s20Table[$mac]['timerVal'] = $swVal;
                $s20Table[$mac]['timerAction'] = 0;
            }
        } else {
            if ($actionValue == "setCountdown" || $actionValue == "clearCountdown" || $actionValue == "clearSwitchOff") {
                require_once ORVFMS_PATH . "timer_settings.php";
                timerSettings($s20Table, $actionValue);
            }
        }
        require_once ORVFMS_PATH . "main_page.php";
        displayMainPage($s20Table, $myUrl);
        require_once ORVFMS_PATH . "main_page_scripts.php";
Esempio n. 2
0
        echo "Device with mac address " . $mac . " (" . $s20Table[$mac]['name'] . ") seems to be inactive\n";
    }
}
if ($ok == 0) {
    echo "No active sockets found; exiting.\n";
    exit(0);
}
for ($i = 0; $i < 2; $i++) {
    foreach ($s20Table as $mac => $devData) {
        if ($s20Table[$mac] && !array_key_exists('off', $s20Table[$mac])) {
            $name = $devData['name'];
            $ip = $devData['ip'];
            $st = checkStatus($mac, $s20Table);
            echo "Status of S20 named >" . $name . "< (mac=" . $mac . ", IP=" . $ip . ") is " . ($st ? "ON" : "OFF") . "\n";
            echo "  ...Turning it " . ($st ? "OFF" : "ON") . "\n";
            actionAndCheck($mac, $st ? 0 : 1, $s20Table);
            $st = checkStatus($mac, $s20Table);
            echo "  ...new status is " . ($st ? "ON" : "OFF") . "\n\n";
            ob_flush();
        }
    }
    sleep(2);
}
foreach ($s20Table as $mac => $devData) {
    if ($s20Table[$mac] && !array_key_exists('off', $s20Table[$mac])) {
        break;
    }
}
for ($i = 0; $i < 2; $i++) {
    //
    // Timer test; toggle first device twice, 10 seconds
Esempio n. 3
0
function sendActionByDeviceName($name, $action, $s20Table)
{
    //
    // Sends an action to device designates with $name
    //
    $mac = getMacFromName($name, $s20Table);
    return actionAndCheck($mac, $action, $s20Table);
}
Esempio n. 4
0
<?php

define('SWITCH_CACHE', __DIR__ . '/switches.json');
require './orvfms/orvfms.php';
$cmd = $argv[1];
function getSwitches($refresh = false)
{
    if ($refresh || !file_exists(SWITCH_CACHE)) {
        $switches = initS20Data();
        file_put_contents(SWITCH_CACHE, json_encode($switches));
    } else {
        $switches = json_decode(file_get_contents(SWITCH_CACHE), $assoc = true);
    }
    return $switches;
}
switch ($cmd) {
    case 'list':
        echo json_encode(getSwitches());
        break;
    case 'on':
        $switchId = $argv[2];
        $switches = getSwitches();
        actionAndCheck($switchId, 1, $switches);
        break;
    case 'off':
        $switchId = $argv[2];
        $switches = getSwitches();
        actionAndCheck($switchId, 0, $switches);
        break;
}