31.03.2021, 09:23
First of all don't run this script with 0 sleep time, it will consume all CPU resources of the system. To write data to objects use grp.checkwrite(address, value). Make sure that you have created objects beforehand and that they have matching datatypes for the data that will be stored there (string, boolean, number).
For control you will need to create an event script for each action and send HTTP requests to the speakers. You should use different objects for control and status otherwise it's possible to make an infinite loop which will also overload the system.
Example for volume control (use 1 byte scale object):
Code:
if res then
data = json.pdecode(table.concat(respbody))
if type(data) == 'table' then
grp.checkwrite('1/1/1', data.input)
grp.checkwrite('1/1/2', data.mute)
end
else
log('request failed', res, code)
end
For control you will need to create an event script for each action and send HTTP requests to the speakers. You should use different objects for control and status otherwise it's possible to make an infinite loop which will also overload the system.
Example for volume control (use 1 byte scale object):
Code:
value = event.getvalue()
ip = '192.168.1.169'
http = require('socket.http')
res, code, hdrs = http.request({
url = 'http://' .. ip .. '/YamahaExtendedControl/v1/main/setVolume?volume=' .. value,
headers = {
['X-AppName'] = 'MusicCast/1.0',
['X-AppPort'] = '41100',
}
})