from the notes provided: "The connection to usBIM.IoT takes place via certified Web Sockets. The certificate is provided by
Acca and the flow of incoming and outgoing data is regularized by the formalism shown below "
(06.05.2021, 15:08)admin Wrote: JSON is just a data format but what is used as a transport, HTTP or something else?
I thought of translating the notes provided by our client to better understand the problem.
I hope you can help me.
Peppe
P.S. This BIM standard, as you certainly know, is expanding a lot and will soon become, at least in Italy, mandatory for any building project. So I think it is important to understand how to interface LM.
2. Create a user library named websocket using the attached source.
3. Upload certificates via FTP using ftp login, rename files with long names to cert.pem and key.pem accordingly.
4. Create a resident script with 0 sleep time.
Code:
if not client then
require('json')
ws = require('websocket')
url = 'wss://test-hub.usbim.com'
res, err = client:connect(url, opts)
if not res then
log('connection failed', err)
client:sock_close()
client = nil
end
end
if client then
frame, opcode, clean, code, reason = client:receive()
log(frame, opcode, clean, code, reason)
if frame then
data = json.pcdecode(frame)
log(data)
elseif reason ~= 'timeout' then
log('connection dropped', reason)
client:sock_close()
client = nil
end
end
This example is only a starting point, it should be extended with additional send/receive logic.
2. Create a user library named websocket using the attached source.
3. Upload certificates via FTP using ftp login, rename files with long names to cert.pem and key.pem accordingly.
4. Create a resident script with 0 sleep time.
Code:
if not client then
require('json')
ws = require('websocket')
url = 'wss://test-hub.usbim.com'
res, err = client:connect(url, opts)
if not res then
log('connection failed', err)
client:sock_close()
client = nil
end
end
if client then
frame, opcode, clean, code, reason = client:receive()
log(frame, opcode, clean, code, reason)
if frame then
data = json.pcdecode(frame)
log(data)
elseif reason ~= 'timeout' then
log('connection dropped', reason)
client:sock_close()
client = nil
end
end
This example is only a starting point, it should be extended with additional send/receive logic.
Thank you very much.... now I am getting that log.... I guess something is still wrong...
This means that the script is connected but there are no messages to be read from the websocket connection.
Can you describe what data do you want to send/receive via this connection?
I know about the protocol but the question was about your own use case. What kind of devices are going to control like this? Or do you want to read some sensor values?
(11.05.2021, 09:42)admin Wrote: I know about the protocol but the question was about your own use case. What kind of devices are going to control like this? Or do you want to read some sensor values?
I have to let them to control the ETS objects in LM... so I have to send sensor values, object states and let them to command i.e. lamps, termostate setpoint, etc.
1. Create a user library named bim-iot using the attached source.
2. Make sure that the updated websocket library and keys are in place.
3. Create a resident script with sleep time = 0:
Code:
if not wsclient then
require('json')
require('user.bim-iot')
if wsclient then
local res, lbstat, wsstat = socket.xselect(10, lbfd, wsfd)
if res > 0 then
if lbstat then
lb:step()
end
if wsstat then
local msg, opcode, clean, code, reason = wsclient:receive()
log(msg, opcode, clean, code, reason)
if msg then
onwsmessage(msg)
elseif reason ~= 'timeout' then
log('WS connection dropped', reason)
wsclient:sock_close()
wsclient = nil
end
end
end
else
-- handle incoming object messages before trying to reconnect WS
lb:loop(10)
end
Since I don't have the tools to test some parts might not work.
The connection is ok, but they still can't get nothing. I guess you already understood, but just to be clear:
they should receive any object event when it occurs and to be able to write on the objects.
Can I send you the backup of my LM in private? Could be useful?
they checked the logs and the data they are receiving but it seems to be not in the correct format due to an error that is present in the documentation we sent you.
We receive the following JSON:
Modify the sendobjvalue function in bim-iot library and do a full script restart via disable/enable:
Code:
function sendobjvalue(obj)
local data = json.encode({
Type = 'NotificationPackage',
Item = {
Name = obj.name,
State = encodevalue(obj.value, obj.dtype),
Type = obj.dtype,
Editable = 2, -- allow read/write
Link = ''
},
TimeStamp = timestamp()
})
(13.05.2021, 09:53)admin Wrote: Modify the sendobjvalue function in bim-iot library and do a full script restart via disable/enable:
Code:
function sendobjvalue(obj)
local data = json.encode({
Type = 'NotificationPackage',
Item = {
Name = obj.name,
State = encodevalue(obj.value, obj.dtype),
Type = obj.dtype,
Editable = 2, -- allow read/write
Link = ''
},
TimeStamp = timestamp()
})
wsclient:send(data)
end
I already done it...
Everything seems to works fine at moment...
now they said me that they will try to send write messages in the next days... hopefully everything will be fine.
(13.05.2021, 09:53)admin Wrote: Modify the sendobjvalue function in bim-iot library and do a full script restart via disable/enable:
Code:
function sendobjvalue(obj)
local data = json.encode({
Type = 'NotificationPackage',
Item = {
Name = obj.name,
State = encodevalue(obj.value, obj.dtype),
Type = obj.dtype,
Editable = 2, -- allow read/write
Link = ''
},
TimeStamp = timestamp()
})
wsclient:send(data)
end
HI,
They finally tested the ws connection sending commands from their side: it doesn't work.
They try to on/off a led or to set temperature on a termostate, but nothing happens.
They json strings they are sending are like:
Use the attached updated library and see if receiving values works.
You must tag the objects that you want to be accessible via this connection. Use either bim-read, bim-write or bim-read-write tag to define the access level. Only one tag can be used for any object.