{"action":"created","issue":{"url":"https://api.github.com/repos/sandeepmistry/bleno/issues/131","labels_url":"https://api.github.com/repos/sandeepmistry/bleno/issues/131/labels{/name}","comments_url":"https://api.github.com/repos/sandeepmistry/bleno/issues/131/comments","events_url":"https://api.github.com/repos/sandeepmistry/bleno/issues/131/events","html_url":"https://github.com/sandeepmistry/bleno/issues/131","id":108226478,"number":131,"title":"Intermittently working on Edison","user":{"login":"mikaye","id":656239,"avatar_url":"https://avatars.githubusercontent.com/u/656239?v=3","gravatar_id":"","url":"https://api.github.com/users/mikaye","html_url":"https://github.com/mikaye","followers_url":"https://api.github.com/users/mikaye/followers","following_url":"https://api.github.com/users/mikaye/following{/other_user}","gists_url":"https://api.github.com/users/mikaye/gists{/gist_id}","starred_url":"https://api.github.com/users/mikaye/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikaye/subscriptions","organizations_url":"https://api.github.com/users/mikaye/orgs","repos_url":"https://api.github.com/users/mikaye/repos","events_url":"https://api.github.com/users/mikaye/events{/privacy}","received_events_url":"https://api.github.com/users/mikaye/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":25,"created_at":"2015-09-24T22:32:23Z","updated_at":"2015-10-26T15:07:27Z","closed_at":null,"body":"When running test.js on the edison, sometimes the android scanner sees it advertise as 'test' and I'm able to connect and all works as I would expect. Mostly, it sees it as \"BCM433...\" and I'm unable to connect"},"comment":{"url":"https://api.github.com/repos/sandeepmistry/bleno/issues/comments/151167671","html_url":"https://github.com/sandeepmistry/bleno/issues/131#issuecomment-151167671","issue_url":"https://api.github.com/repos/sandeepmistry/bleno/issues/131","id":151167671,"user":{"login":"danki","id":2181315,"avatar_url":"https://avatars.githubusercontent.com/u/2181315?v=3","gravatar_id":"","url":"https://api.github.com/users/danki","html_url":"https://github.com/danki","followers_url":"https://api.github.com/users/danki/followers","following_url":"https://api.github.com/users/danki/following{/other_user}","gists_url":"https://api.github.com/users/danki/gists{/gist_id}","starred_url":"https://api.github.com/users/danki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danki/subscriptions","organizations_url":"https://api.github.com/users/danki/orgs","repos_url":"https://api.github.com/users/danki/repos","events_url":"https://api.github.com/users/danki/events{/privacy}","received_events_url":"https://api.github.com/users/danki/received_events","type":"User","site_admin":false},"created_at":"2015-10-26T15:07:27Z","updated_at":"2015-10-26T15:07:27Z","body":"@mikaye sorry for hi-jacking you post, the original issue you described, iven seen that behaviour as well in my project. Tho ive found a mini workaround to BCM... advertising.\r\n\r\nFirst, in bleno app, onconnect, add a timeoutlike this:\r\n```javascript\r\nglobal.g_timeout = setTimeout(function(){\r\n    if(bleno){\r\n        bleno.disconnect();\r\n        bleno.stopAdv(); }\r\n}, 10000); // Give it 10 sec to establish connection\r\n```\r\n\r\nThen create a characteristics, where you set read or write properties, which when executed, clears the timeout\r\n```javascript\r\nclearTimeout( global.g_timeout );\r\n```\r\n\r\n1) First when you scan for Bleno, lets say you find it as BCM...\r\n2) Make a connection, which eventually will be disconnected, you will need to scan and connect again afterwards, where hopefully your phone sees bleno as advertised name and as BLE (in bluetooth low energy it would be type 2). BCM usually is type 3 and when your phone sees that type, your node app has failed initiate properly i think.\r\n3) When you see that advertising name in scannings, make a connection which hopefully is success, and right after that write/read the characteristics which clears the timeout.\r\n\r\nYou may also do some pre-initiation in bleno app (ive had to do that few times)\r\nWhen ever the main.js is started in nodejs, you use exec to dovarious things:\r\n\r\n Run this as first thing in bleno app, just to be sure\r\n```javascript\r\n// You may want to change hciconfig to run up command instead of reset, test around to see what works\r\nexec(\"rfkill unblick bluetooth && hciconfig hci0 reset && sleep 5 && echo 'OK'\",function(err, in, ou){\r\n\tif(err){\r\n\t\tconsole.log(err);\r\n\r\n\t\tif (ou.indexOf(\"No such device\") > -1 || ou.indexOf(\"(110)\") > -1) {\r\n\t\t\tconsole.log(\"This is big problem, HCI is completely dead!!!!\")\r\n\t\t\tconsole.log(\"Need to reboot the system...\")\r\n\t\t\tsetTimeout(function () {\r\n\t\t\t\texec(\"reboot\", null);\r\n\t\t\t\treturn;\r\n\t\t\t}, 3000);\r\n\t\t}\r\n\r\n\t\t// Use this ONLY if you have a service running, which is setup to restart app if it exits\r\n\t\tsetTimeout(function () {\r\n\t\t\tconsole.log(\"Exiting APP!\");\r\n\t\t\tprocess.exit(2);\r\n\t\t}, 5000);\r\n\t}else{\r\n\t\t// Just to clear any cache\r\n\t\tfor ( var i in require.cache ){\r\n\t\t\tif(i.indexOf(\"/bleno/\") > -1 ){\r\n\t\t\t\tdelete require.cache[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(in.indexOf(\"OK\") > -1){\r\n        // Initiate Bleno library like\r\n\t\t\tbleno = require(\"bleno\");\r\n        // add event listeners as no on\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\nAnother tip, set a timeout to exit the app after like 5 seconds.\r\nNow when Bleno initiated and you get event  stateChanged poweredOff or unsupported, exit the app so service can re-start it again. If statechanged gives you poweredOn OR your startAdvertising is triggered, you can kill this timeout so app would not exit when everything is correct.\r\n\r\nIve tested around all kinds of solutions, and (cant share code tho) what i do is that my bleno app runs as service, (boots up with edison). The service is set to restart the app whenever the exit code is non clean. In my Case clean exit is 0, so any other exit are non clean ones.\r\n\r\nAlso, you could tie bleno lib event stateChanged  poweredOff and unsupported to some kind of behaviour to re-enable your app and its advertising.\r\n\r\nI hope this might help you a little and you'll find a good way to get it back working.\r\n\r\nPS. these above examples were what ive tried and tested, at some, my current setup is similar, and so far only \"way\" that assures the right conditions for bleno to work and i have not has any issues so far.\r\n\r\n"}}