2017 © Pedro Peláez
 

library php-musiccast-api

PHP Wrapper for Yamaha MusicCast API

image

samvdb/php-musiccast-api

PHP Wrapper for Yamaha MusicCast API

  • Monday, September 11, 2017
  • by samvdb
  • Repository
  • 3 Watchers
  • 6 Stars
  • 37 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Yamaha MusicCast API PHP Library

DEPRECATED!!!!

grandDam improved this library alot, it includes tests and more functionality., (*1)

Use this fork Library instead!, (*2)

composer require granddam/php-musiccast-api

DEPRECATED!!!!

A simple wrapper for the Yamaha MusicCast API. Not all call's have been implemented yet so pull requests are welcome!, (*3)

Build Status, (*4)

Based on the API specification found at https://jayvee.com.au/downloads/commands/yamaha/YXC_API_Spec_Basic.pdf, (*5)

Updated API specs on 2017/04: https://www.pdf-archive.com/2017/04/21/yxc-api-spec-advanced/yxc-api-spec-advanced.pdf, (*6)

Update

The API pdf's can also be found in this repository., (*7)

Requirements

PHP >= 5.6 Guzzle library, (optional) PHPUnit to run tests., (*8)

Install

Download Composer, (*9)

$ curl -s http://getcomposer.org/installer | php

Via composer, (*10)

$ composer require samvdb/php-musiccast-api php-http/guzzle6-adapter

You can install any adapter you want but guzzle is probably fine for what you want to do., (*11)

Creating a client

$yamaha = new MusicCast\Client([
    'host' => 'localhost',
    'port' => 80, // default value
]);

Using the API

$result = $yamaha->api('zone')->status('main');
print_r($result);

Enabling events

Yamaha can notify you directly in case of changes. The events are spread out as UDP unicast packets. In order to receive these packets you must subscribe every 10 minutes, else the subscription will expire., (*12)

Only the IP that requests the subscription will receive the events., (*13)

The default port is 41100., (*14)

$yamaha->api('events')->subscribe();

Using php sockets to read the events

Pretty easy using Clue's socket wrapper., (*15)

$ composer require clue/socket-raw
$factory = new \Socket\Raw\Factory();
$socket = $factory->createUdp4();
$socket->bind('0.0.0.0:41100');

while(true) {
    $data = $socket->read(5120);
    $result = json_decode($data, true);

    print_r($result);
}

Testing

bash $ composer test, (*16)

Credits

This api is highly inspired by the excellent Github api client made by KnpLabs!, (*17)

KnpLabs/php-github-api, (*18)

The Versions