Skip to content

Instantly share code, notes, and snippets.

@indieisaconcept
Last active November 6, 2023 18:23
Show Gist options
  • Save indieisaconcept/6aa34375a183c8b5e23371f724caf98c to your computer and use it in GitHub Desktop.
Save indieisaconcept/6aa34375a183c8b5e23371f724caf98c to your computer and use it in GitHub Desktop.

Revisions

  1. indieisaconcept revised this gist Oct 2, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion setup_subwoofer.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/usr/bin/env bash

    # Copyright 2021 Jonothan Barnett <[email protected]>
    # Copyright 2021 Jonathan Barnett <[email protected]>
    #
    # Permission is hereby granted, free of charge, to any person obtaining a copy
    # of this software and associated documentation files (the "Software"), to deal
  2. indieisaconcept revised this gist Oct 2, 2021. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion setup_subwoofer.sh
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,6 @@ while [ $# -gt 0 ]; do
    if [[ $1 == *"--"* ]]; then
    param="${1/--/}"
    declare $param="$2"
    # echo $1 $2 // Optional to see the parameter:value result
    fi
    shift
    done
  3. indieisaconcept revised this gist Oct 2, 2021. 1 changed file with 23 additions and 33 deletions.
    56 changes: 23 additions & 33 deletions setup_subwoofer.sh
    Original file line number Diff line number Diff line change
    @@ -21,24 +21,16 @@

    ################################################################################

    # This script is inspired by the excellent app SonoSequencr. Its purpose is to make
    # it possible to pair a Symfonisk speaker or any other potentially compatible Sonos
    # speaker as a Subwoofer.
    #
    # Unfortunately I couldn't get SonoSequencr working hence this scripts existence.
    # Hopefully it will eventually work & it can replace this script.
    #
    # Usage
    #
    # Review the system information section in the Sonos app in-order to obtain the
    # relevant values required.
    #
    # host The IP address of the soundbar to pair
    # soundbar_id The mac address of the soundbar
    # subwooder_id The mac address of the device to use as a subwoofer
    # soundbar The IP address of the soundbar
    # subwoofer The IP address of the device to use as a subwoofer
    #
    # $> chmod u+x setup_subwoofer.sh
    # $> ./setup_subwoofer.sh --host 192.168.1.2 --soundbar_id 1B:B8:1D:E3:B2:0B --subwoofer_id 62:30:B5:1B:26:1E
    # $> ./setup_subwoofer.sh --soundbar 192.168.1.2 --subwoofer 192.168.1.3

    while [ $# -gt 0 ]; do
    if [[ $1 == *"--"* ]]; then
    @@ -51,18 +43,22 @@ done

    ################################################################################

    format_mac_address() {
    echo $1 | sed -e 's/://g' | tr '[:lower:]' '[:upper:]'
    }

    generate_error() {
    echo "ERROR | $1"
    }

    generate_envelope () {
    DeviceDescription() {
    echo $(curl -s -H "Host: $1:1400" -H 'Accept: */*' --compressed "http://$1:1400/xml/device_description.xml")
    }

    get_device_uuid() {
    local uuid=$(DeviceDescription $1 | xpath -q -e '//root/device/UDN/text()[1]' | sed -e 's/uuid://g')
    echo $uuid
    }

    local soundbar=$(format_mac_address $1)
    local subwoofer=$(format_mac_address $2)
    AddHTSatellite() {
    local soundbar=$(get_device_uuid $1)
    local subwoofer=$(get_device_uuid $2)

    cat <<BODY
    <?xml version="1.0" encoding="utf-8"?>
    @@ -71,39 +67,33 @@ cat <<BODY
    <s:Body>
    <u:AddHTSatellite
    xmlns:u="urn:schemas-upnp-org:service:DeviceProperties:1">
    <HTSatChanMapSet>RINCON_$(echo $soundbar)01400:LF,RF;RINCON_$(echo $subwoofer)01400:SW</HTSatChanMapSet>
    <HTSatChanMapSet>$(echo $soundbar):LF,RF;$(echo $subwoofer):SW</HTSatChanMapSet>
    </u:AddHTSatellite>
    </s:Body>
    </s:Envelope>
    BODY
    }

    if [ -z ${host+x} ]; then
    echo $(generate_error "Please supply the IP address of your soundbar you wish to pair");
    args_error=true;
    fi
    ################################################################################

    if [ -z ${soundbar_id+x} ]; then
    echo $(generate_error "Please supply the mac address of the soundbar you wish to pair a subwoofer with");
    if [ -z ${soundbar+x} ]; then
    echo $(generate_error "Please supply the IP address of the soundbar you wish to pair a subwoofer with");
    args_error=true;
    fi

    if [ -z ${subwoofer_id+x} ]; then
    echo $(generate_error "Please supply the mac address of the device you wish to use as a subwoofer");
    if [ -z ${subwoofer+x} ]; then
    echo $(generate_error "Please supply the IP address of the device you wish to use as a subwoofer");
    args_error=true;
    fi

    if [ "$args_error" = "true" ]; then
    exit 2;
    fi

    payload=$(generate_envelope $soundbar_id $subwoofer_id)
    payload=$(AddHTSatellite $soundbar $subwoofer)

    echo $payload | curl -v "http://$host:1400/DeviceProperties/Control" \
    -H "Host: $host:1400" \
    echo $payload | curl -s -v "http://$soundbar:1400/DeviceProperties/Control" \
    -H "Host: $soundbar:1400" \
    -H 'Content-Type: text/xml; charset=utf-8' \
    -H 'SOAPAction: urn:schemas-upnp-org:service:DeviceProperties:1#AddHTSatellite' \
    -H 'Accept: */*' \
    -H 'Accept-Language: en-au' \
    -H 'User-Agent: SonoSequencr/661 CFNetwork/1323 Darwin/21.1.0' \
    --data-binary @- --compressed
  4. indieisaconcept revised this gist Sep 28, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions setup_subwoofer.sh
    Original file line number Diff line number Diff line change
    @@ -26,6 +26,7 @@
    # speaker as a Subwoofer.
    #
    # Unfortunately I couldn't get SonoSequencr working hence this scripts existence.
    # Hopefully it will eventually work & it can replace this script.
    #
    # Usage
    #
  5. indieisaconcept revised this gist Sep 28, 2021. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions setup_subwoofer.sh
    Original file line number Diff line number Diff line change
    @@ -21,6 +21,12 @@

    ################################################################################

    # This script is inspired by the excellent app SonoSequencr. Its purpose is to make
    # it possible to pair a Symfonisk speaker or any other potentially compatible Sonos
    # speaker as a Subwoofer.
    #
    # Unfortunately I couldn't get SonoSequencr working hence this scripts existence.
    #
    # Usage
    #
    # Review the system information section in the Sonos app in-order to obtain the
  6. indieisaconcept created this gist Sep 28, 2021.
    102 changes: 102 additions & 0 deletions setup_subwoofer.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,102 @@
    #!/usr/bin/env bash

    # Copyright 2021 Jonothan Barnett <[email protected]>
    #
    # Permission is hereby granted, free of charge, to any person obtaining a copy
    # of this software and associated documentation files (the "Software"), to deal
    # in the Software without restriction, including without limitation the rights to
    # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
    # of the Software, and to permit persons to whom the Software is furnished to do
    # so, subject to the following conditions:
    #
    # The above copyright notice and this permission notice shall be included in all
    # copies or substantial portions of the Software.
    #
    # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
    # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
    # IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

    ################################################################################

    # Usage
    #
    # Review the system information section in the Sonos app in-order to obtain the
    # relevant values required.
    #
    # host The IP address of the soundbar to pair
    # soundbar_id The mac address of the soundbar
    # subwooder_id The mac address of the device to use as a subwoofer
    #
    # $> chmod u+x setup_subwoofer.sh
    # $> ./setup_subwoofer.sh --host 192.168.1.2 --soundbar_id 1B:B8:1D:E3:B2:0B --subwoofer_id 62:30:B5:1B:26:1E

    while [ $# -gt 0 ]; do
    if [[ $1 == *"--"* ]]; then
    param="${1/--/}"
    declare $param="$2"
    # echo $1 $2 // Optional to see the parameter:value result
    fi
    shift
    done

    ################################################################################

    format_mac_address() {
    echo $1 | sed -e 's/://g' | tr '[:lower:]' '[:upper:]'
    }

    generate_error() {
    echo "ERROR | $1"
    }

    generate_envelope () {

    local soundbar=$(format_mac_address $1)
    local subwoofer=$(format_mac_address $2)

    cat <<BODY
    <?xml version="1.0" encoding="utf-8"?>
    <s:Envelope
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <s:Body>
    <u:AddHTSatellite
    xmlns:u="urn:schemas-upnp-org:service:DeviceProperties:1">
    <HTSatChanMapSet>RINCON_$(echo $soundbar)01400:LF,RF;RINCON_$(echo $subwoofer)01400:SW</HTSatChanMapSet>
    </u:AddHTSatellite>
    </s:Body>
    </s:Envelope>
    BODY
    }

    if [ -z ${host+x} ]; then
    echo $(generate_error "Please supply the IP address of your soundbar you wish to pair");
    args_error=true;
    fi

    if [ -z ${soundbar_id+x} ]; then
    echo $(generate_error "Please supply the mac address of the soundbar you wish to pair a subwoofer with");
    args_error=true;
    fi

    if [ -z ${subwoofer_id+x} ]; then
    echo $(generate_error "Please supply the mac address of the device you wish to use as a subwoofer");
    args_error=true;
    fi

    if [ "$args_error" = "true" ]; then
    exit 2;
    fi

    payload=$(generate_envelope $soundbar_id $subwoofer_id)

    echo $payload | curl -v "http://$host:1400/DeviceProperties/Control" \
    -H "Host: $host:1400" \
    -H 'Content-Type: text/xml; charset=utf-8' \
    -H 'SOAPAction: urn:schemas-upnp-org:service:DeviceProperties:1#AddHTSatellite' \
    -H 'Accept: */*' \
    -H 'Accept-Language: en-au' \
    -H 'User-Agent: SonoSequencr/661 CFNetwork/1323 Darwin/21.1.0' \
    --data-binary @- --compressed