Home | pfodApps/pfodDevices | WebStringTemplates | Java/J2EE | Unix | Torches | Superannuation | | About Us
 

Forward Logo (image)      

Bluetooth Low Energy BLE Problems
and How to Fix them

by Matthew Ford 15th November 2017 (originally posted 15th November 2017)
© Forward Computing and Control Pty. Ltd. NSW Australia
All rights reserved.

Bluetooth V4, Bluetooth V5 (BLE) Problems and Solutions
for General Purpose Control

Read This First – Do you really need BLE?

This tutorial covers some of the common problems, and their solutions, when using Bluetooth Low Energy devices (BLE) or Bluetooth V4, Bluetooth V5 modules. However “Do you really need to use BLE?”

If you just need some way to connect your Arduino project to your mobile or PC then a much better and easier solution is to use a Bluetooth Classic (Bluetooth V2) shield, like Itead Bluetooth Shield, OR a cheap WiFi shield like this project, Cheap/Simple Wifi Shield.

You should only consider using a BLE module if you need one of its unique features, such as very low power consumption, or you want to stay on the “bleeding edge” of technology. The Remote Controlled Light switch is an example of a project that needs to run of very low current <1.5mA so that is does not need an additional power supply.

Custom BLE – No Programming required provides details on more the half a dozen different BLE modules.

Problems with Bluetooth Low Energy

There are a number of problems with using BLE for general purpose control.

Older mobiles and computers do not support BLE

Bluetooth used to be easy to use, every Android and iPhone and most computers supported Bluetooth V2. The Bluetooth Serial Port Profile (SPP) was the standard way to get a general data connection via Bluetooth and all Arduino Bluetooth V2.0 shields supported it.

Note: not all Android mobiles support BLE. You can check if your mobile supports BLE with the free Nordic nRF Master Control Panel (BLE) android app . If your mobile does not support BLE, then pfodApp will not display the +BLE button in the add/edit connections screen.

The BLE mobile hardware is still being ironed out. On the Android side, BLE support was introduced in V4.2 but that version and V4.3 was very buggy. V4.4 improved the BLE support and later version should be better.

The only solution is to update your mobile phone or computer to a later one that supports BLE. Note: BLE V5 specification has been release so you may need to update again shortly to use is enhanced features, like Mesh support.

The Bluetooth SIG standard does not define a general purpose UART connection.

The biggest problem with trying to use BLE for general purpose control is that the SIG specification does NOT define a standard UART connection. Bluetooth V5 specification does not fix this problem. Where as Bluetooth V2 (Bluetooth Classic) defined Bluetooth Serial Port Profile (SPP) which was universal and easy to code, BLE does not define a replacement.

This has resulted in each manufacture having to define their own 'uart' service and your mobile app needs to know the details in order to use it.

One solution is to use a general purpose app, like pfodApp, which recognizes half a dozen or more common 'uart' services from various module manufactures. pfodApp has it own general purpose messaging system, pfod. The pfod messaging system is particularly suited for BLE because almost all the messages are very short (<20bytes)

Nordic Semiconductor has defined their own UART service, which pfodApp recognizes, and which a number of manufactures use. There are apps from Nordic Semiconductor to let to test its uart connection, Nordic nRF Master Control Panel (BLE) and nRF Toolbox for BLE However even for this 'standard' there is some confusion about the TX versus RX characteristic. pfodApp handles both alternatives.

Programming BLE control Apps is difficult.

Programming an Android or IOS app to make a BLE 'uart' connection is non-trivial. There are services and characteristics to be handled and messaging delays to be allowed for as well as the 20byte message limit of BLE V4.

The nRF Toolbox for BLE provides a simple 'uart' connection if and only if the module you are connecting to uses Nordic's uart (correctly). The Android pfodApp on the other hand provides a general purpose menu and graphical driven control platform for a variety of different modules. The menus and graphics displayed on pfodApp are completely controlled by the code in your Arduino or BLE module, no Android mobile coding is necessary to get functional controls.

Programming BLE devices is not straight forward.

Because of the lack of a BLE uart standard each module manufacture defines their own, or does not define any at all. This means there is no standard Arduino library for BLE. Some modules connect via Serial, some via SPI, some via direct library calls.

The free pfodDesigner app provides a solution to this by letting you design pfodApp menus and then generating the code for a variety of BLE modules. Even if you don't want to pfodApp, the generated code provides you with a template 'uart' connection for you own use.

Some BLE modules/software stacks deliver the same message twice is quick succession

While testing a number of BLE modules it was found that some occasionally deliver the same message from the mobile app, twice in quick succession. That is within about 100mS. Depending of how your code and commands are structure this can be a problem.

For example if you use the same command to toggle a switch on and off then you will find the switch stays OFF when you try to turn it on because the second delivery of the same command turns it off as soon as the real command has turned it on.

pfodApp V3.322+ overcomes this problem by adding a sequence number/letter to each command and and the pfodParser V3.17+ filters out any commands with duplicate sequence number/letter.

Some BLE modules/software stacks drop bytes when sending long messages.

BLE V4 messages are limited to 20bytes per message. BLE V5 allows longer messages but it is a recent specification and most of the software has not caught with it. Even if the module is advertised as being V5 it probably still uses the 20byte limit.

To send long messages via BLE they need to be broken down into 20byte chunks and sent separately. You would hope/expect that module's supporting library would handle this for you. However in a number of cases trying to send long messages requiring multiple chucks results in the end of the messages being dropped.

The pfodParser V3.15+ library provided as pfodBLEBufferedSerial class that you can insert between your prints and the BLE serial output to accept the full message and release it 20 bytes at a time very 200mS or so. This gives the BLE communication time to pass the message on to the mobile.

Conclusion

BLE offers some unique advantages, very low power consumption, if programmed correctly, and the promise of a local Mesh. However it is not without is problems. If you only need to communicate between your Arduino project and your mobile or PC you are better off using Bluetooth Classic V2 or WiFi (Itead Bluetooth Shield, OR Cheap/Simple Wifi Shield).

If you really need to use BLE, or you want to stay on the “bleeding edge” of technology, then pfodApp removes the need to code an Android app and the free pfodDesigner generates all the code you need for a variety of BLE modules to create general purpose menus on your mobile. While the pfodParser library and pfodBLEBufferedSerial over come double delivery of commands and loss of transmitted responses.

AndroidTM is a trademark of Google Inc. For use of the Arduino name see http://arduino.cc/en/Main/FAQ


The General Purpose Android/Arduino Control App.
pfodDevice™ and pfodApp™ are trade marks of Forward Computing and Control Pty. Ltd.




Forward home page link (image)

Contact Forward Computing and Control by
©Copyright 1996-2020 Forward Computing and Control Pty. Ltd. ACN 003 669 994