You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create an Android app where two devices can send to each other message. Everything works fine (Im using bluetooth2.1 rfcomm connection) but i have small problem in java script.
When connection is created beetwen two devices (on java side they are in ConnectedThread) In java script method GetConnectedDevices() is returning empty table on both devices.
And another question:
Is there easy way to create addEventListener to read ANY message which is coming to my device. From documantation i understand that u must have device object and then run method rfcommRead . But I dont know how to get this object for now.
Sorry For My Bad English :(
Here is my code:
if(!BC.bluetooth.isopen){
BC.Bluetooth.OpenBluetooth(init,function(){alert("There is problem with bluetooth. Please restart application");});
}else{
init();
}
function init(){
$scope.blueReady = true;
BC.Bluetooth.RFCOMMListen("appName","7A9C3B55-78D0-44A7-A94E-A93E3FE118CE",false);
};
$scope.startScan = function(){
BC.Bluetooth.StartScan("Classical");
alert("Started Scan");
};
$scope.connectDevice = function(device){
BC.Bluetooth.StopScan();
alert("connection start: "+ JSON.stringify(BC.bluetooth.devices[device.deviceAddress]));
device = BC.bluetooth.devices[device.deviceAddress];
device.connect(function(){writeMSG(device)},function(){alert("error!");},"7A9C3B55-78D0-44A7-A94E-A93E3FE118CE",false);
};
var writeMSG = function(device){
alert("device is already connected well! is connected: "+device.isConnected);
device.rfcommWrite("Hex","01",writeSuccess);
function writeSuccess(data){
alert("write success!" + JSON.stringify(data));
}
};
var readMSG = function(device){
device.rfcommRead(readSuccess);
function readSuccess(data){
alert("Data : "+JSON.stringify(data.value)+" \n Time :"+data.date);
}
};
BC.bluetooth.addEventListener("newdevice",addNewDevice);
function addNewDevice(s){
var newDevice = s.target;
$scope.devices.push(newDevice);
readMSG(device);
alert("new device be found! it's device Address is: " + JSON.stringify(newDevice));
};
$scope.connectedDevices = function(){
BC.Bluetooth.GetConnectedDevices(function(mes){alert("this is connected: "+JSON.stringify(mes));});
};
The text was updated successfully, but these errors were encountered:
Hi There,
I'm trying to create an Android app where two devices can send to each other message. Everything works fine (Im using bluetooth2.1 rfcomm connection) but i have small problem in java script.
When connection is created beetwen two devices (on java side they are in ConnectedThread) In java script method GetConnectedDevices() is returning empty table on both devices.
And another question:
Is there easy way to create addEventListener to read ANY message which is coming to my device. From documantation i understand that u must have device object and then run method rfcommRead . But I dont know how to get this object for now.
Sorry For My Bad English :(
Here is my code:
if(!BC.bluetooth.isopen){
BC.Bluetooth.OpenBluetooth(init,function(){alert("There is problem with bluetooth. Please restart application");});
}else{
init();
}
function init(){
$scope.blueReady = true;
BC.Bluetooth.RFCOMMListen("appName","7A9C3B55-78D0-44A7-A94E-A93E3FE118CE",false);
The text was updated successfully, but these errors were encountered: