{"action":"created","issue":{"url":"https://api.github.com/repos/sandeepmistry/noble/issues/420","repository_url":"https://api.github.com/repos/sandeepmistry/noble","labels_url":"https://api.github.com/repos/sandeepmistry/noble/issues/420/labels{/name}","comments_url":"https://api.github.com/repos/sandeepmistry/noble/issues/420/comments","events_url":"https://api.github.com/repos/sandeepmistry/noble/issues/420/events","html_url":"https://github.com/sandeepmistry/noble/issues/420","id":163537881,"number":420,"title":"Help connecting to known devices","user":{"login":"lessonpix","id":4677402,"avatar_url":"https://avatars.githubusercontent.com/u/4677402?v=3","gravatar_id":"","url":"https://api.github.com/users/lessonpix","html_url":"https://github.com/lessonpix","followers_url":"https://api.github.com/users/lessonpix/followers","following_url":"https://api.github.com/users/lessonpix/following{/other_user}","gists_url":"https://api.github.com/users/lessonpix/gists{/gist_id}","starred_url":"https://api.github.com/users/lessonpix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lessonpix/subscriptions","organizations_url":"https://api.github.com/users/lessonpix/orgs","repos_url":"https://api.github.com/users/lessonpix/repos","events_url":"https://api.github.com/users/lessonpix/events{/privacy}","received_events_url":"https://api.github.com/users/lessonpix/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-02T22:21:26Z","updated_at":"2016-07-02T23:02:14Z","closed_at":null,"body":"Hi folks,\r\n\r\nI've had much more luck since moving from the CSR dongle to the RPi3 internal adapter (yay).  \r\n\r\nWhat I'm seeing now is more of a timing issue that may be related to my newness to Node-style coding.  I'd like some help getting this done right, and I'll be happy to write up a guide in the Wiki when it's working.\r\n\r\nI have 8 devices I'm working with: 7 BLE bulbs and an adafruit Bluefruit chip (which is irrelevant here).  I know all of their UUIDs and I have logical Ids (positions in the room) that map to them.  Here's my current approach:\r\n\r\n1) Start Discovering at process startup\r\n2) In on(\"discover) I connect(), then discoverServices() to see if it has a bulb Characteristic and, if so, I store the Peripheral & Characteristic objects in a map and set that entry to \"valid\".\r\n3) I set a timer to periodically adjust the lights (per logic that's not relevant) every 200ms\r\n4) When I see I have all the devices, I stopScanning().\r\n\r\nWhat I'm seeing is that if I do the logic in #2 above, I miss the discovery event for some of the lights.  So I am re-working this to JUST store the peripheral object in the map and then loop through those after I have all 7 bulbs.  However, I'm finding that EVEN THAT connect() call is enough to make me miss discover events.\r\n\r\nGiven that I have the addresses, is there a better approach?  I don't see a way to connect() to peripherals by UUID (unless I'm missing something), and I LIKE the discover() approach because it would work well if the lights are turned off and on (they'd be removed & replaced in the map).\r\n\r\nSample code is attached... it relies on onecolor, but that could easily be removed\r\n\r\nWhen the connectAndSetup() call (line44) is commented out, I get this output:\r\n```\r\npi@pi3:~/fadecandy/examples/node $ node test.js\r\nState Changed: poweredOn\r\ndiscovered: b4:99:4c:55:38:d1\r\ndiscovered: b4:99:4c:64:85:26\r\ndiscovered: b4:99:4c:64:84:cb\r\ndiscovered: b4:99:4c:64:83:f4\r\ndiscovered: b4:99:4c:64:7d:bd\r\ndiscovered: b4:99:4c:64:85:01\r\ndiscovered: b4:99:4c:64:83:35\r\ndiscovered: f2:bb:cf:78:2c:85\r\n```\r\n\r\nWhen I uncomment it, I get this:\r\n```\r\nCpi@pi3:~/fadecandy/examples/node $ node test.js\r\nState Changed: poweredOn\r\ndiscovered: b4:99:4c:64:7d:bd\r\ndiscovered: b4:99:4c:55:38:d1\r\ndiscovered: b4:99:4c:64:83:f4\r\nConnecting to b4:99:4c:64:7d:bd\r\nnull\r\nFound a Bulb - b4:99:4c:64:7d:bd\r\nchecking for the map\r\nConnecting to b4:99:4c:55:38:d1\r\nnull\r\nFound a Bulb - b4:99:4c:55:38:d1\r\nchecking for the map\r\nConnecting to b4:99:4c:64:83:f4\r\nnull\r\nFound a Bulb - b4:99:4c:64:83:f4\r\nchecking for the map\r\n#the output stops here\r\n```\r\nIt looks like if that the first attempt to connect causes the scanning/disconnect to fail: I've attached the hcidump output of that second attempt.\r\n\r\nAny thoughts here?  Again, this seems like a usage that will be pretty common - people who know what peripherals to expect and want to configure them on discovery.\r\n\r\nThanks and again, I'll be happy to write \r\n[test.js.txt](https://github.com/sandeepmistry/noble/files/344752/test.js.txt)\r\n\r\n[hcidump.out.txt](https://github.com/sandeepmistry/noble/files/344754/hcidump.out.txt)\r\n\r\nup what the end result is as a guide.\r\n\r\nBill\r\n"},"comment":{"url":"https://api.github.com/repos/sandeepmistry/noble/issues/comments/230126188","html_url":"https://github.com/sandeepmistry/noble/issues/420#issuecomment-230126188","issue_url":"https://api.github.com/repos/sandeepmistry/noble/issues/420","id":230126188,"user":{"login":"lessonpix","id":4677402,"avatar_url":"https://avatars.githubusercontent.com/u/4677402?v=3","gravatar_id":"","url":"https://api.github.com/users/lessonpix","html_url":"https://github.com/lessonpix","followers_url":"https://api.github.com/users/lessonpix/followers","following_url":"https://api.github.com/users/lessonpix/following{/other_user}","gists_url":"https://api.github.com/users/lessonpix/gists{/gist_id}","starred_url":"https://api.github.com/users/lessonpix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lessonpix/subscriptions","organizations_url":"https://api.github.com/users/lessonpix/orgs","repos_url":"https://api.github.com/users/lessonpix/repos","events_url":"https://api.github.com/users/lessonpix/events{/privacy}","received_events_url":"https://api.github.com/users/lessonpix/received_events","type":"User","site_admin":false},"created_at":"2016-07-02T23:02:14Z","updated_at":"2016-07-02T23:02:14Z","body":"After adding lots of safety checks and JUST saving the peripheral, waiting until all had been connected,  I have this connected to 6 of 7 90+% of the time. and 7 of 7 50% of the time.  When it fails I see this message in hcidump:\r\n```\r\n> HCI Event: Command Status (0x0f) plen 4\r\n    LE Read Remote Used Features (0x08|0x0016) status 0x00 ncmd 1\r\n> HCI Event: Disconn Complete (0x05) plen 4\r\n    status 0x00 handle 68 reason 0x3e\r\n    Reason: Connection Failed to be Established\r\n```\r\nNow, some googling tells me that that error 0x3e can \"just happen\" sometimes (yuk).  However, don't see this error being returned (all 'error' parameters are null), so I don't know how to retry this...\r\n\r\nAny help would be appreciated.  I've included the new code for reference\r\n\r\nBill\r\n[test.js.txt](https://github.com/sandeepmistry/noble/files/344774/test.js.txt)\r\n\r\n"}}
{"actor":{"display_login":"lessonpix"}}