问题
I am trying to implement a communication between a BLE112 board and a BLE112 Smart Dongle by BlueGiga.
These two support AT command set.
I have managed to perform pairing between these two over the BLEGUI tool as shown in the screenshot below.
For the Read operations the console shows following:
ble_cmd_attclient_read_by_handle connection: 0 chrhandle: 3
TX: 00030404000300
ble_rsp_attclient_read_by_handle connection: 0 result: 0 ['No Error']
RX: 00030404000000
ble_evt_attclient_attribute_value connection: 0 atthandle: 3 type: 0 value:426c75656769676120554152542044656d6f
RX: 801704050003000012426c75656769676120554152542044656d6f
The lines above means that the Client (BLED112 USB Dongle) is able to read the 3rd attrbute value stored in Server(BLE112 board). This value was right there in it ever since I received it.
Now below part shows that I tried to read the 7th attribute, which was not present on the device, but I intend to create. Since the followinf read command was written directly by me onto the console of BLEGUI, it appears in a different way than what would it look had that been sent through the buttons present on BLEGUI.
ble_cmd_attclient_read_by_handle 0 7
TX: 00030404000700
ble_rsp_attclient_read_by_handle connection: 0 result: 0 ['No Error']
RX: 00030404000700
ble_evt_attclient_procedure_completed connection: 0 result: 401 ['The attribute handle given was not valid on this server']chrhandle: 7
RX: 800504010001040700
I have the following questions:
- Can I create new(user defined) attributes onto the device?
- Can I write/change the existing attributes on the device?
- If I intend to store any data onto the device, how can this be done?
回答1:
Yes, you can create and upload your own firmware to the BLE112 board, with services and characteristics defined by you. A good guide through the process is Bluegiga's Application Note "Developing your 1st Bluetooth Smart Application" which can be found here: BLE112 Documentation and Software
With regards to storing data, the BLE112 has a persistent store where you can store (key, value) pairs. Have a look at the "Bluetooth Smart Software API Reference" document about details on how to access it. This document can also be found under the above link.
回答2:
For anyone looking at this question later, I'll try to embed some example code.
Can I create new(user defined) attributes onto the device?
Can I write/change the existing attributes on the device?
@stathisv put the links for the Bluegiga documentation, but here are some practical examples: https://github.com/sureshjoshi/ble113-firmware-examples
You need to edit the gatt.xml, define a service (or use existing) and define a characteristic. For example:
<service uuid="aaa51666-e7cb-469b-8e4d-2742f1ba7aaa" advertise="true">
<characteristic uuid="0dddd780-b042-4876-aae1-112855353ddd" id="xgatt_who">
<description>Who Am I</description>
<properties read="true" notify="true" />
<value length="1" />
</characteristic>
</service>
If I intend to store any data onto the device, how can this be done?
I've written a compilable example here: https://github.com/sureshjoshi/ble113-firmware-examples/tree/master/Persistence, but the basics are as simple as two API commands:
# Write value to PS-store
call flash_ps_save($8000, 2, value_data(0:2))
# Read value from PS-store
call flash_ps_load($8000)(read_result, len, data(0:2))
The only real trick is the $8000 which is the first usable (persistent) memory address according the Bluegiga documentation.
Please note, that if you overwrite the BLE112/BLE113 firmware, either using the CC-Debugger or OTA programming, you wipe out all of your persistent flash information.
来源:https://stackoverflow.com/questions/21883950/read-write-error-in-bgapi-for-ble112-modules-by-bluegiga