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…