This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Json virtual object
#1
Hi,

Do any have an example of how to mass greate virtual objects in json?

BR Even Sundgot.
Reply
#2
Why not use a script with grp.create in a loop? What kind of objects do you want to create?
Reply
#3
That`s probably just as good. Im doing some testing and want to create 200 objects like this:
BACnet_001 to BACnet_200
And I want them to start at 32\1\1

Datatype 1 Byte scale
Reply
#4
Code:
for i = 1, 200 do
  name = string.format('BACnet_%03d', i)
  grp.create({
     name = name,
     address = '32/1/' .. i,
     datatype = dt.scale,
  })
end
Reply
#5
(08.08.2018, 07:49)admin Wrote:
Code:
for i = 1, 200 do
 name = string.format('BACnet_%03d', i)
 grp.create({
    name = name,
    address = '32/1/' .. i,
    datatype = dt.scale,
 })
end

Perfect!  Smile

Thanks!
Reply
#6
Is there any way to add the same script to several objects, but with one thing changing everytime?

I have this script that i want to add to 200 objects, but the ID needs to be changed everytime.
from 65793 to 65992

require('bacnet')

value = event.getvalue()

bacnet.write(127001, 'analog value', 65809, value)
Reply
#7
You can attach event script to a tag. Use event.dstraw to calculate BACnet object id from the group address that triggered the script.
Reply
#8
Can you give me an example of this?
Reply
#9
First, add a certain tag to all objects via mass edit. Then create an event script which is mapped to the tag you've added. If your range is 32/1/1..32/1/200 then you don't need any extra conversion since it is 65793..65992 in numeric form.

Code:
require('bacnet')

value = event.getvalue()

bacnet.write(127001, 'analog value', event.dstraw, value)
Reply
#10
(08.08.2018, 11:00)admin Wrote: First, add a certain tag to all objects via mass edit. Then create an event script which is mapped to the tag you've added. If your range is 32/1/1..32/1/200 then you don't need any extra conversion since it is 65793..65992 in numeric form.

Code:
require('bacnet')

value = event.getvalue()

bacnet.write(127001, 'analog value', event.dstraw, value)

I dont understand how, but it works!  Smile

Thanks!
Reply
#11
Is there any way to adjust this script to match the range 32/2/1 - 32/2/250 and 32/3/1 - 32/3/250 (all have the same Tag)
I have 500 objects that i want to link to ID 0- 500.
Reply
#12
(09.08.2018, 13:29)Evens Wrote: Is there any way to adjust this script to match the range 32/2/1 - 32/2/250 and 32/3/1 - 32/3/250 (all have the same Tag)
I have 500 objects that i want to link to ID 0- 500.

Nothing has to be modified it will work.  your bacnet range will be 66049 - 66290 and 66305 - 66554
------------------------------
Ctrl+F5
Reply
#13
event.dstraw is an integer value of group address. You can easily convert to a 0..499 range like this:
Code:
id = event.dstraw

if 66049 <= id and id <= 66290 then
  id = id - 66049
elseif 66305 <= id and id <= 66554 then
  id = id - 66305 + 250
else
  return
end

value = event.getvalue()
bacnet.write(127001, 'analog value', id, value)
Reply
#14
Thanks!
I can’t get it to work properly. maybe I’m doing something wrong.
How do you convert from Group Address to the number?
Reply
#15
H/M/L
H * 2048 + M * 256 + L
Reply
#16
Thanks!

This event.dstraw, do you have an easy explanation for it, I’d like to understand what it does.
Reply
#17
event.dst is group address that triggered the script in H/M/L format, event.dstraw is the same address but in numeric form.
Reply
#18
Thanks, Now i understand Smile
Reply


Forum Jump: