Pair Android with Arduino (HC-05) without manually

2020-02-07 03:52发布

I'm sending some String data from android to arduino which is HC-05 .

Currently I can send data from android to hc-05 successfully (with or without pairing) and I've used this method to create socket

private BluetoothSocket createBluetoothSocket(BluetoothDevice device) throws IOException {

            try {
                final Method  m = device.getClass().getMethod("createInsecureRfcommSocketToServiceRecord", new Class[] { UUID.class });
                return (BluetoothSocket) m.invoke(device, MY_UUID);
            } catch (Exception e) {
                Log.e(TAG, "Could not create Insecure RFComm Connection",e);
            }

        return  device.createRfcommSocketToServiceRecord(MY_UUID);
    }

as you can see clearly . Its first trying to create InsecureRfcommSocket. Its using insecure connection to connect . AFAIK it may caused mitm attack , So I want to use secure communication which is createRfcommSocketToServiceRecord. but I also don't want user to enter pin at the time of pairing (secure comm socket won't be possible without pin exchange right? : correct me if i'm wrong). so

My Question is :

  1. How can I pair hc-05 without user interference in pin input ?(I've tried with intent filter and broadcast receiver but its not working(system always get first priority then my receiver))
  2. Is there any way to create secure comm Channel without pairing it ? cause i want only secure Channel and data exchange.
  3. If i want to enter pin programatically,Can I use device.setpin() or should i have to fire AT-Command for that?

0条回答
登录 后发表回答