I have recently started to learn developing a mircocontroller-based device which will have BLE module. The device is supposed to send analog reading fetched from sensor to an android application that I am going to develop.
For what i have studied about the way GATT works is:
- The microntroller-based device will be GATT server.
- The android application will be GATT client.
- As seen from communication point of view, the microntroller-based device is Slave and the android application is Master.
Questions:
- How do I decide the number of attributes that I need to define in order to receive command from GATT Client and send the response (which is going to be a float value)? Do I need to have two distinct attributes: One for Android to send commands and one for the microncontroller-based device to send data to android? Or I can use a single attribute?
- GATT appears to be an event-driven system.
2.1: What events will be generated when android sends a command to microcontroller-based device: (Client to Server) ?
2.2: Will an event be generated when the data is written on the attribute which is going to be read by Android application: (Server to Client) ? - The android application (GATT Client) should use read/write commands to communicate with the microncontroller-based device (GATT Server). And, the GATT Server should use Notify/Indicate to pass the data to the GATT Client. Is my understanding correct?
I am using this BlueGiga BLE112 Module for development.
The gatt.xml file that I so far have written is:
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<!-- 1800: org.bluetooth.service.generic_access -->
<service uuid="1800" id="generic_access">
<description>Generic Access</description>
<!-- 2A00: org.bluetooth.characteristic.gap.device_name -->
<characteristic uuid="2A00" id="c_device_name">
<description>Device Name</description>
<properties read="true" const="true" />
<value>MyBLEDev</value>
</characteristic>
<!-- 2A01: org.bluetooth.characteristic.gap.appearance -->
<characteristic uuid="2A01" id="c_appearance">
<description>Appearance</description>
<properties read="true" const="true" />
<value type="hex">0300</value>
</characteristic>
</service>
<!-- custom service -->
<service uuid="624e957f-cb42-4cd6-bacc-84aeb898f69b" advertise="true">
<description>Custom Device Service</description>
<!-- custom write-only characteristic for Client to send commands to fetch reading -->
<characteristic uuid="a57892fe-4f58-97d4-a5245-78a4125d3e6" id="c_cmd_TxReading">
<description>Request for Reading</description>
<properties write="true" />
<value length="4" />
</characteristic>
<characteristic uuid="8fde302a-56ac-b289-65ed-a577ed66b89c" id="c_reading">
<description>Measurement</description>
<properties read="true" write="true" />
<value length="4" type="float32" />
</characteristic>
</service>