• Stars
    star
    224
  • Rank 177,792 (Top 4 %)
  • Language
    Swift
  • License
    BSD 3-Clause "New...
  • Created over 4 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Mocking library for CoreBluetooth framework.

Core Bluetooth Mock

Version number Platform Carthage compatible

The Core Bluetooth Mock library was designed to emulate Core Bluetooth objects, providing easy way to test Bluetooth-enabled apps. As the native Bluetooth API is not supported on a simulator, using this library you can run, test and take screenshots of such apps without the need of a physical phone or tablet. You may also start working on the iOS app when your peripheral is still under development.

Core Bluetooth?

The Core Bluetooth framework provides the classes needed for your apps to communicate with Bluetooth-equipped low energy (LE) wireless technology. It requires an iPhone or iPad to work making Bluetooth-enabled apps difficult to test. As the documentation states:

Don’t subclass any of the classes of the Core Bluetooth framework. Overriding these classes isn’t supported and results in undefined behavior.

Core Bluetooth Mock!

The Core Bluetooth Mock library defines number of CBM... classes and constants, that wrap or imitate the corresponding CB... counterparts from Core Bluetooth framework. For example, CBMCentralManager has the same API and behavior as CBCentralManager, etc. On physical iDevices all calls to CBMCentralManager and CBMPeripheral are forwarded to their native equivalents, but on a simulator a user defined mock implementation is used.

How to start

The Core Bluetooth Mock library is available only in Swift, and compatible with iOS 11.0+1, macOS 10.13+, tvOS 11.0+1 and watchOS 4.0+, with some features available only on newer platforms. For projects running Objective-C we recommend https://github.com/Rightpoint/RZBluetooth library.

Including the library

The library support CocoaPods, Carthage and Swift Package Manager.

CocoaPods

  • Create/Update your Podfile with the following contents

    target 'YourAppTargetName' do
        pod 'CoreBluetoothMock'
    end
  • Install dependencies

    pod install
  • Open the newly created .xcworkspace

Carthage

  • Create a new Cartfile in your project's root with the following contents

    github "https://github.com/NordicSemiconductor/IOS-CoreBluetooth-Mock" ~> x.y // Replace x.y with your required version
    
  • Build with carthage

    carthage update --platform iOS // also supported are tvOS, watchOS and macOS
  • Copy the CoreBluetoothMock.framework from Carthage/Build to your project and follow instructions from Carthage.

Swift Package Manager

The library can also be included as SPM package. Simply add it in Xcode: File -> Swift Packages -> Add package dependency, type https://github.com/NordicSemiconductor/IOS-CoreBluetooth-Mock.git and set required version, branch or commit.

If you have Swift.package file, include the following dependency:

dependencies: [
    // [...]
    .package(name: "CoreBluetoothMock", 
             url: "https://github.com/NordicSemiconductor/IOS-CoreBluetooth-Mock.git", 
             .upToNextMajor(from: "x.y")) // Replace x.y with your required version
]

and add it to your target:

targets: [
    // [...]
    .target(
        name: "<Your target name>",
        dependencies: ["CoreBluetoothMock"]),
]

Documentation

The documentation of the library is available here.

Migration from CoreBluetooth

Migration example is available here. See Pull Request #1 for step-by-step guide.

Note

The migration example application currently does not use mocks in tests. For that, check out the Example folder in this repository with nRF Blinky app, which is using mock peripherals in Unit Tests and UI Tests. See below.

Sample application: nRF Blinky

nRF Blinky is an example app targeted towards newcomer BLE developers, and also demonstrating the use of Core Bluetooth Mock library. This application controls an LED on an nRF5DK and receive notifications whenever the button on the kit is pressed and released.

The mock implementation is used in Unit tests and UI tests. See AppDelegate.swift where the mock environment is set up and and UITests.swift and UITests.swift classes.

The mock peripherals are defined in MockPeripherals.swift.

Nordic LED and Button Service

A simplified proprietary service by Nordic Semiconductor, containing two characteristics one to control LED3 and Button1:

  • Service UUID: 00001523-1212-EFDE-1523-785FEABCD123

    • First characteristic controls the LED state (On/Off).
      • UUID: 00001525-1212-EFDE-1523-785FEABCD123
      • Value: 1 => LED On
      • Value: 0 => LED Off
    • Second characteristic notifies central of the button state on change (Pressed/Released).
      • UUID: 00001524-1212-EFDE-1523-785FEABCD123
      • Value: 1 => Button Pressed
      • Value: 0 => Button Released

    For full specification, check out documentation.

Requirements:

  • An iOS device with BLE capabilities, or a simulator (to run the mock).
  • A Development Kit (unless testing mock).
  • The Blinky example firmware to flash on the Development Kit. For your convenience, we have bundled two firmwares in this project under the Firmwares directory.
  • To get the latest firmwares and check the source code, you may go directly to our Developers website and download the SDK version you need, then you can find the source code and hex files to the blinky demo in the directory /examples/ble_peripheral/ble_app_blinky/
  • The LBS (LED Button Service) is also supported in nRF Connect SDK: here.
  • More information about the nRFBlinky example firmware can be found in the documentation.

Installation and usage:

  • Prepare your Development kit.

    • Plug in the Development Kit to your computer via USB.
    • Power On the Development Kit.
    • The Development Kit will now appear as a Mass storage device.
    • Drag (or copy/paste) the appropriate HEX file onto that new device.
    • The Development Kit LEDs will flash and it will disconnect and reconnect.
    • The Development Kit is now ready and flashed with the nRFBlinky example firmware.
  • Start Xcode and run build the project against your target iOS Device (Note: BLE is not available in the iOS simulator, so the iOS device is a requirement to test with real hardware).

    • Launch the nRF Blinky app on your iOS device.
    • The app will start scanning for nearby peripherals.
    • Select the Nordic_Blinky peripheral that appears on screen (Note: if the peripheral does not show up, ensure that it's powered on and functional).
    • Your iOS device will now connect to the peripheral and state is displayed on the screen.
    • Changing the value of the Toggle switch will turn LED 3 on or off.
    • Pressing Button 1 on the Development Kit will show the button state as Pressed on the app.
    • Releasing Button 1 will show the state as Released on the App.

Footnotes

  1. Xcode 14 dropped support for iOS 9.0 and tvOS 9.0 in simulator. Now the minimum supported version is 11.0 for both platforms. 2

More Repositories

1

Android-BLE-Library

A library that makes working with Bluetooth LE on Android a pleasure. Seriously.
Java
1,982
star
2

Android-nRF-Connect

Documentation and issue tracker for nRF Connect for Android.
1,299
star
3

Android-nRF-Toolbox

The nRF Toolbox is a container app that stores your Nordic Semiconductor apps for Bluetooth Low Energy in one location.
Kotlin
1,077
star
4

Android-DFU-Library

Device Firmware Update library and Android app
Java
760
star
5

Android-Scanner-Compat-Library

A compat library for Bluetooth Low Energy scanning on Android.
Java
755
star
6

IOS-nRF-Toolbox

The nRF Toolbox is a container app that stores your Nordic Semiconductor apps for Bluetooth Low Energy in one location.
Swift
600
star
7

IOS-DFU-Library

OTA DFU Library for Mac and iOS, compatible with nRF5x SoCs
Swift
517
star
8

nRF-Logger-API

The public library with nRF Logger API. Allows to log custom logs into the nRF Logger database.
Java
413
star
9

Android-nRF-Mesh-Library

The Bluetooth Mesh Provisioner and Configurator library.
Java
404
star
10

pc-nrfutil

nrfutil python library and command line client
Python
383
star
11

bluetooth-numbers-database

An up-to-date listing of all the various Bluetooth Specification-related elements that are defined by our industry (Company IDs, Service UUIDs, Characteristic UUIDs and Descriptor UUIDs), that you can use instead of rolling your own.
JavaScript
323
star
12

IOS-nRF-Mesh-Library

Provision, configure and control Bluetooth mesh devices with nRF Mesh library.
Swift
310
star
13

Kotlin-BLE-Library

Kotlin
300
star
14

pc-ble-driver

Desktop library for Bluetooth low energy development
C
281
star
15

Android-nRF-Blinky

nRF Blinky is an application developed targeting an audience of developers who are new to Bluetooth Low Energy
Kotlin
266
star
16

nrfx

Standalone drivers for peripherals present in Nordic SoCs
C
254
star
17

ble-sdk-arduino

C++
249
star
18

nRF-Sniffer-for-802.15.4

nRF-based 802.15.4 sniffer (firmware and software)
Python
227
star
19

Nordic-Thingy52-FW

Nordic Thingy:52 software development kit. This kit is designed to assist users in developing their own custom firmware for Thingy. Please see http://www.nordicsemi.com/thingy for the latest news and software releases.
C
210
star
20

pc-nrfconnect-launcher

nRF Connect for Desktop application and framework
TypeScript
172
star
21

pc-nrfconnect-ble

Bluetooth low energy app for nRF Connect for Desktop
TypeScript
150
star
22

nRF5-SDK-for-Mesh

This repo is a "Release" clone of the zip files available @
C
145
star
23

IOS-nRF-Connect

Info page
136
star
24

pc-ble-driver-py

Python bindings for the ble-driver library
Python
126
star
25

zcbor

Low footprint C/C++ CBOR library and Python tool providing code generation from CDDL descriptions.
C
114
star
26

Android-Nordic-Thingy

Android SDK and sample application for Nordic Thingy:52
Java
107
star
27

Android-nRF-Beacon

The nRF Beacon application lets you explore the full range of possibilities for beacons using Bluetooth Smart technology. The application has been designed to demonstrate all features of the nRF8122 Bluetooth® Smart Beacon Kit.
Java
106
star
28

pc-nrfconnect-ppk

Power Profiler app for nRF Connect for Desktop
TypeScript
103
star
29

IOS-nRF-Connect-Device-Manager

A mobile management library for devices supporting nRF Connect Device Manager.
Swift
88
star
30

Android-nRF-Connect-Device-Manager

A mobile management library for devices running Apache Mynewt and Zephyr (DFU, logs, stats, config, etc.)
Java
81
star
31

pc-ble-driver-js

Node.js interface to the C/C++ pc-ble-driver library. API docs: https://nordicsemiconductor.github.io/pc-ble-driver-js/
JavaScript
79
star
32

pynrfjprog

Python wrapper around the nrfjprog dynamic link library (DLL)
C
75
star
33

pc-nrfconnect-programmer

Programmer app for nRF Connect for Desktop
TypeScript
66
star
34

IOS-Nordic-Thingy

iOS Library and example application for Thingy:52™
Swift
65
star
35

IOS-BLE-Library

The Bluetooth LE library for iOS and Mac. 100% Swift.
Swift
62
star
36

Android-BLE-Common-Library

A companion library for the Android BLE Library. Contains parsers for common Bluetooth SIG characteristics.
Java
55
star
37

Android-nRF-Beacon-for-Eddystone

An application with Eddystone GATT Configuration Service & Google Nearby API and Proximity API.
Java
48
star
38

iOS-nRF-Blinky

A starter app for new developers in the BLE world!
Swift
44
star
39

nrf-udev

Linux udev rules for Nordic Semiconductor devices.
Shell
37
star
40

pc-nrfconnect-rssi

RSSI Viewer app for nRF Connect for Desktop
C
37
star
41

Flutter-nRF-Connect-Device-Manager

A Flutter plugin for McuMgr libraries for Android and iOS.
Dart
36
star
42

Android-nRF-Bluetooth-LE-Joiner

nRF BLE Joiner is an application that lets you add new IoT nodes to a network based on Bluetooth Smart.
Java
35
star
43

Linux-ble-6lowpan-joiner

C
35
star
44

pc-nrfjprog-js

Node.js library that exposes the functionality of the nRF Command Line Tools
C++
28
star
45

nrf-intel-hex

Yet another parser for "Intel HEX" files.
JavaScript
27
star
46

pc-nrfconnect-toolchain-manager

Install and manage tools to develop with the nRF Connect SDK (NCS)
TypeScript
24
star
47

pc-nrfconnect-shared

Dependency management for nRF Connect for Desktop packages
TypeScript
21
star
48

asset-tracker-cloud-firmware-aws

nRF Asset Tracker for AWS firmware.
C
18
star
49

pc-nrf-dfu-js

Javascript implementation of Nordic's DFU protocol over serial (or NoBLE).
JavaScript
17
star
50

nrf-device-setup-js

JavaScript
15
star
51

nRF-IEEE-802.15.4-radio-driver

A generic, stack independent and system independent IEEE 802.15.4 radio driver, intended for nRF SoCs with IEEE 802.15.4 radio. It contains a built-in support for multiprotocol, allowing for concurrent operation of IEEE 802.15.4-based stacks (e.g. Thread, ZigBee) with Bluetooth LE
13
star
52

pc-nrfconnect-linkmonitor

LTE Link Monitor app for nRF Connect for Desktop
JavaScript
13
star
53

pc-nrfconnect-gettingstarted

nRF Connect Getting Started Assistant is a tool to guide through the process of setting up the nRF Connect SDK toolchain
SCSS
12
star
54

asset-tracker-cloud-aws-js

A reference implementation of a serverless backend for an IoT product developed using AWS CDK in TypeScript.
TypeScript
12
star
55

asset-tracker-cloud-docs

The nRF Asset Tracker aims to provide a concrete end-to-end example for an IoT product in the asset tracker space.
CSS
10
star
56

pc-nrfconnect-dtm

C
10
star
57

IOS-Memfault-Library

nRF Memfault Library + Example App
Swift
8
star
58

pc-nrfconnect-boilerplate

Starting point for creating apps for nRF Connect for Desktop
TypeScript
8
star
59

Android-nRF-Wi-Fi-Provisioner

An Android library and app for provisioning Nordic Wi-Fi devices to a network.
Kotlin
8
star
60

KMM-BLE-Library

Kotlin
8
star
61

nRF52-Bluetooth-Course

7
star
62

IOS-nRF-Edge-Impulse

Connect to a Thing:53, collect sensor data over Bluetooth Low Energy and create your machine learning applications.
Swift
6
star
63

Android-Memfault-Library

An Android library for sending heap dumps to the Memfault cloud.
Kotlin
6
star
64

pc-nrfconnect-cellularmonitor

TypeScript
5
star
65

modemtalk

[end-of-life] library to interface with the nRF9160 modem
JavaScript
5
star
66

Android-Gradle-Plugins

Kotlin
5
star
67

pc-nrfconnect-docs

Developer documentation for nRF Connect for Desktop. Read them at https://NordicSemiconductor.github.io/pc-nrfconnect-docs/
HTML
5
star
68

IOS-nRF-Wi-Fi-Provisioner

A Swift library and app for provisioning Nordic Wi-Fi devices to a network.
Swift
5
star
69

pc-nrfconnect-serial-terminal

Terminal emulator for serial port connections
TypeScript
5
star
70

asset-tracker-cloud-app-js

The nRF Asset Tracker Web Application is a reference single-page application (SPA) developed using create-react-app in TypeScript.
TypeScript
5
star
71

piccata

Python CoAp Toolkit
Python
4
star
72

npmx-zephyr

npmx integration with Zephyr
C
4
star
73

pc-nrfconnect-tracecollector

Trace collector tool for nRF Connect for Desktop
JavaScript
4
star
74

microbit-v2-pager

C
4
star
75

cell-geolocation-helpers-js

Helper functions for the cell geolocation feature
TypeScript
4
star
76

nrf-device-lister-js

List usb, serialport and jlink devices
JavaScript
4
star
77

svada

SVD Parsing for Python
Python
3
star
78

asset-tracker-cloud-device-ui-js

Provides a user interface via a web application to interact with a simulated device for the nRF Asset Tracker.
TypeScript
3
star
79

cloud-azure-firmware-ci-runner-js

Runs firmware on a real device connected to Azure IoT hub.
TypeScript
3
star
80

at_host-hex

Compiles the AT host sample for 9161DK, 9160DK, and Thingy:91 and publishes it regularly.
3
star
81

cloud-aws-package-layered-lambdas-js

Packages lambda functions and layers for AWS lambda
TypeScript
3
star
82

NAT-TestServer

Receives NAT test messages from the NAT-TestFirmware and logs them and timeout occurances to S3
TypeScript
3
star
83

asset-tracker-cloud-firmware-azure

nRF Asset Tracker for Azure firmware.
C
3
star
84

Android-nRF-Edge-Impulse

Connect to a Thing:53, collect sensor data over Bluetooth Low Energy and create your machine learning applications.
Kotlin
3
star
85

nrfprogrammer-firmware-images

Provides a list of pre-compiled firmware images for nRF Programmer in the GitHub pages website for this repository.
TypeScript
3
star
86

npmx

Standalone drivers for Nordic PMICs
C
3
star
87

NFC-Connect

Kotlin
2
star
88

pmic-npm6001-lib

C
2
star
89

cloud-e2e-bdd-test-runner-js

Implementation of a test-runner for end-to-end tests of cloud-native applications using Gherkin features.
TypeScript
2
star
90

IOS-CoreBluetooth-Mock-Example

Sample app demonstrating migration to CoreBluetoothMock framework.
Swift
2
star
91

pc-nrfconnect-npm

TypeScript
2
star
92

cloud-device-helpers-js

Helper functions for interacting with the nRF9160 used during end-to-end tests
TypeScript
2
star
93

asset-tracker-cloud-code-style-js

Code style definitions for all nRF Asset Tracker projects.
JavaScript
1
star
94

asset-tracker-cloud-app-aws-js

The nRF Asset Tracker Web Application for AWS is a reference single-page application (SPA) developed using TypeScript.
TypeScript
1
star
95

nrfcloud-location-services-tests-js

Verifies the nRF Cloud Location Services REST API.
TypeScript
1
star
96

cloud-azure-firmware-ci-feature-runner-action

Uses @nordicsemiconductor/e2e-bdd-test-runner to run features files of a firmware.
JavaScript
1
star
97

cloud-e2e-bdd-test-runner-example-js

Example use of @nordicsemiconductor/e2e-bdd-test-runner
TypeScript
1
star
98

cloud-aws-firmware-ci-feature-runner-action

Uses @nordicsemiconductor/e2e-bdd-test-runner to run features files of a firmware.
JavaScript
1
star
99

lwm2m-types-js

TypeScript type definitions and JSON schema for the objects defined in the LwM2M Object Registry.
TypeScript
1
star
100

asset-tracker-cloud-memfault-azure-js

Memfault integration for Azure IoT Hub developed in TypeScript.
TypeScript
1
star