Giter Club home page Giter Club logo

sonos's Introduction

SonosUPnP

This library makes interfacing an Arduino with your Sonos system a breeze. The library supports both controlling and reading the state of your Sonos components. Playing URIs, files, online radio stations, playlists, and line-in is supported as well as the most common commands like play, pause, skip, mute, volume and speaker grouping. What sets this library apart from similar libraries written for the Arduino platform it its ability to read the state of most of the Sonos functions: getting source, player state, track number, track position, volume and more. The library is relatively compact and has a small enough memory footprint to run on the Arduino Uno and Duemilanove.

ESP8266:
For an ESP8266 port, have a look this fork: github.com/antonmeyer/sonos

Getting Started:

Note:
If you download the libraries as ZIP files from GitHub, "-master" will be added to the end of the file names. You need to rename the files, such that e.g. "microxpath-master.zip" becomes "microxpath.zip", before adding the libraries to your Ardiono libraries folder.

Arduino Example Sketch:
In the Arduino example sketch I've implemented a simple serial protocol that allows executing some of the Sonos commands that are supported by the library. Here's a list of supported commands:

pl = Play
pa = Pause
st = Stop
pr = Previous track
nx = Next track
fi = Play test file (file path must be changed for this to work)
ht = Play http stream (you need access to the music service WIMP)
ra = Play radio (works if your speakers are connected to the internet)
li = Play line in (only works if the device has an AUX input)
gr = Group speakers (Living Room, Bathroom and Bedroom)
ug = Ungroups speakers
re = Toggle repeat
sh = Toggle shuffle
lo = Toggle loudness
mu = Toggle mute
52 = Set volume level 52 (range is 00 - 99)
b5 = Set bass level -5 (range is 0 to -9)
B5 = Set bass level +5 (range is 0 to +9)
t3 = Set treble level -3
T0 = Set treble level normal

sonos's People

Contributors

tmittet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sonos's Issues

Structure declared as stack variable?

Not sure if this is correct. At line 403 of SonosUPnp.ccp, in function getTrackInfo, a local variable trackInfo is declared, filled with data, and then returned.

It seemed to cause odd crashes in my code, when the Sonos box is switched off. Should this variable (a structure of all sorts) not be declared globally?

Otherwise, very happy with this library, many thanks.

Cheers, Frank

compiler error

Hi, I try to compile the scan sample and get a compiler error :

.....

"C:\\Program Files (x86)\\Arduino\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\peter\\AppData\\Local\\Temp\\arduino_build_888210\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Bezig met het compileren van de schets...
"C:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\xtensa-esp32-elf-gcc\\1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-g++" -DESP_PLATFORM "-DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\"" -DHAVE_CONFIG_H -DGCC_NOT_5_2_0=0 -DWITH_POSIX "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/config" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/app_trace" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/app_update" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/asio" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/bootloader_support" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/bt" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/coap" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/console" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/driver" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/esp-tls" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/esp32" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/esp_adc_cal" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/esp_event" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/esp_http_client" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/esp_http_server" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/esp_https_ota" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/esp_ringbuf" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/ethernet" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/expat" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/fatfs" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/freemodbus" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/freertos" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/heap" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/idf_test" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/jsmn" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/json" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/libsodium" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/log" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/lwip" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/mbedtls" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/mdns" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/micro-ecc" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/mqtt" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/newlib" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/nghttp" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/nvs_flash" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/openssl" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/protobuf-c" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/protocomm" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/pthread" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/sdmmc" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/smartconfig_ack" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/soc" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/spi_flash" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/spiffs" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/tcp_transport" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/tcpip_adapter" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/ulp" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/vfs" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/wear_levelling" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/wifi_provisioning" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/wpa_supplicant" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/xtensa-debug-module" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/esp-face" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/esp32-camera" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/esp-face" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/fb_gfx" -std=gnu++11 -Os -g3 -Wpointer-arith -fexceptions -fstack-protector -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -w -Wno-error=maybe-uninitialized -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-unused-but-set-parameter -Wno-missing-field-initializers -Wno-sign-compare -fno-rtti -MMD -c -DF_CPU=240000000L -DARDUINO=10813 -DARDUINO_D1_MINI32 -DARDUINO_ARCH_ESP32 "-DARDUINO_BOARD=\"D1_MINI32\"" "-DARDUINO_VARIANT=\"d1_mini32\"" -DESP32 -DCORE_DEBUG_LEVEL=0 "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4\\cores\\esp32" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4\\variants\\d1_mini32" "-IC:\\Users\\peter\\Documents\\Arduino\\libraries\\WiFiNINA\\src" "-IC:\\Users\\peter\\Documents\\Arduino\\libraries\\Sonos-ESP32\\src" "-IC:\\Users\\peter\\Documents\\Arduino\\libraries\\microxpath\\src" "-IC:\\Users\\peter\\Documents\\Arduino\\libraries\\EasyWifi-for-MKR1010-main\\src" "-IC:\\Users\\peter\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4\\libraries\\SPI\\src" "C:\\Users\\peter\\AppData\\Local\\Temp\\arduino_build_888210\\sketch\\SonosScan.ino.cpp" -o "C:\\Users\\peter\\AppData\\Local\\Temp\\arduino_build_888210\\sketch\\SonosScan.ino.cpp.o"
SonosScan:41:12: error: cannot declare variable 'G_Myserver' to be of abstract type 'WiFiServer'
 WiFiServer G_Myserver(SERVER_PORT);
            ^
In file included from C:\Users\peter\Documents\Arduino\libraries\WiFiNINA\src/WiFi.h:36:0,
                 from C:\Users\peter\Documents\Arduino\libraries\WiFiNINA\src/WiFiNINA.h:23,
                 from C:\Users\peter\Documents\Arduino\libraries\Sonos-ESP32\examples\SonosScan\SonosScan.ino:26:
C:\Users\peter\Documents\Arduino\libraries\WiFiNINA\src/WiFiServer.h:32:7: note:   because the following virtual functions are pure within 'WiFiServer':
 class WiFiServer : public Server {
       ^
In file included from C:\Users\peter\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Arduino.h:152:0,
                 from C:\Users\peter\AppData\Local\Temp\arduino_build_888210\sketch\SonosScan.ino.cpp:1:
C:\Users\peter\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Server.h:28:18: note: 	virtual void Server::begin(uint16_t)
     virtual void begin(uint16_t port=0) =0;
                  ^
Bibliotheek WiFiNINA op versie 1.8.7 in map: C:\Users\peter\Documents\Arduino\libraries\WiFiNINA  wordt gebruikt
Bibliotheek Sonos-ESP32 op versie 1.2 in map: C:\Users\peter\Documents\Arduino\libraries\Sonos-ESP32  wordt gebruikt
Bibliotheek microxpath op versie 1.1 in map: C:\Users\peter\Documents\Arduino\libraries\microxpath  wordt gebruikt
Bibliotheek EasyWifi-for-MKR1010-main op versie 1.3.0 in map: C:\Users\peter\Documents\Arduino\libraries\EasyWifi-for-MKR1010-main  wordt gebruikt
Bibliotheek SPI op versie 1.0 in map: C:\Users\peter\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SPI  wordt gebruikt
exit status 1
cannot declare variable 'G_Myserver' to be of abstract type 'WiFiServer'

I'am not good to solving compiler problems, have you an idea what went wrong?
Thanks to point me in the right direction.
Peter

Increase/decrease volume?

Is there a way to just increase or decrease the volume rather than setting it to a specific value? The node.js library has one.

getVolume returns undefined value

The version of getVolume that doesn't take a channel (pasted below) doesn't have a return statement, so the returned value is undefined. In practice you get some random-ish value calling tihs function.

uint8_t SonosUPnP::getVolume(IPAddress speakerIP)
{
  getVolume(speakerIP, SONOS_CHANNEL_MASTER);
}

Adding a return to the one line of code fixes the issue.

Is this library still working with latest Sonos firmware?

Hi, I am trying to make this library work with my Sonos Play 1 Speakers, and I am not sure where things stop.

When I for instance try to run g_sonos.play(g_sonosLivingrIP);, this is what void SonosUPnP::ethClient_write(const char *data) outputs:

POST Host: 192.168.2.212:1400
Content-Length: 266
#"

<u: xmlns:u="urn:"><Speed>1</Speed></u:>

Is this correct?

I have also tried out a .Net library called SonosSharp, which sends the following POST data when "play"-ing:

POST http://192.168.2.212:1400/MediaRenderer/AVTransport/Control HTTP/1.1
Content-Type: text/xml
SOAPAction: "urn:schemas-upnp-org:service:AVTransport:1#Play"
Host: 192.168.2.212:1400
Content-Length: 244
Expect: 100-continue
TerminalId: Vekt2-Nede

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
         <u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
            <Speed>1</Speed>
            <InstanceID>0</InstanceID>
         </u:Play>
    </s:Body>
</s:Envelope>

kindly request for wifi packet lenght optimization

when I look at the wireshark trace I see a lot of small packets for a single SOAP request.
I guess it is from the bunch of ethClient_write_P.
I also guess that the client code should care about MTU and MSS.
I also assume that your buffer-size of 50 byte is a tribute to the HW-limit.
With ESP8266 this looks better.

Play a favorite

Great library. I easily was able to play podcasts and URLs, as well as control volume, etc. from an esp32.

I'm now looking to play items saved as "favorites". i.e. the stations and etc that have been saved to be available one-touch via the sonos controller app. I've seen references to doing this in other sonos libraries, but am not (yet?) familiar enough with the details of sonos's upnp structure to know if a function to do this is present in your library and I don't know the right terminology. Or if it's not present currently and I'll have to give a go at coding it in.

Any pointers on whether this is a feature request vs a documentation request are much appreciated!

Cannot group or ungroup players

Everything seems to wotk just fine with this library except for grouping and ungrouping. Nothing happens and i got no error back. Can someone confirm that it works from their end?

includes not portable

your relative path in SonosUPnP.h

did not work, when I include your libs as zip-lib in arduino ide

include "../../MicroXPath/src/MicroXPath_P.h"

endif

include "../../Ethernet/src/EthernetClient.h"

Sonos_Control_and_State example code

I can't seem to 'verify' the example code. I get an error for 'ethConnectError' not declared in scope. This is solved by adding EthernetClient ethConnectError;

Then fails with error Sonos_Control_and_State:85: error: no matching function for call to 'SonosUPnP::SonosUPnP(EthernetClient&, EthernetClient&)' SonosUPnP g_sonos = SonosUPnP(g_ethClient, ethConnectError);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.