Timeout error - Bacnet4j is not able to read the ack message from the device
-
If i run a test program i am getting an timeout error, i am using the latest version of bacnet4j from sourceforge...
That is version 1.2 "http://sourceforge.net/projects/bacnet4j/files/bacnet4j/1.2/"
Below is the programimport java.net.InetAddress;
import java.net.InetSocketAddress;import com.serotonin.bacnet4j.LocalDevice;
import com.serotonin.bacnet4j.RemoteDevice;
import com.serotonin.bacnet4j.event.DefaultDeviceEventListener;
import com.serotonin.bacnet4j.service.acknowledgement.ReadPropertyAck;
import com.serotonin.bacnet4j.service.confirmed.ReadPropertyRequest;
import com.serotonin.bacnet4j.type.Encodable;
import com.serotonin.bacnet4j.type.constructed.Address;
import com.serotonin.bacnet4j.type.constructed.SequenceOf;
import com.serotonin.bacnet4j.type.enumerated.ObjectType;
import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier;
import com.serotonin.bacnet4j.type.enumerated.Segmentation;
import com.serotonin.bacnet4j.type.primitive.ObjectIdentifier;public class Test2 {
public static void main(String[] args) throws Exception {
LocalDevice localDevice = new LocalDevice(1968, "255.255.255.255");
localDevice.getEventHandler().addListener(new Listener());
localDevice.setPort(47808);
localDevice.initialize();
getObjectList(localDevice, "192.168.1.3", 0xBAC0, 260001);
localDevice.terminate();
}private static void getObjectList(LocalDevice localDevice, String ip, int port, int deviceId) throws Exception { InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(ip), port); System.out.println(""+addr); ReadPropertyRequest read = new ReadPropertyRequest(new ObjectIdentifier(ObjectType.device, deviceId), PropertyIdentifier.objectList); Thread.sleep(1000); ReadPropertyAck ack = (ReadPropertyAck) localDevice.send(addr, null, 1476, Segmentation.segmentedBoth, read); Thread.sleep(1000); System.out.println("IP: " + ip); SequenceOf<ObjectIdentifier> oids = (SequenceOf<ObjectIdentifier>) ack.getValue(); for (ObjectIdentifier oid : oids) System.out.println(" " + oid); } static class Listener extends DefaultDeviceEventListener { @Override public void iAmReceived(RemoteDevice d) { System.out.println("IAm received" + d); } }
}
Everytime if i run this program i am getting the Timeout error:
Exception in thread "main" com.serotonin.bacnet4j.exception.BACnetTimeoutException: Timeout while waiting for response for id 0
at com.serotonin.bacnet4j.npdu.ip.IpMessageControl.send(IpMessageControl.java:314)
at com.serotonin.bacnet4j.npdu.ip.IpMessageControl.send(IpMessageControl.java:249)
at com.serotonin.bacnet4j.LocalDevice.send(LocalDevice.java:480)
at Test2.getObjectList(Test2.java:44)
at Test2.main(Test2.java:29)Able to see the response from the device using wireshark and since bacnet4j is not able to receive the complex ack from the device it will be keep polling and finally timeout error will be thrown..
Even i tried using the latest code available in CVS --->"http://bacnet4j.cvs.sourceforge.net/viewvc/bacnet4j/BACnet4J/" but still the same error results. Can you please help is there something wrong i am doing?
Can you please resolve this issue :roll:
I am finding this issue more on WIFI network not wired, with wired network some times it works fine
-
Hi kishorev,
You seem to be using the bacnet4j api in a bit of a strange way. But I can see a few things that might help. First of all before you ask for the object list, you probably need to do a broadcast, simply so that the responding bacnet device knows you exist, otherwise I'm pretty sure it can't respond to you.
You can do it with a broadcast:
localDevice.sendBroadcast(47808, localDevice.getIAm());
Or you can send it a direct message, since you know who you are talking to:
localDevice.sendUnconfirmed(remoteDevice.getAddress(), null, localDevice.getIAm());
Then then other problem is the way you are getting the object list, you are really using internal API methods, you are much better off using:
List<ObjectIdentifier> oids = ((SequenceOf<ObjectIdentifier>) localDevice.sendReadPropertyAllowNull(remoteDevice, remoteDevice .getObjectIdentifier(), PropertyIdentifier.objectList)).getValues();
Where remoteDevice is an instance of a RemoteDevice, in your case:
Address address = new Address(null,BACnetUtils.dottedStringToBytes("192.168.1.3"),47808); RemoteDevice remoteDevice = localDevice.findRemoteDevice(address, null, deviceId);