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” »

Fritzbox internes Fax immer besetzt

Heute haben wir lange damit gekämpft das unser bisher reibungslos funktionierendes Fax auf einmal die Anrufe nicht mehr angenommen hat. Die Fritzbox ist so eingerichtet gewesen, dass sie auf eine Telefonnummer reagiert um Faxe anzunehmen und eine weitere Nummer dafür da ist zu telefonieren.

Nach langem ausprobieren sind wir auf die Lösung gestoßen. Ein Handy nutzt die FritzFon App. Beim Anmelden vergibt die Fritzbox erstmal dieser App alle Telefonnummern. Das führt dazu, dass die Fritzbox nicht weis welchem Gerät sie die Faxanrufe zu leiten soll. Als Effekt ist ein ewiges Besetztzeichen zu vernehmen.

Lösung: In der Fritzbox-Oberfläche unter “Telefoniergeräte” die App suchen und dort die ankommenden Anrufe auf die Nummer beschränken, die für das Telefonieren gedacht ist.

Get photos from google+ using the command line in linux

I used to have picasawebsync.py as my prefered tool in getting a backup copy of my photos and videos from google+, but it stopped working (for me). GoogleCL to the rescue.

To get all photos from the automatic backup just type

google -u yourusername picasa get "Auto Backup"

in your terminal.  The first time you run it, you will need to open a URL that GoogleCL gives you.

What I am missing is a “sync” feature, as all it does is download.

LogicMachine telnet user script

The following code enables you to open a telnet connection and send commands. I use it to connect to my Pioneer sound system. Add it to a user script.

telnet-lm


-- send Telnet command

function telnet(host, port, command)
  local socket = require("socket")
  local tcp = assert(socket.tcp())
  res, err = tcp:connect(host, port)
  res, err = tcp:send(command)

  while true do
    local s, status, threebytes = tcp:receive(3)
    if status == "closed" then break end
  end  
  tcp:close()
end

Usage

All you need to do now is call the function from your KNX-Object script. Example:


require('user.telnet')
telnet('192.168.0.24', 8102, 'PF\r\n\r\nclose\r\n\r\n')

The PF command tells my Pioneer to turn off. I’m not sure if a close command is necessary, but all the returns are. The IP address and port have to be changed to what you need.