You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »


Create Project 

mkdir sonosPlayer
cd sonosPlayer

npm init

npm install sonos

npm install git://github.com/bencevans/node-sonos.git


> vi discover.js

const Sonos = require('sonos')
  
console.log('Searching for Sonos devices for 5 seconds...')

const discovery = new Sonos.AsyncDeviceDiscovery()

discovery.discover().then((device, model) => {
  console.log('Found one sonos device %s getting all groups', device.host)
  return device.getAllGroups().then((groups) => {
    console.log('Groups %s', JSON.stringify(groups, null, 2))
  })
}).catch(e => {
  console.warn(' Error in discovery %j', e)
})


Run it

> node discover.js


vi playSpotify.js

"Name": "John's Room",
    "host": "192.168.1.24",

"Name": "Dining Room",
    "host": "192.168.1.26",






If you want to add it to npm, edit the package.json file

{
  "name": "sonosplayer",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node discover.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "sonos": "git://github.com/bencevans/node-sonos.git"
  }
}








References

  • No labels