Exemple #1
0
    if (array_key_exists('SERVER_ADDR', $_SERVER)) {
        return $_SERVER['SERVER_ADDR'];
    } elseif (array_key_exists('LOCAL_ADDR', $_SERVER)) {
        return $_SERVER['LOCAL_ADDR'];
    } elseif (array_key_exists('SERVER_NAME', $_SERVER)) {
        return gethostbyname($_SERVER['SERVER_NAME']);
    } else {
        // Running CLI
        if (stristr(PHP_OS, 'WIN')) {
            return gethostbyname(php_uname("n"));
        } else {
            $ifconfig = shell_exec('/sbin/ifconfig eth0');
            preg_match('/addr:([\\d\\.]+)/', $ifconfig, $match);
            return $match[1];
        }
    }
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
$game_controller = new GameController($Server);
//var_dump($game_controller);
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
//$Server->wsStartServer('192.168.0.42', 9301);
$ipAddress = getServerAddress();
$port = "9301";
echo "Server start at " . $ipAddress . ":" . $port;
$Server->wsStartServer($ipAddress, $port);
/**
 * Creates the notification text
 * @param float $temp The temperature in degree C. 
 */
function createNotificationText($temp)
{
    $config = getConfig();
    $notifiactionConfig = $config['notification'];
    $message = "Your Raspberry Pi's temperature raised above your defined maximum temperature. \r\n\r\n";
    // Add Temp
    $message .= "Current temperature: " . $temp . "C\r\n";
    // Add (optional) hostname
    if ($notifiactionConfig['show_hostname']) {
        $message .= "Hostname: " . gethostname() . "\r\n";
    }
    // Add (optional) IP address
    if ($notifiactionConfig['show_ip_address']) {
        $message .= "IP Address: " . getServerAddress('eth0') . "\r\n";
    }
    return $message;
}