Example of UnconfirmedCovNotificationRequest
-
Hello,
I'm using BACnet4J 3.2.3 to subscribe to COV using UnconfirmedCovNotificationRequest.
But I couldn't make it work. My sample program is below.
Can anyone help/suggest on making this work ?import java.net.InetSocketAddress; import com.serotonin.bacnet4j.LocalDevice; import com.serotonin.bacnet4j.RemoteDevice; import com.serotonin.bacnet4j.npdu.ip.IpNetwork; import com.serotonin.bacnet4j.service.unconfirmed.UnconfirmedCovNotificationRequest; import com.serotonin.bacnet4j.transport.DefaultTransport; import com.serotonin.bacnet4j.transport.Transport; import com.serotonin.bacnet4j.type.constructed.PropertyValue; 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.primitive.ObjectIdentifier; import com.serotonin.bacnet4j.type.primitive.UnsignedInteger; import com.serotonin.bacnet4j.util.DiscoveryUtils; public class UnconfirmedCovTest { public static void main(String[] args) { IpNetwork network = new IpNetwork("192.23.29.46", 47808); Transport transport = new DefaultTransport(network); LocalDevice localDevice = new LocalDevice(999, transport); try { localDevice.initialize(); network.registerAsForeignDevice(new InetSocketAddress("192.23.29.46", 47808),9000 ); Thread.sleep(2000); RemoteDevice d = DiscoveryUtils.discoverDevice(localDevice,700710); if (d == null) { throw new RuntimeException("Remote device not found"); } else { final ObjectIdentifier oid = new ObjectIdentifier(ObjectType.analogInput, Integer.valueOf("10")); final SequenceOf<PropertyValue> listOfValues = new SequenceOf<>(); listOfValues.add( new PropertyValue( PropertyIdentifier.presentValue, null ) ); final UnconfirmedCovNotificationRequest unconfirmedCovRequest = new UnconfirmedCovNotificationRequest( new UnsignedInteger(1), oid, oid, new UnsignedInteger(60), listOfValues ); localDevice.send( d.getAddress(), unconfirmedCovRequest ); } } catch ( Exception e ) { e.printStackTrace(); } } }
Thank you very much.
Manoj -
Hello All,
Today I updated my program as below. I'm able to run this program without any exception. But, it never received even a single cov notification for hours.
Any idea/help/support is much appreciated !
Thank you very much.
Manojimport java.net.InetSocketAddress; import com.serotonin.bacnet4j.LocalDevice; import com.serotonin.bacnet4j.RemoteDevice; import com.serotonin.bacnet4j.RemoteObject; import com.serotonin.bacnet4j.event.DeviceEventListener; import com.serotonin.bacnet4j.npdu.ip.IpNetwork; import com.serotonin.bacnet4j.obj.BACnetObject; import com.serotonin.bacnet4j.service.confirmed.ReinitializeDeviceRequest.ReinitializedStateOfDevice; import com.serotonin.bacnet4j.service.unconfirmed.UnconfirmedCovNotificationRequest; import com.serotonin.bacnet4j.transport.DefaultTransport; import com.serotonin.bacnet4j.transport.Transport; import com.serotonin.bacnet4j.type.constructed.Address; import com.serotonin.bacnet4j.type.constructed.Choice; import com.serotonin.bacnet4j.type.constructed.DateTime; import com.serotonin.bacnet4j.type.constructed.PropertyValue; import com.serotonin.bacnet4j.type.constructed.Sequence; import com.serotonin.bacnet4j.type.constructed.SequenceOf; import com.serotonin.bacnet4j.type.constructed.TimeStamp; import com.serotonin.bacnet4j.type.enumerated.EventState; import com.serotonin.bacnet4j.type.enumerated.EventType; import com.serotonin.bacnet4j.type.enumerated.MessagePriority; import com.serotonin.bacnet4j.type.enumerated.NotifyType; import com.serotonin.bacnet4j.type.enumerated.ObjectType; import com.serotonin.bacnet4j.type.notificationParameters.NotificationParameters; import com.serotonin.bacnet4j.type.primitive.Boolean; import com.serotonin.bacnet4j.type.primitive.CharacterString; import com.serotonin.bacnet4j.type.primitive.ObjectIdentifier; import com.serotonin.bacnet4j.type.primitive.UnsignedInteger; import com.serotonin.bacnet4j.util.DiscoveryUtils; public class UnconfirmedCovTest { public static void main(String[] args) { IpNetwork network = new IpNetwork("192.23.29.46", 47808); Transport transport = new DefaultTransport(network); LocalDevice localDevice = new LocalDevice(999, transport); try { localDevice.initialize(); localDevice.getEventHandler().addListener( new DeviceEventListener() { @Override public void textMessageReceived(RemoteDevice arg0, Choice arg1, MessagePriority arg2, CharacterString arg3) { System.out.println( "textMessageReceived : " + arg0 ); } @Override public void synchronizeTime(Address arg0, DateTime arg1, boolean arg2) { System.out.println( "synchronizeTime : " + arg0 ); } @Override public void reinitializeDevice(Address arg0, ReinitializedStateOfDevice arg1) { System.out.println( "reinitializeDevice : " + arg0 ); } @Override public void propertyWritten(Address arg0, BACnetObject arg1, PropertyValue arg2) { System.out.println( "propertyWritten : " + arg0 ); } @Override public void privateTransferReceived(Address arg0, UnsignedInteger arg1, UnsignedInteger arg2, Sequence arg3) { System.out.println( "privateTransferReceived : " + arg0 ); } @Override public void listenerException(Throwable arg0) { System.out.println( "listenerException : " + arg0 ); } @Override public void iHaveReceived(RemoteDevice arg0, RemoteObject arg1) { System.out.println( "iHaveReceived : " + arg0 ); } @Override public void iAmReceived(RemoteDevice arg0) { System.out.println( "iAmReceived : " + arg0 ); } @Override public void eventNotificationReceived(UnsignedInteger arg0, RemoteDevice arg1, ObjectIdentifier arg2, TimeStamp arg3, UnsignedInteger arg4, UnsignedInteger arg5, EventType arg6, CharacterString arg7, NotifyType arg8, Boolean arg9, EventState arg10, EventState arg11, NotificationParameters arg12) { System.out.println( "eventNotificationReceived.arg0 : " + arg0 ); System.out.println( "eventNotificationReceived.arg1 : " + arg1 ); System.out.println( "eventNotificationReceived.arg2 : " + arg2 ); System.out.println( "eventNotificationReceived.arg3 : " + arg3 ); } @Override public void covNotificationReceived(UnsignedInteger arg0, RemoteDevice arg1, ObjectIdentifier arg2, UnsignedInteger arg3, SequenceOf<PropertyValue> arg4) { System.out.println( "covNotificationReceived.arg0 : " + arg0 ); } @Override public boolean allowPropertyWrite(Address arg0, BACnetObject arg1, PropertyValue arg2) { System.out.println( "allowPropertyWrite.arg0 : " + arg0 ); return false; } } ); network.registerAsForeignDevice(new InetSocketAddress("192.23.29.46", 47808),9000 ); Thread.sleep(2000); RemoteDevice d = DiscoveryUtils.discoverDevice(localDevice,700710); if (d == null) { throw new RuntimeException("Remote device not found"); } else { final ObjectIdentifier oid = new ObjectIdentifier(ObjectType.analogInput, Integer.valueOf("10")); final SequenceOf<PropertyValue> listOfValues = new SequenceOf<>(); final UnconfirmedCovNotificationRequest unconfirmedCovRequest = new UnconfirmedCovNotificationRequest( new UnsignedInteger(1), localDevice.getConfiguration().getId(), oid, new UnsignedInteger(60), listOfValues ); localDevice.send( d.getAddress(), unconfirmedCovRequest ); //localDevice.sendBroadcast( d.getAddress(), unconfirmedCovRequest ); System.out.println( "Sent unconfirmed cov request !!" ); } } catch ( Exception e ) { e.printStackTrace(); } } }