MangoAutomation / BACnet4J

BACnet/IP stack written in Java. Forked from http://sourceforge.net/projects/bacnet4j/
GNU General Public License v3.0
183 stars 110 forks source link

COV not working with multiStateValue,multiStateOutput,multiStateInput #63

Closed danishmhmd closed 3 years ago

danishmhmd commented 3 years ago

Hi I was exploring the library for all different COV type but i noticed i am unable to get the COV packets on my listener, however i checked wireshark there seems to be some error of unknown service while subscribing even after that device do sends the notification of which library reply with unknown service. However same is working with a third party online tool i checked called Yabe. PFA screenshot of wire shark with bacnet4j and yabe. Below are the logs which i see when a notification is sent from device: [BACnet4J IP socket listener for device 0] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from local network. From=Address [networkNumber=0, macAddress=[a,0,0,66,ba,c0]], local=0 [BACnet4J IP socket listener for device 0] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from [a,0,0,66,ba,c0]: NPDU [from=Address [networkNumber=0, macAddress=[a,0,0,66,ba,c0]], linkService=null, queue=[0,4,f6,1,9,4,1c,2,0,1e,2c,2c,4,c0,0,5,39,0,4e,9,55,2e,91,3,2f,9,6f,2e,82,4,0,2f,4f]] [BACnet4J IP socket listener for device 0] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from local network. From=Address [networkNumber=0, macAddress=[a,0,0,66,ba,c0]], local=0 [BACnet4J IP socket listener for device 0] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from [a,0,0,66,ba,c0]: NPDU [from=Address [networkNumber=0, macAddress=[a,0,0,66,ba,c0]], linkService=null, queue=[0,4,f7,1,9,1,1c,2,0,1e,2c,2c,4,c0,0,5,39,0,4e,9,55,2e,91,3,2f,9,6f,2e,82,4,0,2f,4f]] [BACnet4J IP socket listener for device 0] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from local network. From=Address [networkNumber=0, macAddress=[a,0,0,66,ba,c0]], local=0 [BACnet4J IP socket listener for device 0] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from [a,0,0,66,ba,c0]: NPDU [from=Address [networkNumber=0, macAddress=[a,0,0,66,ba,c0]], linkService=null, queue=[0,4,f8,1,9,4,1c,2,0,1e,2c,2c,4,c0,0,5,39,0,4e,9,55,2e,91,0,2f,9,6f,2e,82,4,0,2f,4f]] [BACnet4J IP socket listener for device 0] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from local network. From=Address [networkNumber=0, macAddress=[a,0,0,66,ba,c0]], local=0 [BACnet4J IP socket listener for device 0] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from [a,0,0,66,ba,c0]: NPDU [from=Address [networkNumber=0, macAddress=[a,0,0,66,ba,c0]], linkService=null, queue=[0,4,f9,1,9,1,1c,2,0,1e,2c,2c,4,c0,0,5,39,0,4e,9,55,2e,91,0,2f,9,6f,2e,82,4,0,2f,4f]] Bacnet4j Yabe

kishorevenki commented 3 years ago

Have you set COVNotification to TRUE like servicesSupported.setConfirmedCovNotification(true);

danishmhmd commented 3 years ago

Yes as below: remoteDevice.getServicesSupported().setConfirmedCovNotification(true); Here are the console logs of library when i device sends the COV and library reply it with service not supported:-

[BACnet4J IP socket listener for device 0] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from local network. From=Address [networkNumber=0, macAddress=[a,0,0,66,ba,c0]], local=0 [BACnet4J IP socket listener for device 0] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from [a,0,0,66,ba,c0]: NPDU [from=Address [networkNumber=0, macAddress=[a,0,0,66,ba,c0]], linkService=null, queue=[0,4,a8,1,9,1,1c,2,0,1e,2c,2c,4,c0,0,5,39,0,4e,9,55,2e,91,0,2f,9,6f,2e,82,4,0,2f,4f]]

kishorevenki commented 3 years ago

After carefully analyzing the wireshark logs sent earlier I noticed the following:

  1. 10.0.0.100 - BACnet4J as workstation, 10.0.0.102 - Controller having AI,0 and MSV,5.
  2. 10.0.0.100 subscribes COV for both AI,0 and MSV,5 which has been accepted by the controller as well.
  3. Subsequently AI,0 sent COV notification which was accepted by BAcnet4J.
  4. But when the COV is received from MSV,5 it throws error.
  5. So the issue is related to MSV and not with COV.

So please look at the code around MSV and if possible share the code so as to reproduce from my side to see how can I help you.

danishmhmd commented 3 years ago

Sure, Please find the sample code snippet below for communication class and listener :-

=================================================================================================

        IpNetworkBuilder builder = new IpNetworkBuilder();
        builder.withPort(Variables.port);
        builder.withSubnet(Variables.subnetAddress, Variables.networkPrefixLength);
        builder.withReuseAddress(true);
        IpNetwork network = builder.build();
        Transport transport = new DefaultTransport(network);
                    LocalDevice localDevice;
        localDevice = new LocalDevice(Variables.device_no, transport);
        localDevice.initialize();
                    localDevice.getEventHandler().addListener(new CustomListener(localDevice));

WhoISRequestCustom whois = new WhoISRequestCustom(localDevice); whois.whois();

                   SubscribeCOVRequest subscribeCOVRequest = new SubscribeCOVRequest(new UnsignedInteger(1),                       new ObjectIdentifier(ObjectType.multiStateValue, 5),
                 Boolean.TRUE, new UnsignedInteger(0));

                 SubscribeCOVRequest subscribeCOVRequest2 = new SubscribeCOVRequest(new UnsignedInteger(4),
                 new ObjectIdentifier(ObjectType.analogInput, 0),
                 Boolean.TRUE, new UnsignedInteger(0));

                 localDevice.send(remoteDevice1,
                 subscribeCOVRequest).get();
                 localDevice.send(remoteDevice1,
                 subscribeCOVRequest2).get();

======================================================================

public class CustomListener extends DeviceEventAdapter { LocalDevice localDevice;

public CustomListener(LocalDevice localDevice) { this.localDevice = localDevice; }

@Override public void iAmReceived(final RemoteDevice d) { System.out.println("I AM FOR Devcice " + d.toString()); new Thread(new Runnable() { public void run() { try { DiscoveryUtils.getExtendedDeviceInformation(localDevice, d); SequenceOf oids = RequestUtils.getObjectList(localDevice, d);

           System.out.println("I AM " + oids);

        }
        catch (BACnetException e)
        {
           e.printStackTrace();
        }
     }
  }).start();

}

public void covNotificationReceived( final UnsignedInteger subscriberProcessIdentifier, final ObjectIdentifier initiatingDeviceIdentifier, final ObjectIdentifier monitoredObjectIdentifier, final UnsignedInteger timeRemaining, final SequenceOf listOfValues) { try {

     System.out.println(
              "subscriberProcessIdentifier " + subscriberProcessIdentifier
                       + " ,initiatingDeviceIdentifier:"
                       + initiatingDeviceIdentifier.toString());
     System.out.println("monitoredObjectIdentifier "
              + monitoredObjectIdentifier.toString());
     for (int i = 0; i < listOfValues.getCount(); i++)
     {
        try
        {
           System.out.println(
                    "List of value" + listOfValues.get(i).toString());
        }
        catch (Exception e)
        {
           // TODO: handle exception
        }
        if (!(listOfValues.getValues().get(i)
                 .getValue() instanceof StatusFlags))
        {
           System.out.println("COV_Result: Instance-ID:"
                    + monitoredObjectIdentifier.getInstanceNumber()
                    + " Value:" + listOfValues.getValues().get(i).getValue()
                    + " Type: "
                    + monitoredObjectIdentifier.getObjectType().intValue()
                    + " Object Type "
                    + monitoredObjectIdentifier.getObjectType());
        }
     }
  }
  catch (Exception e)
  {
     System.err.println(
              " Exception occurs while reading COV Notification " + e);
  }

}

@Override public void iHaveReceived(final RemoteDevice d, final RemoteObject o) { try { System.out.println(" I Have Received !!!!!!!!!!!!!! " + d.toString()

}

danishmhmd commented 3 years ago

WireShark Capture attached as well Capure.pcapng.txt

kishorevenki commented 3 years ago

Selection_059 I tried the code, but I receicved Simple Ack for MSV,1 and AI,1. Screenshot of the wireshark is enclosed.

192.168.1.143 - BACnet4J

danishmhmd commented 3 years ago

I guess i found the issue i was using version 5.0.0 and you are testing on 6.0.0-SNAPSHOT. Let me once check this with version and update back

danishmhmd commented 3 years ago

Have checked, it is working fine in 6.0.0-SNAPSHOT had the issue with 5.0.0