Raspberry Pi Dashboard refactored

Recently I refactored the Raspberry Pi Dasboard to use the PHP micro framework Slim. I used the Slim Skeleton as starting point with Slim Twig View as template engine.

This update includes also the ability to control the colour of my various wordclocks and the possibility to manage mobile notifications into my Android app with the help of the Google Cloud Messaging.

Additionally I switch the power socket control to pilight, therefore I had to change the control to communicate with the pilight API.

The PHP code for retrieving the pilight config and control a power socket is shown below:

function getPilightConfig(){
    $output	 = '';
    $config = '';

    $socket	 = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
    $result	 = socket_connect( $socket, PILIGHT_ADDRESS, PILIGHT_PORT );

    $identify	 = '{"action":"identify"}';
    socket_write( $socket, $data, strlen( $identify ) );
    $output .= socket_read( $socket, 1024 );

    $data = '{"action":"request config"}';
    socket_write( $socket, $data2, strlen( $data2 ) );

    do {
        $output = socket_read( $socket, 1025 );
        $config .= $output;
    } while ( strlen( $out ) >= 1024 );

    socket_close( $socket );
    return json_decode( $config, true );
}

function sendPilight( $socketname, $state ) {
    $output	 = '';

    $socket	 = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
    $result	 = socket_connect( $socket, PILIGHT_ADDRESS, PILIGHT_PORT );

    $identify	 = '{"action":"identify"}';
    socket_write( $socket, $data, strlen( $identify ) );
    $output .= socket_read( $socket, 1024 );

    $data = '{"action":"control","code":{"device":"' . str_replace( ' ', '', $socketname ) . '","state":"' . $state . '"}}';
    socket_write( $socket, $data2, strlen( $data ) );
    $output .= socket_read( $socket, 1024 );

    socket_close( $socket );

    return $output;
}