I connected to hm-10 from android well.
Hm-10 is not flicking anymore.
but after connected,
How can I send String data to Hm-10?
private ScanCallback mScanCallback = new ScanCallback() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onScanResult(int callbackType, ScanResult result) {
System.out.println("BLE// onScanResult");
super.onScanResult(callbackType, result);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Log.e("action","this name : "+result.getDevice().getName());
Log.e("action","this addr : "+result.getDevice().getAddress());
Log.e("action","this getuuid is : "+result.getDevice().getUuids());
}
if(result.getDevice().getAddress().equals("0C:B2:B7:7B:B2:BB")){
BluetoothDevice btDevice = result.getDevice();
Log.e("action","BB sending. : "+btDevice.toString());
connectToDevice(btDevice);
return;
}
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
System.out.println("BLE// onBatchScanResults");
Log.e("action","onBatchScanResults");
for (ScanResult sr : results) {
Log.e("action", "testing..."+sr.toString());
}
}
@Override
public void onScanFailed(int errorCode) {
System.out.println("BLE// onScanFailed");
Log.e("action", "Error Code: " + errorCode);
}
};
------------------------------------------
public void connectToDevice(BluetoothDevice device)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
Log.e("action","connectToDevice");
bluetoothGatt = device.connectGatt(this, false, mainGattCallback);
}
scanLeDevice(false);// will stop after first device detection
}
--------
private final BluetoothGattCallback mainGattCallback = new BluetoothGattCallback()
{
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState)
{
switch (newState)
{
case BluetoothProfile.STATE_CONNECTED:
Log.e("action", "CONNECTED");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
gatt.discoverServices();
}
break;
case BluetoothProfile.STATE_DISCONNECTED:
Log.e("action", "DISCONNECTED");
break;
default:
Log.e("action", "STATE_OTHER");
}
}
public void onServicesDiscovered(BluetoothGatt gatt, int status)
{
}
public void onCharacteristicRead(BluetoothGatt gatt,
BluetoothGattCharacteristic
characteristic, int status)
{
}
};