BLE Peripheral Emulation is a technique used for testing Bluetooth Low Energy (BLE) devices without the need for a physical device. This technique allows developers to simulate a BLE peripheral device and test its functionality without the need for a physical device.
The process of BLE Peripheral Emulation involves using software to create a virtual BLE peripheral device that can connect to a BLE central device. This virtual device can then be used to test the functionality of the BLE central device, such as a mobile phone or tablet.
The benefits of using BLE Peripheral Emulation for testing include cost savings, as it eliminates the need for physical devices, and time savings, as it allows for faster testing and development cycles. Additionally, BLE Peripheral Emulation provides a controlled testing environment that can be used to test the performance of BLE devices under different conditions.
Initiating the development of a Bluetooth Low Energy (BLE) application is unfeasible while the IOT physical device remains in the process of being developed. Fortunately, there are several ways to emulate a BLE peripheral device for testing purposes. In this article, we will compare three popular methods: using the nRF Connect app, using the CoreBluetoothMock library, and creating a separate iOS application as a Bluetooth peripheral using the CoreBluetooth framework.
1. Via nRF Connect App GATT Server
The nRF Connect app, available for both Android and iOS, is a great tool for testing BLE applications. With it, you can create a GATT server and configure its characteristics. You can also import GATT server configurations from XML files. Setting up a GATT server using the nRF Connect app is very fast and can be done in a matter of minutes.
However, the downside is that the nRF Connect app cannot be programmed. Any written or saved characteristics are read as-is, so it may not be suitable for certain testing scenarios.
2. Using CoreBluetoothMock Library
The CoreBluetoothMock library, available on GitHub, is a mocking library for the CoreBluetooth framework. With it, you can create a mock peripheral device and simulate its behaviour. This method is much more flexible than the nRF Connect app, as you can program the peripheral device to behave in certain ways.
Setting up the CoreBluetoothMock library can be slow, taking several hours to write the code and configure the BLE central to mock. However, once it is set up, it can be used for both unit testing and UI testing on a simulator or real device.
3. Creating a Separate iOS Application as a Bluetooth Peripheral
The final method involves creating a separate iOS application that acts as a Bluetooth peripheral device. While this method is more time-consuming, taking several days to set up, it is the most flexible. You can program the peripheral device to behave in any way you want, and it can be used for both unit testing and UI testing on a real device.
To create a separate iOS application as a Bluetooth peripheral, you will need to use the CoreBluetooth framework. A guide on how to do this can be found in this Medium article.
When choosing a method to emulate a BLE peripheral device for testing, consider the flexibility and speed required for your specific testing needs. All three methods have their pros and cons, so choose the one that best fits your requirements.