{"action":"created","issue":{"url":"https://api.github.com/repos/calimero-project/calimero-core/issues/36","repository_url":"https://api.github.com/repos/calimero-project/calimero-core","labels_url":"https://api.github.com/repos/calimero-project/calimero-core/issues/36/labels{/name}","comments_url":"https://api.github.com/repos/calimero-project/calimero-core/issues/36/comments","events_url":"https://api.github.com/repos/calimero-project/calimero-core/issues/36/events","html_url":"https://github.com/calimero-project/calimero-core/issues/36","id":179302128,"number":36,"title":"Device discovery not reliable?!","user":{"login":"tuxedo0801","id":2862906,"avatar_url":"https://avatars.githubusercontent.com/u/2862906?v=3","gravatar_id":"","url":"https://api.github.com/users/tuxedo0801","html_url":"https://github.com/tuxedo0801","followers_url":"https://api.github.com/users/tuxedo0801/followers","following_url":"https://api.github.com/users/tuxedo0801/following{/other_user}","gists_url":"https://api.github.com/users/tuxedo0801/gists{/gist_id}","starred_url":"https://api.github.com/users/tuxedo0801/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tuxedo0801/subscriptions","organizations_url":"https://api.github.com/users/tuxedo0801/orgs","repos_url":"https://api.github.com/users/tuxedo0801/repos","events_url":"https://api.github.com/users/tuxedo0801/events{/privacy}","received_events_url":"https://api.github.com/users/tuxedo0801/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-26T18:25:22Z","updated_at":"2016-09-28T09:37:20Z","closed_at":null,"body":"Hi,\r\n\r\nI'm using 2.3-beta and face the following problem when trying to discover KNX interface devices:\r\n\r\nThe result is not deterministic: Sometimes I find my routing and tunneling device, sometimes not. I then just need to repeat the procedure a few times, and device is again detected...\r\n\r\nhere's the related code-snippet I'm using:\r\n\r\n```java\r\nList<KnxInterfaceDevice> foundDevices = new ArrayList<>(); // List of detected devices. KnxInterface Device is a simple container object that holds the relevant information for my application to setup the correct KNX connection\r\ntry {\r\n\r\n            Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();\r\n\r\n            // addresses to scan\r\n            int count = 0;\r\n\r\n            if (progress != null) {\r\n                // gathering count data\r\n                while (networkInterfaces.hasMoreElements()) {\r\n                    NetworkInterface ni = networkInterfaces.nextElement();\r\n\r\n                    if (ni.isLoopback() || !ni.isUp()) {\r\n                        continue;\r\n                    }\r\n\r\n                    for (InterfaceAddress iaddr : ni.getInterfaceAddresses()) {\r\n                        if (iaddr.getAddress() instanceof Inet6Address) {\r\n                            continue;\r\n                        }\r\n                        count++;\r\n                    }\r\n                }\r\n\r\n                networkInterfaces = NetworkInterface.getNetworkInterfaces();\r\n            }\r\n\r\n            int i = 0;\r\n            while (networkInterfaces.hasMoreElements()) {\r\n                NetworkInterface ni = networkInterfaces.nextElement();\r\n\r\n                if (ni.isLoopback() || !ni.isUp()) {\r\n                    continue;\r\n                }\r\n                log.debug(\"Found network interface: \" + ni.getName() + \"/\" + ni.getDisplayName() + \"/\" + ni.getInterfaceAddresses());\r\n                try {\r\n\r\n                    for (InterfaceAddress iaddr : ni.getInterfaceAddresses()) {\r\n                        if (iaddr.getAddress() instanceof Inet6Address) {\r\n                            continue;\r\n                        }\r\n                        log.debug(\"Discovering on \" + ni.getName() + \"@\" + iaddr.getAddress());\r\n                        Discoverer discoverer = new Discoverer(iaddr.getAddress(), 0, false, false);\r\n                        if (progress != null) {\r\n                            i++;\r\n                            progress.onProgress(i, count, ni, iaddr.getAddress());\r\n                        }\r\n                        discoverer.startSearch(ni, timeout, true);\r\n                        SearchResponse[] result = discoverer.getSearchResponses();\r\n\r\n                        for (SearchResponse sr : result) {\r\n\r\n                            ServiceFamiliesDIB serviceFamilies = sr.getServiceFamilies();\r\n                            int[] familyIds = serviceFamilies.getFamilyIds();\r\n\r\n                            for (int n = 0; n < familyIds.length; n++) {\r\n\r\n                                int id = familyIds[n];\r\n                                KnxInterfaceDevice foundDevice = null;\r\n                                switch (id) {\r\n                                    case ServiceFamiliesDIB.ROUTING:\r\n                                        foundDevice = new KnxRoutingDevice(ni, sr);\r\n                                        break;\r\n                                    case ServiceFamiliesDIB.TUNNELING:\r\n                                        foundDevice = new KnxTunnelingDevice(ni, sr);\r\n                                        break;\r\n                                    default:\r\n                                        log.warn(\"Unsupported device family: {}\", serviceFamilies.getFamilyName(id));\r\n                                }\r\n                                if (foundDevice != null) {\r\n                                    log.debug(\"Found: {}\", foundDevice);\r\n                                    foundDevices.add(foundDevice);\r\n                                }\r\n\r\n                            }\r\n\r\n                        }\r\n                        discoverer.clearSearchResponses();\r\n                    }\r\n                } catch (Exception ex) {\r\n                    ex.printStackTrace();\r\n                }\r\n\r\n            }\r\n\r\n        } catch (SocketException ex) {\r\n            ex.printStackTrace();\r\n        }\r\n```\r\n\r\nSome words on the implementation:\r\n\r\nWhen working with multiple network interfaces on a single machine, I have to know on which network interface the KNX IP Router is running. So I first get all related network interfaces and then run a discovery on each of them. It makes no difference if I use a timeout of 1sec, 5sec or 15sec. \r\n\r\nI personally faced this issue in Debian Testing AMD64, but some other people faced this on Win7 as well. \r\nI have no firewall running. The PC is connected via LAN to a switch, where also the MDT IP Router is connected to (no WiFi or Fritzbox inbetween).\r\n\r\nAny ideas what's wrong?!"},"comment":{"url":"https://api.github.com/repos/calimero-project/calimero-core/issues/comments/250119670","html_url":"https://github.com/calimero-project/calimero-core/issues/36#issuecomment-250119670","issue_url":"https://api.github.com/repos/calimero-project/calimero-core/issues/36","id":250119670,"user":{"login":"bertvermeiren","id":12035213,"avatar_url":"https://avatars.githubusercontent.com/u/12035213?v=3","gravatar_id":"","url":"https://api.github.com/users/bertvermeiren","html_url":"https://github.com/bertvermeiren","followers_url":"https://api.github.com/users/bertvermeiren/followers","following_url":"https://api.github.com/users/bertvermeiren/following{/other_user}","gists_url":"https://api.github.com/users/bertvermeiren/gists{/gist_id}","starred_url":"https://api.github.com/users/bertvermeiren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bertvermeiren/subscriptions","organizations_url":"https://api.github.com/users/bertvermeiren/orgs","repos_url":"https://api.github.com/users/bertvermeiren/repos","events_url":"https://api.github.com/users/bertvermeiren/events{/privacy}","received_events_url":"https://api.github.com/users/bertvermeiren/received_events","type":"User","site_admin":false},"created_at":"2016-09-28T09:37:20Z","updated_at":"2016-09-28T09:37:20Z","body":"Hi,\n\nI once played with the library and even attempted to write my own java\nimplementation.\nFrom what I see in the github code base there is a possibility to not see\nthe reply when doing discovering.\n\n\nI have a lot of experience in the java world as a professional with multi\nthreaded behaviour.\n\nWithin the Discoverer class you see following code when sending out the\nmulticast packet for discovery :\n\ns.send(new DatagramPacket(buf, buf.length, SYSTEM_SETUP_MULTICAST,\nSEARCH_PORT));\nsynchronized (receivers) {\nfinal ReceiverLoop l = startReceiver(s, timeout,\nnifName + localAddr.getHostAddress());\nreceivers.add(l);\nreturn l;\n}\n\n\nThe time between sending out and starting up your listener thread reading\nfrom the socket, the device can already have sent back the reply and your\nreader thread is not started yet.\nYou should first start your reader thread before sending out the multicast.\n\nJust my experience.\n\nGreetings\n\nBert Vermeiren.\n\n\n\n\n\n\n\n\n\n\n2016-09-28 11:24 GMT+02:00 bmalinowsky <notifications@github.com>:\n\n> Hi, for you setup the set timeout does not matter. 2 seconds or so should\n> be plenty time.\n>\n> Do you know whether there actually is a response received, and whether it\n> was discarded?\n>\n> —\n> You are receiving this because you are subscribed to this thread.\n> Reply to this email directly, view it on GitHub\n> <https://github.com/calimero-project/calimero-core/issues/36#issuecomment-250116642>,\n> or mute the thread\n> <https://github.com/notifications/unsubscribe-auth/ALekjev6klfHO826qAdPUST88CSklRXdks5qujI_gaJpZM4KG15T>\n> .\n>\n"}}
{"actor":{"display_login":"bertvermeiren"}}