Example #1
0
function createSocketAndSendMsg($msg, $ip)
{
    //
    // Create socket, bind it to local address (0.0.0.0,PORT),
    // for listening, sets timeout to receiving operations,
    // and sends msge $msg to address ($ip,PORT)
    //
    $s = createSocketAndBind($ip);
    sendHexMsg($s, $msg, $ip);
    return $s;
}
Example #2
0
function sendAction($mac, $action, $s20Table)
{
    //
    // Sends an $action (ON=1, OFF = 0) to S20 specified by $mac
    // It retries until a proper reply is received with the desired
    // power status
    // However, we have detected that the reported power status just
    // after an action fails sometimes, and therefore you should not
    // use this function alone. Prefer switchAndCheck() below, which
    // performs a double check of the final state.
    //
    subscribe($mac, $s20Table);
    $msg = ACTION . $mac . TWENTIES;
    if ($action) {
        $msg .= ON;
    } else {
        $msg .= OFF;
    }
    $ip = $s20Table[$mac]['ip'];
    $s = createSocketAndBind($ip);
    $hexRecMsg = sendHexMsgWaitReply($s, $msg, $ip);
    $status = (int) hexdec(substr($hexRecMsg, -2, 2));
    socket_close($s);
}