Basic Bacnet4j Question
-
I have a basic question about bacnet4j I hope someone can answer...
I posted this same question last year, never got an answer and never figured it out. I am back at it again attempting to read data from bacnet devices using Java. I looked around on this forum and this same sort of question has come up many times without an answer. If someone with bacnet4j knowledge can answer this question I believe you will be helping a lot of folk now and in the future.
What I am trying to do:
I have a computer on a IP network running an application that will need to read temperature data from a bacnet devices that is behind a BAS router (BACnet Multi-Network Router by Contemporary Controls) which is on the same IP subnet. The computer's IP is 10.0.0.111. The BAS router's IP is 10.0.051. Netmask 255.255.255.0. The bacnet device ID I want to talk to is 5.
I have no idea where to start? I come from the IP world where things have IP addresses and ports. I can't seem to figure out what IP addresses and ports mean as it relates to local and remote bacnet devices. If someone could describe what a remote device and a local device is in the world of bacnet4j that would help greatly! In my scenero above the computer running the java application the local device? Is the bacnet device ID #5 the remote devices. I have looked through all of the test classes and I am still lost.
LocalDevice localDevice = new localDevice(1234, "10.0.0.255")
What is 1234? I know it is a port, but a port on where, the local computer? If so then I assume 10.0.0.255 an interface on the local computer. If so why don't the examples just bind to the localhost?
localDevice.sendBroadcast(2068,null, new WhoIsRequest());
What is 2068? How does this relate to the port 1234 above?
Help!
Thanks (with fingers crossed) Dan
-
If someone could describe what a remote device and a local device is in the world of bacnet4j that would help greatly!
BACnet devices are all peers of one another. To exist in a BACnet network, you (figuratively) must be a BACnet device. The "local" device is the BACnet device that the instance of BACnet4J represents. Everything else - including other instances of BACnet4J running on the same box - is a "remote" device.
What is 1234? I know it is a port...
It is not a port. That is the device id of the local device. All devices in the network are supposed to have a unique id, although in practice this is not strictly enforced. Your CC box has a device id of 5.
What is 2068? How does this relate to the port 1234 above?
That is the port to which you want to send the broadcast. Typically devices listen at port 0xBAC0 (47808), but BACnet4J is capable of working with alternate ports.
-
Thank you so much for the info.
The other confusion I am having is with the IP addresses. Is the IP address specified in the localDevice() call the IP address of the machine running bacnet4j? If so couldn't you just use localhost? I also noticed in some examples they use a broadcast IP address (such as the example above)...
-
It is a UDP broadcast address.
-
If if the PC running bacnet4j has an IP address of 10.0.0.8 and netmask 255.255.255.0 should the IP address specified in the localDevice method then be 10.0.0.255?
-
That should work. If not, try 255.255.255.255 and get more specific from there.
-
I finally got it to work...
LocalDevice localDevice = new LocalDevice(1234, "10.0.0.255", "10.0.0.111");
localDevice.initialize();
localDevice.sendBroadcast(0xBAC0, new WhoIsRequest(null, null));
localDevice.getEventHandler().addListener((DeviceEventListener) new Listener());I now successfully receive an "i am" from all the bacnet devices expected.
In the many of the test examples the LocalDevice constructor used was:
LocalDevice localDevice = new LocalDevice(1234, "10.0.0.255");
I was never able to get any of those examples to work using this form of the constructor. The javadoc offers no help so I have no idea what address it is trying to bind to when you don't specify an address. I would suggest the test examples use the other constructor. Will save newbies a lot of frustration.
Dan