Help Needed Catching Telnet Response

I recently got the iKettle. It accepts telnet commands and using many other forums I have gotten this to work succesfully:

local ipaddress = "192.168.2.18"
local port = 2000
local command = "set sys output 0x4"

local socket = require("socket")
local client = socket.connect(ipaddress, port)

client:send("set sys output 0x4\n")

The kettle also accepts update requests with this command:

get sys status\n

But I dont know how to capture the response.

My goal here is to test this using the Luup Test. Once I know what will happen I am trying to copy the Denon Receiver Plugin to create an iKettle plugin. I am finding it hard to completely understand that plugin.

Any help is appreciated.

I did not write it, but the Lutron ra2 repeater plugin telnets to a control device, issues commands and views responses on the “screen” aka telnet session. It keeps the connection open indefinitely. You may want to view that code for examples. It is up on code.mioa.com.

Also have a look at the squeezebox plugin.

  • Garrett

Thank you @ramias and @garretwp

I am finding it easier to understand the syntax of the Squeeze Application

@Garretwp - how come I see the same similar commands in a .lua file and the Implentatoin file? Which one runs or which is the correct one for me to be working with

Could do with some more help

This is my lua code so far… I am using the ZeroBrane ide for testing it…

I cant seem to get the responses correctly… Anything obivous that I am missing?

[code]–Status messages
any demo code for lua socket — Gideros Forum

–As the state of the kettle changes, either by someone pushing the physical button on the unit, using an app, or sending the command directly you will get async status messages. Note that although the status messages start with “0x” they are not really hex. Here are all the messages you could see:
–sys status 0x100 100C selected
–sys status 0x95 95C selected
–sys status 0x80 80C selected
–sys status 0x100 65C selected
–sys status 0x11 Warm selected
–sys status 0x10 Warm has ended
–sys status 0x5 Turned on
–sys status 0x0 Turned off
–sys status 0x8005 Warm length is 5 minutes
–sys status 0x8010 Warm length is 10 minutes
–sys status 0x8020 Warm length is 20 minutes
–sys status 0x3 Reached temperature
–sys status 0x2 Problem (boiled dry? no water in kettle!)
–sys status 0x1 Kettle was removed (whilst on)

– ===========================================================
–Decalrations for possible commands
–set sys output 0x4 Select On button
–set sys output 0x0 Turn off
local cmdBoil = “sys output 0x4\n”
local cmdCancel = “sys output 0x0”

–set sys output 0x80 Select 100C button
local cmdSet100 = “sys output 0x80”
–set sys output 0x2 Select 95C button
local cmdSet95 = “sys output 0x2”
–set sys output 0x4000 Select 80C button
local cmdSet80 = “sys output 0x4000”
–set sys output 0x200 Select 65C button
local cmdSet65 = “sys output 0x200”
–set sys output 0x8 Select Warm button
local cmdSetWarm = “sys output 0x8”
–set sys output 0x8005 Warm option is 5 mins
local cmdSetWarmTO5 = “sys output 0x8005”
–set sys output 0x8010 Warm option is 10 mins
local cmdSetWarmTO10 = “sys output 0x8010”
–set sys output 0x8020 Warm option is 20 mins
local cmdSetWarmTO20 = “sys output 0x8020”

local cmdGetStatus = “get sys status\n”
– ===========================================================
local ipaddress = “192.168.2.8” --set ip of kettle
local port = 2000 – must be port 2000 for ikettle
– ===========================================================
local socket = require(“socket”)
local client = socket.connect(ipaddress, port)
client:send(cmdGetStatus)

local response_packet = “”
while true do
local s, status, partial = client:receive(3)
local str = s or partial
if str then
response_packet = response_packet … str

  print (response_packet .. "1")
 
else
  response_packet = nil
  break
end

local response_packet_size = #response_packet
if response_packet_size > 30 then
  if response_packet_size == string.format(response_packet) then
    -- OK, packet received
     print (response_packet .. "2")
    break
  else
    print ("2")
  
  end
end
if status == "closed" then 
  response_packet = nil
  break 
end

end
client:close()[/code]

This is the output I get from the above

sys1 sys st1 sys statu1 sys status k1 sys status key=1 sys status key=sys status key=sys status key=sys status key=sys status key=

all help appreciated…