在 BLE 设备上使用 cordova bluetoothSerial 插件
Using cordova bluetoothSerial plug-in with a BLE device
我正在开发一个应用程序,用于向低功耗蓝牙设备发送非常简单的消息。
我使用我的开发平台 (Galaxy S5 Android 4.4) 进行了测试,由于 Nordic Semi 的 nRF UART v2.0 应用程序,可以在设备(Arduino 板和 nRF8001 扩展板)之间建立正确的通信.它工作得很好,因为我可以从一台设备向另一台设备发送和接收消息,所以我对产品的这一方面非常有信心。
我的基于 Cordova 的 bluetoothSerial 插件的应用无法成功与 BLE 设备建立连接。这是代码:
var app = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
document.getElementById('messagebox').innerHTML = "Device Ready";
app.isBluetoothEnabled();
},
isBluetoothEnabled: function() {
document.getElementById('messagebox').innerHTML = "is Bluetooth Enabled";
bluetoothSerial.isEnabled(
function() {
document.getElementById('messagebox').innerHTML = "Bluetooth is enabled";
app.deviceConnect();
},
app.bluetoothEnable()
);
},
bluetoothEnable: function() {
bluetoothSerial.enable(app.deviceConnect(),
function() {
document.getElementById('messagebox').innerHTML = "User did not want to connect.";
});
},
deviceConnect: function() {
bluetoothSerial.connect('DB:A2:49:84:F9:32',
function() {
document.getElementById('messagebox').innerHTML = "Connected to device";
},
function() {
document.getElementById('messagebox').innerHTML = "Not connected to device";
});
}
};
app.initialize();
'messagebox' 元素仅用于检查应用程序停止的每个步骤。
我尝试了方法.list 和.discoverUnpaired。两者都在工作(.list 只列出已经配对的设备)并且使用 discoverPaired 方法我可以看到我的设备及其 MAC 地址,但是 .connect 从未工作过,即使在 connectInsecure 模式下,我也没有成功配对我的设备通过蓝牙参数中的 Android OS(我不知道在尝试与应用程序建立任何连接之前是否需要它)。
如果我误解了 bluetootSerial 的工作方式或(甚至是 BLE),有人能告诉我吗?我是否必须将 MAC 地址以外的其他参数传递给连接方法?
非常感谢
BluetoothSerial plugin 在 Android 上使用 Bluetooth Classic,因此不适用于此用例。 (BluetoothSerial 插件在 iOS 上使用 BLE。)
尝试Bluetooth Low Energy Cordova plugin从Android或iOS连接到nRF8001。
看看bluefruitle example。它连接到 Nordic BLE UART 服务。
我正在开发一个应用程序,用于向低功耗蓝牙设备发送非常简单的消息。
我使用我的开发平台 (Galaxy S5 Android 4.4) 进行了测试,由于 Nordic Semi 的 nRF UART v2.0 应用程序,可以在设备(Arduino 板和 nRF8001 扩展板)之间建立正确的通信.它工作得很好,因为我可以从一台设备向另一台设备发送和接收消息,所以我对产品的这一方面非常有信心。
我的基于 Cordova 的 bluetoothSerial 插件的应用无法成功与 BLE 设备建立连接。这是代码:
var app = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
document.getElementById('messagebox').innerHTML = "Device Ready";
app.isBluetoothEnabled();
},
isBluetoothEnabled: function() {
document.getElementById('messagebox').innerHTML = "is Bluetooth Enabled";
bluetoothSerial.isEnabled(
function() {
document.getElementById('messagebox').innerHTML = "Bluetooth is enabled";
app.deviceConnect();
},
app.bluetoothEnable()
);
},
bluetoothEnable: function() {
bluetoothSerial.enable(app.deviceConnect(),
function() {
document.getElementById('messagebox').innerHTML = "User did not want to connect.";
});
},
deviceConnect: function() {
bluetoothSerial.connect('DB:A2:49:84:F9:32',
function() {
document.getElementById('messagebox').innerHTML = "Connected to device";
},
function() {
document.getElementById('messagebox').innerHTML = "Not connected to device";
});
}
};
app.initialize();
'messagebox' 元素仅用于检查应用程序停止的每个步骤。
我尝试了方法.list 和.discoverUnpaired。两者都在工作(.list 只列出已经配对的设备)并且使用 discoverPaired 方法我可以看到我的设备及其 MAC 地址,但是 .connect 从未工作过,即使在 connectInsecure 模式下,我也没有成功配对我的设备通过蓝牙参数中的 Android OS(我不知道在尝试与应用程序建立任何连接之前是否需要它)。
如果我误解了 bluetootSerial 的工作方式或(甚至是 BLE),有人能告诉我吗?我是否必须将 MAC 地址以外的其他参数传递给连接方法?
非常感谢
BluetoothSerial plugin 在 Android 上使用 Bluetooth Classic,因此不适用于此用例。 (BluetoothSerial 插件在 iOS 上使用 BLE。)
尝试Bluetooth Low Energy Cordova plugin从Android或iOS连接到nRF8001。
看看bluefruitle example。它连接到 Nordic BLE UART 服务。