Result is sometimes 'nill' and sometimes "Busy". I know that this should work because I've checked a communication with ETM-1 via some program which was prepared according with this documentation.
According to the documentation to read armed partitions I must send:
Since you are calling receive() without any arguments it will try to receive all data before socket is closed which is probably not the behavior you want. Try specifying the number of bytes that the reply should contain and it should work.
25.10.2016, 07:43 (This post was last modified: 25.10.2016, 07:50 by buuuudzik.)
(25.10.2016, 06:18)admin Wrote: Since you are calling receive() without any arguments it will try to receive all data before socket is closed which is probably not the behavior you want. Try specifying the number of bytes that the reply should contain and it should work.
Good tip, because now I have response but this response is shorter than the query(look at the screenshot). I've tried also '*a' and '*l' arguments but they gave 'nill'. Response should have 15 bytes.
Code:
function str2hex(str)
raw_len = string.len(str)
i = 1
while i <= raw_len do
current_hexvalue = '0x' .. string.format("%02x", string.byte(str, i))
if value then
value = value .. ', ' .. current_hexvalue
else
value = current_hexvalue
end
i = i + 1
end
return value
end
And also unfortunately I've tried use lmcore.strtohex() but it gives me empty string. I've tried also the str2hex() from Erwin example but it gives me the same. I don't know also why the last 2 variables are not logged and there is no error describing this situation?
I've checked another way and it works perfect
Code:
function str2hex(str)
raw_len = string.len(str)
i = 1
while i <= raw_len do
current_hexvalue = '0x' .. string.format("%02x", string.byte(str, i))
if value then
value = value .. ', ' .. current_hexvalue
else
value = current_hexvalue
end
i = i + 1
end
return value
end
And maybe there is another way to receive some data because sometimes I will not know what is the data length? Maybe not in this script but in the future.
Correction: default receive pattern is '*l' - a single line, not the whole result. Receive() will return partial result as a third return value when an error occurs (that's why you are getting an empty string). So you can use '*a' pattern to receive everything until timeout occurs. This is not the most efficient way, but it will work
Code:
data, err, partial = client:receive('*a')
-- error
if not data then
data = partial
end
-- do something with data that's available
if data then
parsedata(data)
end
client:close()
As for hex logging, new firmware will have loghex() function to make this easier.
I have a script for a read the states of inputs. But I have a little problem in my resident script. I cannot use grp.write() or grp.update() because I have this error:
Code:
Line 0: attempt to call field 'rshift' (a nil value)
I've tried send the same in the other script and there was ok.
This is my script:
Code:
-- Integracja z systemem Satelem po TCP
cmd = string.char(0xFE,0xFE,0x00,0xD7,0xE2,0xFE,0x0D)
bytes = 23
-- function Satel(cmd, bytes)
function satel_send(cmd, bytes)
ethm_ip = '192.168.2.9'
port = 7094
if success == 1 and error == nil then
client:settimeout(0.3)
client:send(cmd)
data, error, partial = client:receive(bytes)
-- error
if not data then
data = partial
end
client:close()
end
return data
end
-- Funkcja odpowiedzialna za wyciągniecie poszczególnych bitów i wstawienie ich do tabeli
function convert(data)
local res, byte
res = {}
for i = 1, #data do
-- get single byte
byte = data:byte(i, i)
byte = string.char(byte)
bits = hex2bin(byte)
for b = 1, #bits do
-- get single bit
bit = bits:byte(b, b)
bit = string.char(bit)
if bit == '0' then
bin = false
elseif bit =='1' then
bin = true
end
-- add to result
res[i*4-(4-b)] = bin
end
end
return res
end
data = satel_send(cmd, bytes)
-- check if some data is available
if data then
data = lmcore.strtohex(data, true)
-- delete first 4 and last 8 chars
data = string.sub(data, 5, (string.len(data) -8))
inputs = convert(data)
else
log('Satel: zajęty')
end
-- update the inputs in the LM database
for i = 1, #inputs do
GA = '0/0/'.. tostring(91+i-1)
grp.update(GA , inputs[i])
end
Interesting to connect to Satels First via ethm card and commands. I havet done this in my home with knx v1 interface from them. That works perfect inn case u need another solution
(26.10.2016, 20:40)PassivPluss Wrote: Interesting to connect to Satels First via ethm card and commands. I havet done this in my home with knx v1 interface from them. That works perfect inn case u need another solution
I have a project with Integra 256plus so 64group addresses from KNX v1 or v2 is not enough.
But I know some important tip from one Satel integrator that KNX module is much reliable than ethm when you have in your project communication via telephone link with monitoring station(when integra sends some data to the monitoring station all connections via ethm are terminated but KNX still works).
So at this moment ethm is a full option(you can integrate whole installation without loosing any additional inputs/outputs) but you must have good script because sometimes ethm is "Busy!".
KNX module v2 is reliable but you loose inputs/outputs, it has only 64 variables.