DuoFernConfigurator/module.php
/**
     * Receive data from parent
     * Will be called when receiving data from parent
     *
     * @param string $JSONString
     *            data json encoded
     */
Receive data from parent
Will be called when receiving data from parent

@param string $JSONString
data json encoded
Receive data from parent Will be called when receiving data from parent @param string $JSONString data json encoded
public function ReceiveData($JSONString)
    {
        $data = json_decode($JSONString);
        $msg = utf8_decode($data->Buffer);
        $this->SendDebug("RECEIVED", $msg, 1);
        $displayMsg = $this->ConvertMsgToDisplay($msg);
        $waitForMsgBuffer = $this->WaitForMsgBuffer;
        $waitForMsgBuffer->Received($displayMsg);
        $this->WaitForMsgBuffer = $waitForMsgBuffer;
        $seenDevicesBuffer = (array)$this->SeenDevicesBuffer; 
        $duoFernCode = (string)substr($displayMsg, 30, 6);
        $seenDevicesBuffer[$duoFernCode] = time();
        $this->SeenDevicesBuffer = $seenDevicesBuffer;
        $duoFernDeviceType = DuoFernDeviceType::getDeviceType(substr($duoFernCode, 0, 2));
        if (preg_match('/^' . substr(DuoFernMessage::DUOFERN_MSG_PAIRED, 0, 6) . '.{38}$/', $displayMsg)) {
            IPS_LogMessage(IPS_GetName($this->InstanceID), sprintf($this->Translate("Device %s paired"),
                $duoFernDeviceType != false ? $duoFernDeviceType . " (" . trim(chunk_split($duoFernCode, 2, " ")) . ")" : trim(chunk_split($duoFernCode, 2, " "))));
        } else if (preg_match('/^' . substr(DuoFernMessage::DUOFERN_MSG_UNPAIRED, 0, 6) . '.{38}$/', $displayMsg)) {
            IPS_LogMessage(IPS_GetName($this->InstanceID), sprintf($this->Translate("Device %s unpaired"),
                $duoFernDeviceType != false ? $duoFernDeviceType . " (" . trim(chunk_split($duoFernCode, 2, " ")) . ")" : trim(chunk_split($duoFernCode, 2, " "))));
        } else if (preg_match('/^' . substr(DuoFernMessage::DUOFERN_MSG_ALREADY_UNPAIRED, 0, 6) . '.{38}$/', $displayMsg)) {
            IPS_LogMessage(IPS_GetName($this->InstanceID), sprintf($this->Translate("Device %s already unpaired"),
                $duoFernDeviceType != false ? $duoFernDeviceType . " (" . trim(chunk_split($duoFernCode, 2, " ")) . ")" : trim(chunk_split($duoFernCode, 2, " "))));
        }
    }
public function ReceiveData ( $ JSONString ) { $ data = json_decode ( $ JSONString ) ; $ msg = utf8_decode ( $ data -> Buffer ) ; $ this -> SendDebug ( " RECEIVED " , $ msg , 1 ) ; $ displayMsg = $ this -> ConvertMsgToDisplay ( $ msg ) ; $ waitForMsgBuffer = $ this -> WaitForMsgBuffer ; $ waitForMsgBuffer -> Received ( $ displayMsg ) ; $ this -> WaitForMsgBuffer = $ waitForMsgBuffer ; $ seenDevicesBuffer = ( array ) $ this -> SeenDevicesBuffer ; $ duoFernCode = ( string ) substr ( $ displayMsg , 30 , 6 ) ; $ seenDevicesBuffer [ $ duoFernCode ] = time ( ) ; $ this -> SeenDevicesBuffer = $ seenDevicesBuffer ; $ duoFernDeviceType = DuoFernDeviceType :: getDeviceType ( substr ( $ duoFernCode , 0 , 2 ) ) ; if ( preg_match ( '/^' . substr ( DuoFernMessage :: DUOFERN_MSG_PAIRED , 0 , 6 ) . '.{38}$/' , $ displayMsg ) ) { IPS_LogMessage ( IPS_GetName ( $ this -> InstanceID ) , sprintf ( $ this -> Translate ( " Device %s paired " ) , $ duoFernDeviceType != false ? $ duoFernDeviceType . "  ( " . trim ( chunk_split ( $ duoFernCode , 2 , " " ) ) . " ) " : trim ( chunk_split ( $ duoFernCode , 2 , " " ) ) ) ) ; } else if ( preg_match ( '/^' . substr ( DuoFernMessage :: DUOFERN_MSG_UNPAIRED , 0 , 6 ) . '.{38}$/' , $ displayMsg ) ) { IPS_LogMessage ( IPS_GetName ( $ this -> InstanceID ) , sprintf ( $ this -> Translate ( " Device %s unpaired " ) , $ duoFernDeviceType != false ? $ duoFernDeviceType . "  ( " . trim ( chunk_split ( $ duoFernCode , 2 , " " ) ) . " ) " : trim ( chunk_split ( $ duoFernCode , 2 , " " ) ) ) ) ; } else if ( preg_match ( '/^' . substr ( DuoFernMessage :: DUOFERN_MSG_ALREADY_UNPAIRED , 0 , 6 ) . '.{38}$/' , $ displayMsg ) ) { IPS_LogMessage ( IPS_GetName ( $ this -> InstanceID ) , sprintf ( $ this -> Translate ( " Device %s already unpaired " ) , $ duoFernDeviceType != false ? $ duoFernDeviceType . "  ( " . trim ( chunk_split ( $ duoFernCode , 2 , " " ) ) . " ) " : trim ( chunk_split ( $ duoFernCode , 2 , " " ) ) ) ) ; } }
Receive data from parent
 Will be called when receiving data from parent
Receive data from parent Will be called when receiving data from parent
// decode data // get msg // send msg as debug msg // wait for msg buffer // save seen devices with last message timestamp // get buffer // send paired and unpaired log messages