• AVR Freaks

Hot!Connecting RN4871 to Android plone

Author
PIC4C code
Junior Member
  • Total Posts : 105
  • Reward points : 0
  • Joined: 2011/02/21 10:32:55
  • Location: 0
  • Status: offline
2019/04/22 11:52:33 (permalink)
0

Connecting RN4871 to Android plone

I will add info later is Microchip will let me post
#1

2 Replies Related Threads

    katela
    Super Member
    • Total Posts : 1259
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: Connecting RN4871 to Android plone 2019/04/22 14:16:33 (permalink)
    0
    Read this thread maybe your are posting something that is triggering the firewall: https://www.microchip.com/forums/m974835.aspx
     

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #2
    PIC4C code
    Junior Member
    • Total Posts : 105
    • Reward points : 0
    • Joined: 2011/02/21 10:32:55
    • Location: 0
    • Status: offline
    Re: Connecting RN4871 to Android plone 2019/04/22 14:32:23 (permalink)
    0
    I didn't first comments went out.  I apologize.
    I have an existing code on my android phone which I use to connect my RN42 module.  When I tried to use the code to connect my RN4871 it fails.  Code snippet:
     
    private void openBT() throws IOException {
    int oopp = 0; // used for debug
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if(mBluetoothAdapter == null)
    {
    myLabel.setText("No bluetooth adapter available");
    }
    if(!mBluetoothAdapter.isEnabled())
    {
    Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
    startActivityForResult(enableBluetooth, 0);
    }
    Intent intent = getIntent();
    myDevice = intent.getStringExtra("theDevice");
    myAddress = intent.getStringExtra("theAddress");
    String toName = myDevice;
    String toAddress = myAddress;
    Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
    int hop = 0; // used for debug
    if(pairedDevices.size() > 0)
    {
    for(BluetoothDevice device : pairedDevices)
    {
    if(toName.equals(device.getName())){
    // result = device;
    mmDevice = device;
    deviceUUID = UUID.randomUUID();

    int gth=0; // used for debug
    break;
    }
    } // end of for loop
    } // end of paired loop

    mmSocket = mmDevice.createRfcommSocketToServiceRecord(deviceUUID);
    BluetoothSocket tmp = null;
    try {
    tmp = mmDevice.createRfcommSocketToServiceRecord(deviceUUID);
    // for others devices its works with:
    // Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
    // for galaxy tab 2 with:
    final Method m = mmDevice.getClass().getMethod("createInsecureRfcommSocket",
    new Class[]{int.class});
    tmp = (BluetoothSocket) m.invoke(mmDevice, 1);
    } catch (IOException e) {
    } catch (NoSuchMethodException e) {
    // TODO Auto-generated catch block
    Toast.makeText(this, "1", Toast.LENGTH_SHORT).show();

    } catch (IllegalAccessException e) {
    // TODO Auto-generated catch block
    Toast.makeText(this, "2", Toast.LENGTH_SHORT).show();

    } catch (IllegalArgumentException e) {
    // TODO Auto-generated catch block
    Toast.makeText(this, "3", Toast.LENGTH_SHORT).show();

    } catch (final InvocationTargetException e) {
    // TODO Auto-generated catch block
    Toast.makeText(this, "4", Toast.LENGTH_SHORT).show();
    }
    mmSocket = tmp;//
    Toast.makeText(this, "5", Toast.LENGTH_SHORT).show();
    /***************  this is where it failed to connect ******************/
    //  Has the correct name, address, and not sure of the random UUID
    mmSocket.connect();
    myLabel.setText("Bluetooth Opened");
    } // end of openBT
    /******************************************************/
    // the RN42 has the same correct name and address and connects
    I'm missing something in the command structure of the RN4871.  I use Tera Term to command the BT modules.  Here is the module.
    BTA=BA1472CD3612
    Name=SECND_3612
    Connected=no
    Authen=2
    Features=0000
    Services=C0
     
    Thanks, Roger


    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5