Tag Archives: Pioneer

LogicMachine control Pioneer AVR via telnet

I thought I’d share this work in progress, based on my previous post here. I am an amateur both in Lua and in KNX… so take with a huge grain of salt.

All these scripts do is open a socket to a defined IP and Port and send a telnet command… then add an “Enter”… then wait for an answer. It closes right after that, as the Pioneer does not like more than one telnet connection at a time and I don’t want to hog the port.

Copy this code into a user library. I called mine user.telnet

--Sends a single telnet command to a host and port
--it returns one line answer
function telnetsend(host, port, command)

 nextline = '\r\n'

 local socket = require("socket")
 local tcp = assert(socket.tcp())
 res, err = tcp:connect(host, port)
 res, err = tcp:send(command .. nextline)
 local answer = tcp:receive('*l')
 tcp:close()
 return answer
end

--Sets the volume to a numeric value
--takes into account, that Pioneer increments the volume in
--2 step intervals. Takes a host ip and port as input.
function setvolume(host, port, volumelevel)

 local currentvolume = getvolume(host, port)

 if volumelevel > currentvolume then
   for i = currentvolume, volumelevel -1, 2 do
     telnetsend(host,port,VOLUME_UP)
   end
 else
   for i = volumelevel, currentvolume-1, 2 do
     telnetsend(host,port,VOLUME_DOWN)
   end
 end
 
 currentvolume = getvolume(host, port)
 return currentvolume

end

--Returns the current volume
function getvolume(host, port)
 
 local currentvolume = tonumber(string.sub(telnetsend(host,port,VOLUME_QUERY), 5))
 return currentvolume
 
end

--Turns reciever on off
function soundonoff(host, port, onoff)
 if onoff == true then
   telnetsend(host,port,POWER_ON)
   local status = telnetsend(host,port,POWER_QUERY)
   if status == POWER_ONSTATE then
     return true
   else
     alert("Could not turn on sound")
   end    
 else
   telnetsend(host,port,POWER_OFF)
   local status = telnetsend(host,port,POWER_QUERY)
   if status == POWER_OFFSTATE then
     return false
   else
     alert("Could not turn off sound")
   end
 end
end

and put this code into a separate user.script. I called mine user.pioneer
Continue reading “LogicMachine control Pioneer AVR via telnet” »