Example #1
0
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;
}
Example #2
0
    $time_ref = 0;
}
//
// Refresh/update only S20 data if $s20Table was initialized before, data seems consistent and
// time since last refresh was less than 5 minutes.
//
// Otherwise, reinitialize all $s20Table structure
//
if (isset($_SESSION["s20Table"]) && count($s20Table) > 0 && time() - $time_ref < 120) {
    $s20Table = updateAllStatus($s20Table);
    if (DEBUG) {
        error_log("Session restarted; only status update\n");
    }
} else {
    $time_ref = time();
    $s20Table = initS20Data();
    $_SESSION["s20Table"] = $s20Table;
    $ndev = count($s20Table);
    if ($ndev == 0) {
        echo "<h2>No sockets found</h2>";
        echo " Please check if all sockets are on-line and assure that they\n";
        echo " they are not locked (check WiWo app -> select socket -> more -> advanced).<p>";
        echo " In this version, locked or password protected devices are not supported.<p>";
        exit(1);
    }
    $_SESSION["devNumber"] = $ndev;
    $_SESSION["time_ref"] = $time_ref;
    if (DEBUG) {
        error_log("New session: S20 data initialized\n");
    }
}