{"action":"opened","issue":{"url":"https://api.github.com/repos/sandeepmistry/noble/issues/467","repository_url":"https://api.github.com/repos/sandeepmistry/noble","labels_url":"https://api.github.com/repos/sandeepmistry/noble/issues/467/labels{/name}","comments_url":"https://api.github.com/repos/sandeepmistry/noble/issues/467/comments","events_url":"https://api.github.com/repos/sandeepmistry/noble/issues/467/events","html_url":"https://github.com/sandeepmistry/noble/issues/467","id":179211793,"number":467,"title":"Peripheral Explore on RPi 3 using node-red","user":{"login":"rbagree","id":17608412,"avatar_url":"https://avatars.githubusercontent.com/u/17608412?v=3","gravatar_id":"","url":"https://api.github.com/users/rbagree","html_url":"https://github.com/rbagree","followers_url":"https://api.github.com/users/rbagree/followers","following_url":"https://api.github.com/users/rbagree/following{/other_user}","gists_url":"https://api.github.com/users/rbagree/gists{/gist_id}","starred_url":"https://api.github.com/users/rbagree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbagree/subscriptions","organizations_url":"https://api.github.com/users/rbagree/orgs","repos_url":"https://api.github.com/users/rbagree/repos","events_url":"https://api.github.com/users/rbagree/events{/privacy}","received_events_url":"https://api.github.com/users/rbagree/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-26T12:13:13Z","updated_at":"2016-09-26T12:13:13Z","closed_at":null,"body":"Hi,\r\nI am new but very enthusiastic about  BLE and to node.js as well. \r\n\r\nThe tasks I am trying to achieve are:\r\n1. Connect the RPi-3 to a peripheral and explore its services and characteristics\r\n2. Read/ write characteristics on the peripheral and send the data over MQTT to a remote server.\r\n\r\nI found Node-Red as the easiest way to begin. so, as per various tutorial I installed the node-red and noble's \"scanBLE\" node. It worked fine. Got the Mac address of all the nearby peripheral.\r\n\r\nNow I am trying to extends the \"scanBLE\" node's code to explore the services and characteristics of the peripherals. I am able to make the connection with the peripheral but after that there is no output on the console. \r\nFollowing is the code (I have removed the copyright text just for posting the code. This is based on the noble and the scanBLE node available for th Node-Red)\r\n\r\nPlease suggest the changes/error/mistake.\r\n`\r\n module.exports = function(RED){\r\n\t\"use strict\"\r\n\t\r\n\tvar noble = require('noble');\r\n\r\n\tfunction NobleScan(n) {\r\n\t\r\n\tRED.nodes.createNode(this, n);\r\n\t\r\n\tthis.duplicates = n.duplicates;\r\n\tthis.uuids = [];\r\n\r\n\tif(n.uuids != undefined && n.uuids !== \"\")\r\n\t\tthis.uuids = n.uuids.split(',');\r\n\r\n\tvar node = this;\r\n\tvar scanning = false;\r\n\tvar scanUUID = '713d0000503e4c75ba943148f18d941e';\r\n\r\n\tfunction startScan(stateChange, error){\r\n\t\t\r\n\t\tif(!node.scanning){\r\n\t\t\r\n\t\t\tvar msg = {\r\n\t\t\t\tstatusUpdate: true,\r\n\t\t\t\terror: error, \r\n\t\t\t\tstateChange: stateChange,\r\n\t\t\t\tstate: noble.state,\r\n\t\t\t\tlocation: \"startScan\"\r\n\t\t\t};\r\n\t\t\tnode.send(msg);\r\n\t\t\t//lets start scanning\r\n\t\t\t\r\n\t\t\tnoble.startScanning(node.uuids, node.duplicates, function(){\r\n\t\t\t \tnode.log(\"Scanning for BLEs Started. UUIDs: \"+ node.uuids + \" - Duplicates allowed: \" + node.duplicates);\r\n\t\t\t\tnode.status({fill:\"green\", shape:\"dot\", text:\"started\"});\r\n\t\t\t\tnode.scanning = true;\r\n\t\t\t});\t\r\n\t\t}\r\n\r\n\t}\r\n\r\n\tfunction stopScan(stateChange, error){\r\n\t\tif(node.scanning){\r\n\t\t\tvar msg = {\r\n\t\t\t\tstatusUpdate: true,\r\n                                error: error,\r\n                                stateChange: stateChange,\r\n                                state: noble.state,\r\n                                location: \"stopScan\"\r\n\t\t\t};\r\n\t\t\tnode.send(msg);\r\n\t\t\t\r\n\t\t\tnoble.stopScanning(function(){\r\n\t\t\t\tnode.log('BLE scanning stopped.');\r\n\t\t\t\tnode.status({fill:\"red\", shape: \"ring\", text: \"stopped\"});\r\n\t\t\t\tnode.scanning = false\r\n\t\t\t});\r\n\t\t\tif (error)\r\n\t\t\t\tnode.warn(\"BLE scanning stopped due to change in adapter state.\");\r\n\t\t}\r\n\t}\r\n\r\n\r\n\tnoble.on('discover', function(peripheral){\r\n\t\tif(peripheral.advertisement.serviceUuids == scanUUID){\r\n\t\t\tnode.log('Node discovered');\r\n\t\t\tif (node.scanning)\r\n                    \t\tstopScan(true, true);\r\n                \t\r\n\t\t\tperipheral.connect(function(err){\r\n\t\t\t\tperipheral.discoverServices([], function(err, services){\r\n\t\t\t\t\tservices.forEach(function(service){\r\n\t\t\t\t\t\tnode.log('found service:', service.uuid);\r\n\t\t\t\t\t\tservice.discoverCharacteristics([], function(err, characteristics){\r\n\t\t\t\t\t\t\tcharacteristics.forEach(function(characteristic){\r\n\t\t\t\t\t\t\t\tnode.log('found characteristics:', characteristic.uuid);\r\n\t\t\t\t\t\t\t})\r\n\t\t\t\t\t\t})\r\n\t\t\t\t\t})\r\n\t\t\t\t})\r\n\t\t\t})\r\n\t\t\r\n\t\t}\r\n\t});\r\n\r\n\tnoble.on('stateChange', function(state){\r\n\t\tif(state === 'poweredOn'){\r\n\t\t\tnode.log('I am powered up');\r\n\t\t\tstartScan(true, false);\r\n\t\t}\r\n\t\telse{\r\n\t\t\tif(node.scanning){\r\n\t\t\t\tnode.log('Let us stop scanning');\r\n\t\t\t\tstopScan(true, true);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t});\r\n\r\n\tnode.on(\"close\", function(){\r\n\t\tstopScan(false, false);\r\n\t\tnoble.removeAllListeners();\r\n\r\n\t});\r\n\r\n\t//it all begins from this space\r\n\tif(noble.state === 'poweredOn'){\r\n\t\tstartScan(false, false);\r\n\t\t//node.log('Node is poweredOn');\r\n\t} else{\r\n\t\tvar msg = {\r\n\t\t\tstatusUpdate: true,\r\n\t\t\terror: true,\r\n\t\t\tstateChange: false,\r\n\t\t\tstate:noble.state,\r\n\t\t\tlocation: \"begining if statement\"\r\n\t\t};\r\n\t\tsetTimeout(function(){\r\n\t\t\tnode.send(msg);}, 3000);\r\n\t\tnode.warn('Unable to start BLE scan. Adapter state: '+ noble.state);\r\n\t\tnode.log('Node is not poweredon');\r\n\t};\r\n\t}\r\n\tRED.nodes.registerType(\"scan ble\", NobleScan);\r\n}\r\n`\r\n\r\n"}}
{"actor":{"display_login":"rbagree"}}