Squeezebox Radio Control Help

Posted on
Mon Mar 29, 2010 9:31 am
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Squeezebox Radio Control Help

I have this script located in the attachments folder and have it run on server startup.

-- SlimServer control attachment
--
-- This script provides functions for easily controlling SlimDevices
-- SLIMP3 or Squeezebox from Indigo Execute AppleScript actions.
--
-- Author: Andrew Turner (software at highearthorbit dot com)
-- Changes: Paul Roomberg (paul at pasaro dot nl)
-- Nick Sosnicki - 30 Oct 2006 - v1.2
-- -tested on Indigo 2.0b8, SlimServer 6.5.0
-- -added error trapping to shell scripts
-- -set the curl connect timeout to 5 seconds
-- and the curl transaction time limit to
-- 10 seconds (these can be increased if needed)
-- - added option to ping server and Squeezebox to
-- see if they are there before sending commands
-- -added support for multiple Squeezeboxes through
-- a nick name/IP address definition; this requires
-- an extra parm for each command
-- -to support multiple Squeezebox status, multiple
-- status variables are used; these will be created
-- automatically if needed
-- -changed slim server display function to allow
-- dynamic control of the time to display
-- Matt Bendiksen - 1 Jan 2007 - v1.2.1
-- -general cleanup, bug fixes, and added to base
-- Indigo 2.0 install
--
-- __Attachment Functions__ Can be called from within Indigo Execute AppleScript actions,
-- or any _tell app "IndigoServer"_ block. If the squeezebox nickname is blank, the first
-- one defined in the map will be used.
--
-- SlimServerDisplay("Line 1", "Line 2", seconds to display, "Squeeze Nickname")
-- SlimServerVolume(volume, "Squeeze Nickname")
-- volume: 0-100
-- SlimServerPlaySong("Song Name", "Squeeze Nickname")
-- SlimServerSkipFwd("Squeeze Nickname")
-- SlimServerSkipRew("Squeeze Nickname")
-- SlimServerPower(On or Off, "Squeeze Nickname")
-- On or Off: 0 is off, 1 is on
-- SlimServerCommand("Command","Squeeze Nickname")
-- available commands: "play", "pause", "stop", "sleep"
--
-- Status variable are named "SlimStatus" and the Squeezebox's nick name
-- for example, "SlimStatusupBath1" and "SlimStatusupBath2"

property slimIP : "10.0.1.2" -- slimserver IP address
property slimPort : "9000" -- slimserver web port

-- Map of Squeezebox nicknames and their IP addresses. MAC addresses
-- can be used instead, but you must set pingSqueeze to false (the ping
-- test cannot be used with MAC addresses). Add a new pair for every
-- Squeezebox you want to control.
property squeezeMap : {¬
    {"LivingRoom", "192.168.1.10"}, ¬
    {"MasterBedroom", "192.168.1.11"} ¬
        }

property pingSlim : true --if true, ping slimserver before commands
property pingSqueeze : true --if true, ping squeezebox before commands

property slimResponseText : ""

using terms from application "IndigoServer"
    on SlimServerCommand(theCommand, squeezeNick)
        SendToSlimServer(theCommand, 0, 0, 0, squeezeNick)
    end SlimServerCommand
    
    on SlimServerDisplay(displayString1, displayString2, displaySeconds, squeezeNick)
        set lineOne to _searchReplaceText(" ", "%20", displayString1)
        set lineTwo to _searchReplaceText(" ", "%20", displayString2)
        SendToSlimServer("display", lineOne, lineTwo, displaySeconds, squeezeNick)
    end SlimServerDisplay
    
    on SlimServerVolume(volume, squeezeNick)
        SendToSlimServer("mixer", "volume", volume, 0, squeezeNick)
    end SlimServerVolume
    
    on SlimServerPlaySong(songName, squeezeNick)
        SendToSlimServer("playlist", "play", songName, 0, squeezeNick)
        getSlimStatus(squeezeNick)
    end SlimServerPlaySong
    
    on SlimServerSkipFwd(squeezeNick)
        SendToSlimServer("button", "jump_fwd", 1, 0, squeezeNick)
        getSlimStatus(squeezeNick)
    end SlimServerSkipFwd
    
    on SlimServerSkipRew(squeezeNick)
        SendToSlimServer("button", "jump_rew", 0, 0, squeezeNick)
        getSlimStatus(squeezeNick)
    end SlimServerSkipRew
    
    on SlimServerPower(onOff, squeezeNick)
        SendToSlimServer("power", onOff, 0, 0, squeezeNick)
        getSlimStatus(squeezeNick)
    end SlimServerPower
    
    on SlimServerGetStatus(squeezeNick)
        SendToSlimServer("status", 0, 0, 0, squeezeNick)
        getSlimStatus(squeezeNick)
    end SlimServerGetStatus
    
    on SlimServerLog(logString)
        tell application "IndigoServer"
            log logString using type "SlimServer"
        end tell
    end SlimServerLog
    
    on getSlimStatus(squeezeNick)
        if squeezeNick is "" then
            set squeezeNick to item 1 of item 1 of squeezeMap
        end if
        tell application "IndigoServer"
            -- if a status variable pair does not exisit for this Squeeze's nick name, create it
            set statusVar1 to "SlimStatus" & squeezeNick & "1"
            set statusVar2 to "SlimStatus" & squeezeNick & "2"
            if not (variable statusVar1 exists) then
                make new variable with properties {name:statusVar1, value:first paragraph of slimResponseText}
            else
                set value of variable statusVar1 to the first paragraph of slimResponseText
            end if
            if not (variable statusVar2 exists) then
                make new variable with properties {name:statusVar2, value:last paragraph of slimResponseText}
            else
                set value of variable statusVar2 to the last paragraph of slimResponseText
            end if
        end tell
    end getSlimStatus
    
    on SendToSlimServer(p0, p1, p2, p3, squeezeNick)
        --lookup IP for squeeze box nickname if provided, else use first entry
        if squeezeNick is "" then
            set squeezeIP to item 2 of item 1 of squeezeMap
        else
            set squeezeIP to ""
            repeat with mapEntry in squeezeMap
                if item 1 of mapEntry is squeezeNick then
                    set squeezeIP to item 2 of mapEntry
                    exit repeat
                end if
            end repeat
        end if
        if squeezeIP is "" then
            SlimServerLog("Squeezebox nickname " & squeezeNick & " or IP address is not defined")
            return
        end if
        
        set pingSucess to true
        if pingSlim then --try to ping slimserver
            if not PingAddress(slimIP) then
                set pingSucess to false
                set slimResponseText to "SlimServer at " & slimIP & " not reachable"
                SlimServerLog("SlimServer at " & slimIP & " not reachable")
            end if
        end if
        if pingSqueeze then --try to ping squeezebox
            if not PingAddress(squeezeIP) then
                set pingSucess to false
                set slimResponseText to "Squeezebox at " & squeezeIP & " not reachable"
                SlimServerLog("Squeezebox at " & squeezeIP & " not reachable")
            end if
        end if
        if pingSucess then
            set h to "http://" & slimIP & ":" & slimPort & "/status.txt"
            set d to h & "?p0=" & p0
            if p1 is not equal to 0 then set d to d & "&p1=" & p1
            if p2 is not equal to 0 then set d to d & "&p2=" & p2
            if p3 is not equal to 0 then set d to d & "&p3=" & p3
            set d to d & "&player=" & squeezeIP
            try
                set slimResponseText to doShellScript("curl --connect-timeout 5 --max-time 10 --get -d --url \"" & d & "\" ")
            on error errStatement number errNum
                set slimResponseText to "Connection error (CURL): " & errNum
                SlimServerLog("Connection error (CURL) with SlimServer at " & slimIP & "; error number: " & errNum)
            end try
        end if
    end SendToSlimServer
end using terms from

-- Pings given address and returns true if there were no errors, false if there were errors
on PingAddress(IPAddress)
    set errTest to true
    try
        set ping_result to doShellScript("ping -o -q -n -t 3 " & IPAddress)
    on error errStatement number errNum
        set errTest to false
    end try
    return errTest
end PingAddress

-- Glue for shell scripts to ensure correct environmental vars are used
on doShellScript(scriptStr)
    tell application "Finder" to set returnVal to do shell script scriptStr
    return returnVal
end doShellScript

(*
_searchReplaceText(searchTerm, replaceTerm, theText)
Replaces a string found in a text by another string.
This handle supports lists of search/replace terms.

Parameters:
searchTerm: the text to search for
replaceTerm: the text to use as replacement
theText: the text to search/replace

Examples:
_searchReplaceText("foo", "bar", "You are a foo") --> "You are a bar"
_searchReplaceText({"foo", " a "}, {"bar", " one "}, "You are a foo") --> "You are one bar"
*)
to _searchReplaceText(searchTerm, replaceTerm, theText)
    set searchTerm to searchTerm as list
    set replaceTerm to replaceTerm as list
    set theText to theText as text
    
    set oldTID to AppleScript's text item delimiters
    repeat with i from 1 to count searchTerm
        set AppleScript's text item delimiters to searchTerm's item i
        set theText to theText's text items
        set AppleScript's text item delimiters to replaceTerm's item i
        set theText to theText as text
    end repeat
    set AppleScript's text item delimiters to oldTID
    return theText
end _searchReplaceText


I then execute this as an action to turn the radio off: SlimServerPower("0", "Squeeze Nickname")

I've tried to read and understand how this all works but can't seem to get it to work.
I see in the Squeezebox server info the server is 10.0.1.2 but the radio itself has a different address, 10.0.1.23
I assume the server info is correct to enter into the script, not the radio itself?

Any help greatly appreciated!

Carl

Posted on
Mon Mar 29, 2010 4:52 pm
anode offline
Posts: 697
Joined: May 27, 2007
Location: NC

Re: Squeezebox Radio Control Help

ckeyes888 wrote:
property slimIP : "10.0.1.2" -- slimserver IP address
property slimPort : "9000" -- slimserver web port

-- Map of Squeezebox nicknames and their IP addresses. MAC addresses
-- can be used instead, but you must set pingSqueeze to false (the ping
-- test cannot be used with MAC addresses). Add a new pair for every
-- Squeezebox you want to control.
property squeezeMap : {¬
{"LivingRoom", "192.168.1.10"}, ¬
{"MasterBedroom", "192.168.1.11"} ¬
}


Is the 10.0.x.x in the routing table? (I do believe that the 10.0.x.x is non-internet subnet like the 192.168.x.x i ie: only used for internal networks)
Also whats it doing/not doing?

Posted on
Mon Mar 29, 2010 11:20 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Squeezebox Radio Control Help

Sorry, don't know what a routing table is. The 10.0.1.2 is what's listed in the system prefs under the Squeezebox server info for the IP address.
If that's not it I don't know where else to look.

I haven't been able to get any functions to work.

This is the event return:

SlimServer Squeezebox nickname KitchenRadio or IP address is not defined
Error script error: in file "slimserver attachment mine.scpt"
Error script error: Can’t get paragraph 1 of "". (-1728)
Error error dispatching event to attachment script (-1753)
Error script error: around characters 0 to 36
Error script error: Can’t get paragraph 1 of "". (-1708)

Squeezebox Server Status

Version: 7.4.2 - r30215 @ Mon Feb 22 12:40:30 PST 2010
Hostname: Macintosh.local
Server IP Address: 10.0.1.2
Server HTTP Port Number: 9000
Operating system: Mac OS X 10.5.8 - EN - utf8
Platform Architecture: x86
Perl Version: 5.8.8 - darwin-thread-multi-2level
MySQL Version: 5.0.22-standard
Total Players Recognized: 0


Carl

Posted on
Tue Mar 30, 2010 3:28 pm
BillC offline
Posts: 237
Joined: Mar 09, 2008

Re: Squeezebox Radio Control Help

If I'm reading the code correctly, you've defined the server but not "KitchenRadio".
Let's try this (I don't use squeezebox, just checking the code for consistency):

find this portion of the script:
Code: Select all
property slimIP : "10.0.1.2" -- slimserver IP address
property slimPort : "9000" -- slimserver web port

-- Map of Squeezebox nicknames and their IP addresses. MAC addresses
-- can be used instead, but you must set pingSqueeze to false (the ping
-- test cannot be used with MAC addresses). Add a new pair for every
-- Squeezebox you want to control.
property squeezeMap : {¬
    {"LivingRoom", "192.168.1.10"}, ¬
    {"MasterBedroom", "192.168.1.11"} ¬
        }


And change to (changes are only in "property squeezeMap" section):
Code: Select all
property slimIP : "10.0.1.2" -- slimserver IP address
property slimPort : "9000" -- slimserver web port

-- Map of Squeezebox nicknames and their IP addresses. MAC addresses
-- can be used instead, but you must set pingSqueeze to false (the ping
-- test cannot be used with MAC addresses). Add a new pair for every
-- Squeezebox you want to control.
property squeezeMap : {¬
    {"KitchenRadio", "10.0.1.23"}, ¬
        }


192.168.x.x and 10.x.x.x are "private" address spaces used only on LANs, not on the internet. 192.168.x.x is common for home use so that's what the code examples used; the 10.x.x.x space is equally valid.

Above assumes the following is correct:
I see in the Squeezebox server info the server is 10.0.1.2 but the radio itself has a different address, 10.0.1.23

Posted on
Tue Mar 30, 2010 3:42 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Squeezebox Radio Control Help

Thanks Bill. I put in those numbers and still get this back in the event log:

Action Group Power Play Kitchen Radio
SlimServer Squeezebox nickname Kitchen_Radio or IP address is not defined

This is the "Action" i use to execute :

SlimServerCommand("play", "Kitchen_Radio")

Lost in script land,

Carl

P.S. Sorry I'm such a weenie at this...
I'm hoping there's a "Apple script for Dummies" book out there.

Posted on
Tue Mar 30, 2010 5:23 pm
BillC offline
Posts: 237
Joined: Mar 09, 2008

Re: Squeezebox Radio Control Help

You're almost there.

There's a difference between "Kitchen_Radio" and "KitchenRadio"

EITHER change your action to:

Code: Select all
SlimServerCommand("play", "KitchenRadio")


OR change the script definition to:

Code: Select all
property squeezeMap : {¬
    {"Kitchen_Radio", "10.0.1.23"}, ¬
        }

Posted on
Wed Mar 31, 2010 11:56 am
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Squeezebox Radio Control Help

Thanks Bill. I've confirmed the name of the radio as Kitchen_Radio
and tried your suggestion but still no go.

Action Group Power Play Kitchen_Radio
SlimServer Squeezebox nickname Kitchen_Radio or IP address is not defined


Here's what I have in the script:
property slimIP : "10.0.1.2" -- slimserver IP address
property slimPort : "9000" -- slimserver web port

property squeezeMap : {¬
    {"Kitchen_Radio", "10.0.1.32"}, ¬
    {"MasterBedroom", "192.168.1.11"} ¬
        }

and here's what I'm executing:
SlimServerCommand("play", "Kitchen_Radio")

and this is what I get in the event log:
SlimServer Squeezebox nickname Kitchen_Radio or IP address is not defined


I see that most every time I check the radio's IP address it has changed. Not sure how any script could work
if that's the case.

I tried removing the {"MasterBedroom", "192.168.1.11"} ¬ entry, as I only have the one unit, but it won't compile with it gone.

Thanks,

Cal

Posted on
Wed Mar 31, 2010 1:57 pm
BillC offline
Posts: 237
Joined: Mar 09, 2008

Re: Squeezebox Radio Control Help

Here's where the script is failing (where the error log entry is coming from...last section of code):
Code: Select all
on SendToSlimServer(p0, p1, p2, p3, squeezeNick)
      --lookup IP for squeeze box nickname if provided, else use first entry
      if squeezeNick is "" then
         set squeezeIP to item 2 of item 1 of squeezeMap
      else
         set squeezeIP to ""
         repeat with mapEntry in squeezeMap
            if item 1 of mapEntry is squeezeNick then
               set squeezeIP to item 2 of mapEntry
               exit repeat
            end if
         end repeat
      end if
      if squeezeIP is "" then
         SlimServerLog("Squeezebox nickname " & squeezeNick & " or IP address is not defined")
         return
      end if


...and I'm not sure why. At that point the script hasn't tried to send a command so a wrong IP wouldn't matter....the problem is that the script is failing to set an IP for the variable squeezeIP; the variable is set to null ("") so it returns with the error.

Since you only have one receiver, the code isn't really needed. For troubleshooting purposes (or until you get another receiver), you could comment out the logic that sets squeezeIP to match a receiver name, and assign it directly:
Code: Select all
on SendToSlimServer(p0, p1, p2, p3, squeezeNick)

           --explicitly set value for squeezeIP
           set squeezeIP to "10.0.1.32"

      --lookup IP for squeeze box nickname if provided, else use first entry
(*      if squeezeNick is "" then
         set squeezeIP to item 2 of item 1 of squeezeMap
      else
         set squeezeIP to ""
         repeat with mapEntry in squeezeMap
            if item 1 of mapEntry is squeezeNick then
               set squeezeIP to item 2 of mapEntry
               exit repeat
            end if
         end repeat
      end if
      if squeezeIP is "" then
         SlimServerLog("Squeezebox nickname " & squeezeNick & " or IP address is not defined")
         return
      end if
*)


(The (* and *) define a comment block)

It doesn't matter with the above workaround...explicit declaration of squeezeIP...but you should be able to delete the MasterBedroom line and have it compile; my fault in the examples I sent you. You'll need to remove the comma after the last curly brace in the Kitchen_Radio line so the compiler won't be expecting another entry in the list.
Code: Select all
property squeezeMap : {¬
    {"Kitchen_Radio", "10.0.1.32"} ¬
    }



You also need to deal with the fluctuating IP address on the receiver. If I recall correctly (it's been a few years since I played with SlimDevices) you can set the receiver to a fixed IP through the startup routine on the receiver. You can also use the mac address of the receiver to give it a fixed address in your router's DHCP tables. The script notes say you can use the mac address of the receiver (it'll be on a label on the receiver) instead of the IP address, but I'm not sure how to enter it... you could replace the IP address in the "set squeezeIP to" statement in the second code block above with the mac address in the form "00:00:00:00:00:00" (six pairs of hex digits separated by colons).

Hopefully someone who has this script working will jump in...I'm just attacking the logic but can't test it.

Posted on
Wed Mar 31, 2010 2:37 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Squeezebox Radio Control Help

Really appreciate your efforts Bill but nothing seems to work.

I tried:
property squeezeMap : {¬
    {"Kitchen_Radio", "00:04:20:26:e4:25"} ¬
        }

I also tried to insert the code you suggested and comment out the above but the script won't compile.

Thanks,

Carl

Posted on
Wed Mar 31, 2010 3:22 pm
BillC offline
Posts: 237
Joined: Mar 09, 2008

Re: Squeezebox Radio Control Help

Hmmm....It compiles for me. Here's the whole script with the changes so far...check the slimserver and receiver IP's to make sure they are correct...this code compiles for me; I just can't run it.

Code: Select all
-- SlimServer control attachment
--
-- This script provides functions for easily controlling SlimDevices
-- SLIMP3 or Squeezebox from Indigo Execute AppleScript actions.
--
-- Author:   Andrew Turner (software at highearthorbit dot com)
-- Changes:   Paul Roomberg (paul at pasaro dot nl)
--         Nick Sosnicki - 30 Oct 2006 - v1.2
--            -tested on Indigo 2.0b8, SlimServer 6.5.0
--            -added error trapping to shell scripts
--            -set the curl connect timeout to 5 seconds
--               and the curl transaction time limit to
--               10 seconds (these can be increased if needed)
--            - added option to ping server and Squeezebox to
--               see if they are there before sending commands
--            -added support for multiple Squeezeboxes through
--               a nick name/IP address definition; this requires
--               an extra parm for each command
--            -to support multiple Squeezebox status, multiple
--               status variables are used; these will be created
--               automatically if needed
--            -changed slim server display function to allow
--               dynamic control of the time to display
--         Matt Bendiksen - 1 Jan 2007 - v1.2.1
--            -general cleanup, bug fixes, and added to base
--               Indigo 2.0 install
--
-- __Attachment Functions__ Can be called from within Indigo Execute AppleScript actions,
-- or any _tell app "IndigoServer"_ block. If the squeezebox nickname is blank, the first
-- one defined in the map will be used.
--
--   SlimServerDisplay("Line 1", "Line 2", seconds to display, "Squeeze Nickname")
--   SlimServerVolume(volume, "Squeeze Nickname")
--      volume: 0-100
--   SlimServerPlaySong("Song Name", "Squeeze Nickname")
--   SlimServerSkipFwd("Squeeze Nickname")
--   SlimServerSkipRew("Squeeze Nickname")
--   SlimServerPower(On or Off, "Squeeze Nickname")
--      On or Off: 0 is off, 1 is on
--   SlimServerCommand("Command","Squeeze Nickname")
--      available commands: "play", "pause", "stop", "sleep"
--
--   Status variable are named "SlimStatus" and the Squeezebox's nick name
--      for example, "SlimStatusupBath1" and "SlimStatusupBath2"

property slimIP : "10.0.1.2" -- slimserver IP address
property slimPort : "9000" -- slimserver web port

-- Map of Squeezebox nicknames and their IP addresses. MAC addresses
-- can be used instead, but you must set pingSqueeze to false (the ping
-- test cannot be used with MAC addresses). Add a new pair for every
-- Squeezebox you want to control.
property squeezeMap : {¬
   {"Kitchen_Radio", "10.0.1.32"} ¬
      }

property pingSlim : true --if true, ping slimserver before commands
property pingSqueeze : true --if true, ping squeezebox before commands

property slimResponseText : ""

using terms from application "IndigoServer"
   on SlimServerCommand(theCommand, squeezeNick)
      SendToSlimServer(theCommand, 0, 0, 0, squeezeNick)
   end SlimServerCommand
   
   on SlimServerDisplay(displayString1, displayString2, displaySeconds, squeezeNick)
      set lineOne to _searchReplaceText(" ", "%20", displayString1)
      set lineTwo to _searchReplaceText(" ", "%20", displayString2)
      SendToSlimServer("display", lineOne, lineTwo, displaySeconds, squeezeNick)
   end SlimServerDisplay
   
   on SlimServerVolume(volume, squeezeNick)
      SendToSlimServer("mixer", "volume", volume, 0, squeezeNick)
   end SlimServerVolume
   
   on SlimServerPlaySong(songName, squeezeNick)
      SendToSlimServer("playlist", "play", songName, 0, squeezeNick)
      GetSlimStatus(squeezeNick)
   end SlimServerPlaySong
   
   on SlimServerSkipFwd(squeezeNick)
      SendToSlimServer("button", "jump_fwd", 1, 0, squeezeNick)
      GetSlimStatus(squeezeNick)
   end SlimServerSkipFwd
   
   on SlimServerSkipRew(squeezeNick)
      SendToSlimServer("button", "jump_rew", 0, 0, squeezeNick)
      GetSlimStatus(squeezeNick)
   end SlimServerSkipRew
   
   on SlimServerPower(onOff, squeezeNick)
      SendToSlimServer("power", onOff, 0, 0, squeezeNick)
      GetSlimStatus(squeezeNick)
   end SlimServerPower
   
   on SlimServerGetStatus(squeezeNick)
      SendToSlimServer("status", 0, 0, 0, squeezeNick)
      GetSlimStatus(squeezeNick)
   end SlimServerGetStatus
   
   on SlimServerLog(logString)
      tell application "IndigoServer"
         log logString using type "SlimServer"
      end tell
   end SlimServerLog
   
   on GetSlimStatus(squeezeNick)
      if squeezeNick is "" then
         set squeezeNick to item 1 of item 1 of squeezeMap
      end if
      tell application "IndigoServer"
         -- if a status variable pair does not exisit for this Squeeze's nick name, create it
         set statusVar1 to "SlimStatus" & squeezeNick & "1"
         set statusVar2 to "SlimStatus" & squeezeNick & "2"
         if not (variable statusVar1 exists) then
            make new variable with properties {name:statusVar1, value:first paragraph of slimResponseText}
         else
            set value of variable statusVar1 to the first paragraph of slimResponseText
         end if
         if not (variable statusVar2 exists) then
            make new variable with properties {name:statusVar2, value:last paragraph of slimResponseText}
         else
            set value of variable statusVar2 to the last paragraph of slimResponseText
         end if
      end tell
   end GetSlimStatus
   
   on SendToSlimServer(p0, p1, p2, p3, squeezeNick)
      -- explicitly set variable
      set squeezeIP to "10.0.1.32"
      --lookup IP for squeeze box nickname if provided, else use first entry
      (*      if squeezeNick is "" then
         set squeezeIP to item 2 of item 1 of squeezeMap
      else
         set squeezeIP to ""
         repeat with mapEntry in squeezeMap
            if item 1 of mapEntry is squeezeNick then
               set squeezeIP to item 2 of mapEntry
               exit repeat
            end if
         end repeat
      end if
      if squeezeIP is "" then
         SlimServerLog("Squeezebox nickname " & squeezeNick & " or IP address is not defined")
         return
      end if
*)
      set pingSucess to true
      if pingSlim then --try to ping slimserver
         if not PingAddress(slimIP) then
            set pingSucess to false
            set slimResponseText to "SlimServer at " & slimIP & " not reachable"
            SlimServerLog("SlimServer at " & slimIP & " not reachable")
         end if
      end if
      if pingSqueeze then --try to ping squeezebox
         if not PingAddress(squeezeIP) then
            set pingSucess to false
            set slimResponseText to "Squeezebox at " & squeezeIP & " not reachable"
            SlimServerLog("Squeezebox at " & squeezeIP & " not reachable")
         end if
      end if
      if pingSucess then
         set h to "http://" & slimIP & ":" & slimPort & "/status.txt"
         set d to h & "?p0=" & p0
         if p1 is not equal to 0 then set d to d & "&p1=" & p1
         if p2 is not equal to 0 then set d to d & "&p2=" & p2
         if p3 is not equal to 0 then set d to d & "&p3=" & p3
         set d to d & "&player=" & squeezeIP
         try
            set slimResponseText to DoShellScript("curl --connect-timeout 5 --max-time 10 --get -d --url \"" & d & "\" ")
         on error errStatement number errNum
            set slimResponseText to "Connection error (CURL): " & errNum
            SlimServerLog("Connection error (CURL) with SlimServer at " & slimIP & "; error number: " & errNum)
         end try
      end if
   end SendToSlimServer
end using terms from

-- Pings given address and returns true if there were no errors, false if there were errors
on PingAddress(IPAddress)
   set errTest to true
   try
      set ping_result to DoShellScript("ping -o -q -n -t 3  " & IPAddress)
   on error errStatement number errNum
      set errTest to false
   end try
   return errTest
end PingAddress

-- Glue for shell scripts to ensure correct environmental vars are used
on DoShellScript(scriptStr)
   tell application "Finder" to set returnVal to do shell script scriptStr
   return returnVal
end DoShellScript

(*
   _searchReplaceText(searchTerm, replaceTerm, theText)
   Replaces a string found in a text by another string.
   This handle supports lists of search/replace terms.

   Parameters:
      searchTerm: the text to search for
      replaceTerm: the text to use as replacement
      theText: the text to search/replace

   Examples:
      _searchReplaceText("foo", "bar", "You are a foo") --> "You are a bar"
      _searchReplaceText({"foo", " a "}, {"bar", " one "}, "You are a foo") --> "You are one bar"
*)
to _searchReplaceText(searchTerm, replaceTerm, theText)
   set searchTerm to searchTerm as list
   set replaceTerm to replaceTerm as list
   set theText to theText as text
   
   set oldTID to AppleScript's text item delimiters
   repeat with i from 1 to count searchTerm
      set AppleScript's text item delimiters to searchTerm's item i
      set theText to theText's text items
      set AppleScript's text item delimiters to replaceTerm's item i
      set theText to theText as text
   end repeat
   set AppleScript's text item delimiters to oldTID
   return theText
end _searchReplaceText

Posted on
Wed Mar 31, 2010 3:39 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Squeezebox Radio Control Help

Still same problem:
SlimServer Squeezebox nickname Kitchen_Radio or IP address is not defined

I'm assuming the script can be run by clicking the "Execute Actions Now" button at the bottom right
of the screen? When I do that this shows in the event log: Trigger Action Squeezebox Script
Hate to think I haven't been implementing the script changes correctly.

Thanks,

Carl

Posted on
Wed Mar 31, 2010 5:22 pm
BillC offline
Posts: 237
Joined: Mar 09, 2008

Re: Squeezebox Radio Control Help

If you are actually running the script in my last post, you will not get the "SlimServer Squeezebox nickname Kitchen_Radio or IP address is not defined" log entry. The code that generates that entry is commented out.

Have you been making the changes in Script Editor? Have you been saving the changed file? Is the file located in /Library/Application Support/Perceptive Automation/Indigo 4/Scripts/Attachments/ ?

Close out script editor app and go to the above folder...open the slimserver attachment.scpt and see what's in it.

Somehow I think you're not executing the script you've been editing.

Posted on
Wed Mar 31, 2010 6:43 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Squeezebox Radio Control Help

Thanks a bunch for all your help Bill. Got most all functions working.

Are you familiar with how the: SlimServerPlaySong("Song Name", "Squeeze Nickname") works?

I've been inserting some song titles from iTunes but the display shows "Nothing".

Thanks again,

Carl
Last edited by ckeyes888 on Wed Mar 31, 2010 7:57 pm, edited 1 time in total.

Posted on
Wed Mar 31, 2010 7:52 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Squeezebox Radio Control Help

One other thing... anyone know how to access the radio by it's MAC address instead of the IP in the script?
Been trying it but no go so far. The IP seems to change a lot more often than I'd like to modify the script to keep it working.

Thanks,

Carl

Posted on
Wed Mar 31, 2010 8:37 pm
seanadams offline
Posts: 489
Joined: Mar 19, 2008
Location: Saratoga, CA

Re: Squeezebox Radio Control Help

MAC address is always the proper way to identify a Squeezebox. This script should not have used IP.

Try just putting MACs in place of the IPs. If you read the script he says it should work. Also on this line change true to false:

property pingSqueeze : true --if true, ping squeezebox before commands

Who is online

Users browsing this forum: No registered users and 8 guests

cron