26.03.2018, 19:12
please is very easy to help me because I am a beginner with them
the ip ip from wiser is 192.168.1.50
my sonos ip is 192.168.1.7 and 192.168.1.8
thank you in advance.
-- Load modules
require('json')
require('socket.http')
-- Set timout
socket.http.TIMEOUT = 5
-- Read IP address from controller
data = io.readproc('if-json')
data = json.decode(data)
ip = data.eth0.inetaddr
-- Set SONOS name
Sonos_Player_Name = 'dining'
-- Get event value
value = event.getvalue()
-- Set stepsize volume
Volume_Step = 10
-- Set Action
if value == 101 then
Sonos_Action = 'play'
elseif value == 102 then
Sonos_Action = 'stop'
elseif value == 103 then
Sonos_Action = 'next'
elseif value == 104 then
Sonos_Action = 'previous'
elseif value == 105 then
Sonos_Action = 'mute'
elseif value == 106 then
Sonos_Action = 'unmute'
elseif value == 107 then
Sonos_Action = 'setvolumeup'
Volume_Step = Volume_Step or 10
elseif value == 108 then
Sonos_Action = 'setvolumedown'
Volume_Step = Volume_Step or 10
else
action = 'none'
end
-- Execute action on value 0 to 100
if value >= 0 and value <= 100 then
local reply = socket.http.request('http://'192.168.1.50'/apps/data/sonos/sonos.lp?action=setvolume&name=' .. dining.. '&volume=' .. value .. '')
end
-- Execute action on value 101 to 106
if value >= 101 and value <= 106 then
local reply = socket.http.request('http://'192.168.1.50'/apps/data/sonos/sonos.lp?action=' .. Sonos_Action .. '&name=' ..dining.. '')
end
-- Execute action on value 107 to 108
if value >= 107 and value <= 108 then
local reply = socket.http.request('http://'192.168.1.50'/apps/data/sonos/sonos.lp?action=' .. Sonos_Action .. '&name=' ..dining .. '&step=' .. Volume_Step .. '')
end
-- Execute action on value 255 (Feedback)
if value == 255 then
local reply = socket.http.request('http://'192.168.1.50'/apps/data/sonos/sonos.lp?action=getextendedstate&name=' ..dining.. '&createbaseimg=true')
reply = json.pdecode(reply)
if reply then
local current_volume = reply[1].volume
local current_mutestate = reply[2].mute
local current_crossfadestate = reply[3].crossfade
local current_playmode = reply[4].playmode
local current_transportmode = reply[5].transport
local current_duration = reply[7].duration
local current_playingtime = reply[8].playingtime
local current_title = reply[9].tracktitle
local current_artist = reply[10].creator
local current_album = reply[11].album
local current_albumart = reply[12].albumart
local current_mediatype = reply[11].mediatype
end
end
the ip ip from wiser is 192.168.1.50
my sonos ip is 192.168.1.7 and 192.168.1.8
thank you in advance.
-- Load modules
require('json')
require('socket.http')
-- Set timout
socket.http.TIMEOUT = 5
-- Read IP address from controller
data = io.readproc('if-json')
data = json.decode(data)
ip = data.eth0.inetaddr
-- Set SONOS name
Sonos_Player_Name = 'dining'
-- Get event value
value = event.getvalue()
-- Set stepsize volume
Volume_Step = 10
-- Set Action
if value == 101 then
Sonos_Action = 'play'
elseif value == 102 then
Sonos_Action = 'stop'
elseif value == 103 then
Sonos_Action = 'next'
elseif value == 104 then
Sonos_Action = 'previous'
elseif value == 105 then
Sonos_Action = 'mute'
elseif value == 106 then
Sonos_Action = 'unmute'
elseif value == 107 then
Sonos_Action = 'setvolumeup'
Volume_Step = Volume_Step or 10
elseif value == 108 then
Sonos_Action = 'setvolumedown'
Volume_Step = Volume_Step or 10
else
action = 'none'
end
-- Execute action on value 0 to 100
if value >= 0 and value <= 100 then
local reply = socket.http.request('http://'192.168.1.50'/apps/data/sonos/sonos.lp?action=setvolume&name=' .. dining.. '&volume=' .. value .. '')
end
-- Execute action on value 101 to 106
if value >= 101 and value <= 106 then
local reply = socket.http.request('http://'192.168.1.50'/apps/data/sonos/sonos.lp?action=' .. Sonos_Action .. '&name=' ..dining.. '')
end
-- Execute action on value 107 to 108
if value >= 107 and value <= 108 then
local reply = socket.http.request('http://'192.168.1.50'/apps/data/sonos/sonos.lp?action=' .. Sonos_Action .. '&name=' ..dining .. '&step=' .. Volume_Step .. '')
end
-- Execute action on value 255 (Feedback)
if value == 255 then
local reply = socket.http.request('http://'192.168.1.50'/apps/data/sonos/sonos.lp?action=getextendedstate&name=' ..dining.. '&createbaseimg=true')
reply = json.pdecode(reply)
if reply then
local current_volume = reply[1].volume
local current_mutestate = reply[2].mute
local current_crossfadestate = reply[3].crossfade
local current_playmode = reply[4].playmode
local current_transportmode = reply[5].transport
local current_duration = reply[7].duration
local current_playingtime = reply[8].playingtime
local current_title = reply[9].tracktitle
local current_artist = reply[10].creator
local current_album = reply[11].album
local current_albumart = reply[12].albumart
local current_mediatype = reply[11].mediatype
end
end