Using Microhip's MLDP data streaming from Android or iOS

Dan Christian picture Dan Christian · Jul 3, 2015 · Viewed 9.5k times · Source

Microchip defined a way to stream data over BlueTooth low energy (BLE) and called it MLDP (Microchip Low-energy Data Profile). They built it into their RN4020 chip, and there is even an sample Android app.

However, I can't find any specification of how the protocol works or source for the app. I'd like to be able to use it to debug an embedded device from Android and/or iOS.

Does anyone know the specification for this protocol or software that implements it?

Answer

Sebasu picture Sebasu · Sep 15, 2015

Hi i was in the same problem, but at this moment i have a working code with MLDP, first you need to go to the Module web page:

http://www.microchip.com/wwwproducts/Devices.aspx?product=RN4020

then, under Documentation & Software you can find:

  • Android Explorer 16 RN4020 PICtail Demo Code
  • MLDP Demo for Android
  • RN4020 Android App Demo

The first item is an example code for working with the module and MLDP from android, it uses Bluetooth GATT clases which was implemented from Android 4.3 (API 18)

The MLDP concept is like any other 'GATT Characteristic' of BTL, but it is send directly from the RF to the UART without microcontroller need to request the characteristic value

in the example code you will find two projects (one with service (android background component)), go to the 'RN4020 Die' project, import it to your workspace if you want, but under the src/package name/ folders, you will find the file 'DeviceControlActivity.java'

that file contains the main code for using de BluetoothDevice object you select and create the GATT connection with it, then you will see functions like write and read characteristic, checking and/or using parts of the code you will be able to begin using the module like SPP

some parts of my code for fast understanding and implementation:

mBluetoothGatt = mDevice.connectGatt(this, false, mGattCallback);//To connect to mDevice

mGattCallBack is the same like the microchip's sample code, but with the change of:

@Override
public void onCharacteristicChanged(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic) {
    String dataValue = characteristic.getStringValue(0);//get modified data
    RX.append(dataValue);//append it on my RX textview 
}

with that modification, you will receive an 'event' when characteristic changes, in this case, every time microcontroller send data

you can use the provided function 'writeCharacteristic' to send data, you can use it like this:

mDataMDLP.setValue("R=>" + TX.getText() + "\r\n");
writeCharacteristic(mDataMDLP);

Finally, the function 'findMldpGattService' is too important, it will compare the declared UUIDs of the MLDP protocol with the available on the device, then it will initialice the 'mDataMDLP' object, allowing you to use it

I hope my answer to be useful for you and someone else.