{"action":"created","issue":{"url":"https://api.github.com/repos/don/BluetoothSerial/issues/223","repository_url":"https://api.github.com/repos/don/BluetoothSerial","labels_url":"https://api.github.com/repos/don/BluetoothSerial/issues/223/labels{/name}","comments_url":"https://api.github.com/repos/don/BluetoothSerial/issues/223/comments","events_url":"https://api.github.com/repos/don/BluetoothSerial/issues/223/events","html_url":"https://github.com/don/BluetoothSerial/issues/223","id":150902901,"number":223,"title":"read from two HC-06s","user":{"login":"diattamo","id":10426238,"avatar_url":"https://avatars.githubusercontent.com/u/10426238?v=3","gravatar_id":"","url":"https://api.github.com/users/diattamo","html_url":"https://github.com/diattamo","followers_url":"https://api.github.com/users/diattamo/followers","following_url":"https://api.github.com/users/diattamo/following{/other_user}","gists_url":"https://api.github.com/users/diattamo/gists{/gist_id}","starred_url":"https://api.github.com/users/diattamo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diattamo/subscriptions","organizations_url":"https://api.github.com/users/diattamo/orgs","repos_url":"https://api.github.com/users/diattamo/repos","events_url":"https://api.github.com/users/diattamo/events{/privacy}","received_events_url":"https://api.github.com/users/diattamo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-25T15:39:33Z","updated_at":"2016-04-28T18:02:42Z","closed_at":null,"body":"Hello I am trying to read data from two HC-06 modules each connected to their own arduino. \r\nWhat I am trying to do is:\r\nconnect to 1, disconnect from it, connect to the second one and and then disconnect again. I have gotten it to work once but I keep running into this issue. \r\n\r\n> 04-25 11:34:44.703 22437-23021/com.phonegap.helloworld E/BluetoothSerialService: java.io.IOException: read failed, socket might closed or timeout, read ret: -1\r\n\r\nSometimes it connects, but only to the first module. \r\n\r\nHere is my code (below). Any suggestions as to how I should be handling the flow of connect to 1->disconnect->connect to 2->disconnect will be appreciated.\r\n\r\n`var app = {\r\n    initialize: function() {\r\n        this.bindEvents();\r\n        localStorage.currentUnit = JSON.stringify(\"kg\");\r\n    },\r\n    initializeSettings: function() {\r\n        document.getElementById(\"current-unit\").innerHTML = JSON.parse(localStorage.currentUnit);\r\n    },\r\n    bindEvents: function() {\r\n        document.addEventListener('deviceready', this.onDeviceReady, false);\r\n        Measure.addEventListener('touchstart', this.connect1, false);\r\n    },\r\n    onDeviceReady: function() {\r\n         console.log(\"device ready\");\r\n    },\r\n\r\n    connect1: function() {\r\n        console.log(\"connecting to bluetooth 1\");\r\n\r\n        var onConnect = function() {\r\n                // subscribe for incoming data\r\n                bluetoothSerial.subscribe(\"\\n\", app.onMessage1, app.subscribeFailed); \r\n                bluetoothSerial.write(\"1\");\r\n            };\r\n\r\n        bluetoothSerial.connect(macAddress, onConnect, app.onFailconnect);\r\n\r\n    },\r\n    connect2: function() {\r\n        console.log(\"connecting to bluetooth 2\");\r\n\r\n        var onConnect = function() {\r\n                // subscribe for incoming data\r\n                bluetoothSerial.subscribe(\"\\n\", app.onMessage2, app.subscribeFailed); \r\n                bluetoothSerial.write(\"1\");\r\n            };\r\n\r\n        bluetoothSerial.connect(macAddress2, onConnect, app.onFailconnect);\r\n    },\r\n    onFailconnect: function() {\r\n        console.log(\"connection failed\");\r\n    },\r\n    onMessage1: function(data) {\r\n        console.log(\"reading 1\");\r\n        counter.innerHTML = data;\r\n        bluetoothSerial.disconnect(app.connect2, app.failDisc);\r\n\r\n\r\n    },\r\n    onMessage2: function(data) {\r\n        console.log(\"reading 2\");\r\n        counter.innerHTML = \"data2\";\r\n        bluetoothSerial.disconnect(app.successDisc, app.failDisc);\r\n    },\r\n    subscribeFailed: function() {\r\n        alert(\"subscribe failed\");\r\n    },\r\n    successDisc: function() {\r\n        console.log(\"Disconnect successful\");\r\n    },\r\n    failDisc: function() {\r\n        console.log(\"Disconnect Unsuccessful\");\r\n    },\r\n\r\n};`"},"comment":{"url":"https://api.github.com/repos/don/BluetoothSerial/issues/comments/215512209","html_url":"https://github.com/don/BluetoothSerial/issues/223#issuecomment-215512209","issue_url":"https://api.github.com/repos/don/BluetoothSerial/issues/223","id":215512209,"user":{"login":"don","id":3133,"avatar_url":"https://avatars.githubusercontent.com/u/3133?v=3","gravatar_id":"","url":"https://api.github.com/users/don","html_url":"https://github.com/don","followers_url":"https://api.github.com/users/don/followers","following_url":"https://api.github.com/users/don/following{/other_user}","gists_url":"https://api.github.com/users/don/gists{/gist_id}","starred_url":"https://api.github.com/users/don/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/don/subscriptions","organizations_url":"https://api.github.com/users/don/orgs","repos_url":"https://api.github.com/users/don/repos","events_url":"https://api.github.com/users/don/events{/privacy}","received_events_url":"https://api.github.com/users/don/received_events","type":"User","site_admin":false},"created_at":"2016-04-28T18:02:42Z","updated_at":"2016-04-28T18:02:42Z","body":"This should work. If you disconnect and reconnect to the **same** device do you get this error?  (Try with each device.)\r\n\r\nAfter you disconnect from the peripheral, is there something that need to be reset before it will accept a new connection?\r\n\r\nIs it a timing issue? If you wait a bit, can you successfully connect?\r\n"}}