Posts: 174
Threads: 34
Joined: Feb 2017
Reputation:
3
(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
Posts: 1626
Threads: 5
Joined: Jul 2015
Reputation:
102
29.06.2020, 14:06
(This post was last modified: 29.06.2020, 14:07 by Erwin van der Zwart.)
Hi,
Try this script, it is stand alone and it does not uses any of the (old) Sonos App files
BR,
Erwin
Posts: 174
Threads: 34
Joined: Feb 2017
Reputation:
3
30.06.2020, 08:00
(This post was last modified: 30.06.2020, 08:18 by Trond Hoyem.)
(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
Posts: 1626
Threads: 5
Joined: Jul 2015
Reputation:
102
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
Posts: 174
Threads: 34
Joined: Feb 2017
Reputation:
3
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
Posts: 1626
Threads: 5
Joined: Jul 2015
Reputation:
102
Hi,
Why are you looping through all players and not using the sayall command?
BR,
Erwin
Posts: 174
Threads: 34
Joined: Feb 2017
Reputation:
3
(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
Posts: 56
Threads: 27
Joined: May 2018
Reputation:
1
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?
Posts: 175
Threads: 58
Joined: Sep 2015
Reputation:
0
09.04.2022, 02:42
(This post was last modified: 13.04.2022, 01:35 by phongvucba.)
Hi guys !
I don't know if anyone still uses the Sonos app now? I'm using it and haven't seen any errors yet. Has anyone switched to Sonos API's Sonos?
I use Sonos API and have a few questions that I can't answer, I really need your help:
( https://developer.sonos.com/reference/au...ation-api/)
( https://forum.logicmachine.net/showthrea...15&page=14)
-require('custom.sonos.lib') -->Where do I get this library? And where to put in LM5?  (
-I also want to add the command line:
Adjust the volume to increase or decrease a certain range.
-sonos_app.SendApiActionCommand(groupID, 'playPlaylist',1) ---This command, it makes my queue add a lot of songs over and over again 
-sonos_app.SendApiActionCommand(groupID, 'setPlayModes', 'repeat') --it didn't work for me, even though i tried repeatOne,shuffle,v.v..
--------------------------
I use Sonos app and have a few questions that I can't answer, I really need your help:
-How can I Load 1 Playlists that I have created, for example named Demo1 and Demo2. Because if these playlists can be played, customers can add their own favorite songs  . Very helpful
"http://192.168.100.5/user/sonos.lp?action=loadplaylist&uuid=RINCON_F0F6C126547C01400&listname=Demo2&autoplay=true "
I tried the above and it doesn't work! 
-How can I play a playlist that I save on LM5 (via ftp is apps)
-Can I get Sonos' status? (eg status play,mute,volume.etc...)
Thank so much everyone !
|