Code-House / bacnet4j-wrapper

Simple facade for bacnet4j api.
GNU General Public License v3.0
49 stars 21 forks source link

Example from Readme does not work. #11

Closed baardl closed 2 years ago

baardl commented 4 years ago

Hi

I'm trying to run the example from the Readme.md.

My output is:

06:39:29.686 [main] DEBUG com.serotonin.bacnet4j.transport.DefaultTransport - Broadcasting WhoIsRouter to local network
06:39:29.692 [BACnet4J IP socket listener for device 6006] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from local network. From=Address [networkNumber=0, macAddress=[a,0,4b,1,ba,c0]], local=0
06:39:29.697 [BACnet4J IP socket listener for device 6006] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from [a,0,4b,1,ba,c0]: NPDU [from=Address [networkNumber=0, macAddress=[a,0,4b,1,ba,c0]], linkService=null, networkMessageType=0]
06:39:29.706 [BACnet4J IP socket listener for device 6006] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from local network. From=Address [networkNumber=0, macAddress=[a,0,4b,1,ba,c0]], local=0
06:39:29.706 [BACnet4J IP socket listener for device 6006] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from [a,0,4b,1,ba,c0]: NPDU [from=Address [networkNumber=0, macAddress=[a,0,4b,1,ba,c0]], linkService=null, queue=[10,2,9,0,1c,2,0,17,76,2c,2,0,17,76,39,0,4e,9,70,2e,91,0,2f,9,cb,2e,2e,a4,78,2,7,5,b4,6,27,1d,42,2f,2f,9,c4,2e,91,0,2f,4f]]
06:39:29.790 [BACnet4J IP socket listener for device 6006] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from local network. From=Address [networkNumber=0, macAddress=[a,0,4b,1,ba,c0]], local=0
06:39:29.790 [BACnet4J IP socket listener for device 6006] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from [a,0,4b,1,ba,c0]: NPDU [from=Address [networkNumber=0, macAddress=[a,0,4b,1,ba,c0]], linkService=null, queue=[10,8]]
06:39:29.791 [BACnet4J IP socket listener for device 6006] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from local network. From=Address [networkNumber=0, macAddress=[a,0,4b,1,ba,c0]], local=0
06:39:29.791 [BACnet4J IP socket listener for device 6006] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from [a,0,4b,1,ba,c0]: NPDU [from=Address [networkNumber=0, macAddress=[a,0,4b,1,ba,c0]], linkService=null, queue=[10,0,c4,2,0,17,76,22,5,c4,91,0,22,3,61]]
06:39:30.213 [main] INFO no.entra.bacnet.client.Simple - Found: 0 devices

pom.xml

....
<dependencies>
        <dependency>
            <groupId>org.code-house.bacnet4j</groupId>
            <artifactId>api</artifactId>
            <version>1.1.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.code-house.bacnet4j</groupId>
            <artifactId>ip</artifactId>
            <version>1.1.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.infiniteautomation</groupId>
            <artifactId>bacnet4j</artifactId>
            <version>5.0.2</version>
        </dependency>
....

code:

package no.entra.bacnet.client;

import org.code_house.bacnet4j.wrapper.api.BacNetClient;
import org.code_house.bacnet4j.wrapper.api.Device;
import org.code_house.bacnet4j.wrapper.api.Property;
import org.code_house.bacnet4j.wrapper.ip.BacNetIpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Set;

public class Simple {
    private static final Logger log = LoggerFactory.getLogger( Simple.class );

    public Simple() {
    }

    void find() {
        String ip = "0.0.0.0";
        String broadcast = "255.255.255.255";
        int deviceId = 6006;
        BacNetClient client = new BacNetIpClient(ip,broadcast, deviceId);
        client.start();
        Set<Device> devices = client.discoverDevices(500); // given number is timeout in millis
        log.info("Found: {} devices", devices.size());
        for (Device device : devices) {
            System.out.println(device);

            for (Property property : client.getDeviceProperties(device)) {
                //System.out.println(property.getName() + " " + client.getPropertyValue(property));
               //Commented out due to wrong signature on method.
            }
        }

        client.stop();
    }

    public static void main(String[] args) {
        Simple simple = new Simple();
        simple.find();
    }
}
splatch commented 4 years ago

Hey @baardl, I believe that timeout you set on discover method call is too short. It is time in milliseconds. If you have even small network time should be couple of seconds (5000). Log entries you get is most likely output generated from local device created by library and not the real one you looking for.

Let me know if any of above helps.

splatch commented 4 years ago

@baardl is it any better with above suggestions?

baardl commented 4 years ago

@baardl is it any better with above suggestions?

Sorry for late reply. I have not had time to retry yet. I have tried with longer reply (20 sec) before, and need to retry. Bård

splatch commented 2 years ago

@baardl I believe you found your way to get it over. Please reopen issue if you still need help with it.