This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

SONOS app
(05.06.2020, 14:46)Erwin van der Zwart Wrote: Hi,

What source are you playing from? We store the current URI when playing the mp3 and works with Intune Radio, but it might be that playing Spotify or other service has another methode then the URI we store and That might be the cause of what you experience. Can you test it with a radio station playing?

BR,

Erwin
Hi Erwin

That was the cause... I was playing from Spotify, but tested now with a radio station in the Sonos app, and then it worked.
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
Hi,

Try this script, it is stand alone and it does not uses any of the (old) Sonos App files

.lua   Sonos doorbell by script.lua (Size: 14.84 KB / Downloads: 15)

BR,

Erwin
Reply
(29.06.2020, 14:06)Erwin van der Zwart Wrote: Hi,

Try this script, it is stand alone and it does not uses any of the (old) Sonos App files


BR,

Erwin

Nothing happens when running it. 

I changed the start of the script to;

Code:
    playername = 'Kontor'
  renew_stored_player_data = true  -- set to true to force a network scan and renew stored player data table
    audiofile = 'http://192.168.39.10/user/Ringeklokke.mp3'
    duration = 10 -- duration of the audiofile
    volume = 10

I am soon ready to give up the sonos integration. It seems that what I need to do is not possible, or I am just not able to do it...

What I need to do is the following:
- If I get a TRUE on my object, I want to play a mp3 file from the ftp of LM on a certain player.
- If I get a FALSE on my object, the playing of the mp3 shold stop.

I am able to play the file on the player I want with the old API created by Erwin. But it seems that to stop it when playing is not possible as it always play the complete file. As I am playing a file to indicate that the alarm is triggered, I naturally need the file to stop when I reset the alarm by entering the code.

Is this even possible, or should I simply tell the customer that we need to go for a totally different solution?
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
Hi,

This is the most cleaned methode to do what you need:
Code:
-- Function to execute Sonos requests
function upnpavcmd(host, port, cmd, param)
  local client, soap, reqs, service, res, err
  require('socket')
  client = socket.tcp()
  client:settimeout(3)
  -- try connecting to upnp endpoint
  res, err = client:connect(host, port)
  if not res then
      return nil, err
  end
  -- guess service name based on command
  if cmd == 'SetVolume' or
     cmd == 'GetVolume' or
     cmd == 'SetMute' or
     cmd == 'GetMute' or
     cmd == 'SetBass' or
     cmd == 'GetBass' or
     cmd == 'SetTreble' or
     cmd == 'GetTreble' or
     cmd == 'SetLoudness' or
     cmd == 'GetLoudness' then
    base = 'MediaRenderer'
    service = 'RenderingControl'
  elseif cmd == 'Browse' then
    base = 'MediaServer'
    service = 'ContentDirectory'
  else
    base = 'MediaRenderer'
    service = 'AVTransport'
  end
  -- soap envelope
  soap = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' ..
           '<s:Body>' ..
             '<u:' .. cmd .. ' xmlns:u="urn:schemas-upnp-org:service:' .. service .. ':1">' ..
               '<InstanceID>0</InstanceID>' ..
               (param or '') ..
             '</u:' .. cmd .. '>' ..
           '</s:Body>' ..
         '</s:Envelope>'
  -- http request   
  reqs = 'POST /' .. base .. '/' .. service .. '/Control HTTP/1.1\r\n' ..
         'CONNECTION: close\r\n' ..
         'HOST: ' .. host .. ':' .. port .. '\r\n' ..
         'CONTENT-LENGTH: ' .. soap:len() .. '\r\n' ..
         'CONTENT-TYPE: text/xml; charset="utf-8"\r\n' ..
         'SOAPACTION: "urn:schemas-upnp-org:service:' .. service .. ':1#' .. cmd .. '"\r\n' ..
         '\r\n' .. soap
  -- send http request
  res, err = client:send(reqs)
  if not res then
    return nil, err
  end
  -- get reply and close connection
  res, err = client:receive('*a')
  client:close()
  return res, err
end


if event.getvalue() == true then
  upnpavcmd('192.168.10.181', 1400, 'SetVolume', '<Channel>Master</Channel><DesiredVolume>30</DesiredVolume>')
  upnpavcmd('192.168.10.181', 1400, 'SetAVTransportURI', '<CurrentURI>x-rincon-mp3radio://http://192.168.0.10/user/deurbel.mp3</CurrentURI><CurrentURIMetaData/>')
  upnpavcmd('192.168.10.181', 1400, 'Play', '<Speed>1</Speed>')
else
  upnpavcmd('192.168.10.181', 1400, 'Pause')
end
BR,

Erwin
Reply
I got it to somewhat work by doing like this:

Code:
if alarm then
  --alert('Brannalarm utløst i ' .. text)
  for _, PlayerID in ipairs(players) do
    --http://127.0.0.1/user/sonos.lp?action=say&uuid=' .. PlayerID .. '&audiofile=' .. audiofile .. '&volume=15&duration=200
    reply = socket.http.request('http://127.0.0.1/user/sonos.lp?action=say&uuid=' .. PlayerID .. '&audiofile=' .. audiofile .. '&volume=80&duration=200')
    log(PlayerID)
  end
  log(alarm, reply)
else
  for _, PlayerID in ipairs(players) do
    reply = socket.http.request('http://127.0.0.1/user/sonos.lp?action=stop&uuid=' .. PlayerID ..'')
  end
  log(alarm, reply)
end

But then there is a delay in this sonos function so that it takes a lot of time to start all the players I have in the list. 

I also now esperienced another challenge; I did a scan in the sonos network to verify my player ID's, and then the log from that scan is too long for the log-window, and I cannot see all players. Is there a way to list only player name and ID? There is a lot of information in the normal scan, and so it is not possible to see the complete result.
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
Hi,

Why are you looping through all players and not using the sayall command?

BR,

Erwin
Reply
(30.06.2020, 22:40)Erwin van der Zwart Wrote: Hi,

Why are you looping through all players and not using the sayall command?

BR,

Erwin
Because I should not use all players, but a selection of them.
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
Hello,

We have a problem with one client and Sonos system. I have installed Sonos app in our LogicMachine. It finds the Sonos and everything is fine till it comes to controlling it – controls are very delayed. For example, if I press pause on a song from the app from LogicMachine, it pauses it after 10-30 seconds. Internet connection is strong (100mbps). The particular Sonos model is „Sonos Connect“ and it is used to stream audio to „Denon“ amplifier. Sonos is connected to internet via cable. Where could be the problem?
Reply


Forum Jump: