Skip to content
This repository was archived by the owner on Apr 9, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@
"strict": "off",
"no-console": "off",
"no-restricted-syntax": "off",
"no-undef": 1,
"no-unused-vars": 1,
"valid-jsdoc": [2, {
"prefer": {
"return": "returns"
}
}]
},
"no-undef": 1,
"no-unused-vars": 1,
"plugins": [
"react"
],
"env": {
"es6": true,
"jest": true
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ package-lock.json
build
jest.json
docs
/pc-ble-driver
4 changes: 0 additions & 4 deletions .gitmodules

This file was deleted.

76 changes: 50 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
cmake_minimum_required(VERSION 3.3)
cmake_minimum_required(VERSION 3.13)

if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
endif()

# Name of the project (will be the name of the plugin)
project (pc-ble-driver-js)
Expand All @@ -7,19 +12,18 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# All projects depending on pc-ble-driver need to include this first
include(pc-ble-driver/cmake/pc-ble-driver.cmake)
add_subdirectory(pc-ble-driver)
find_package(nrf-ble-driver 4.1.0 REQUIRED)

set(UECC_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/uECC)
# Essential include files to build a node addon,
# you should add this line in every CMake.js based project.
if (NOT DEFINED CMAKE_JS_INC OR NOT DEFINED CMAKE_JS_LIB)
message (
FATAL_ERROR
"-DCMAKE_JS_INC and -DCMAKE_JS_LIB must be provided. "
"Run `npm install` to build this project instead of "
"running cmake directly."
)
endif ()

include_directories(${CMAKE_JS_INC} ${PC_BLE_DRIVER_INCLUDE_DIR} ${UECC_INCLUDE_DIR})
include_directories(${PC_BLE_DRIVER_INCLUDE_DIR}/common)
include_directories(${PC_BLE_DRIVER_INCLUDE_DIR}/common/sdk_compat)
include_directories(${PC_BLE_DRIVER_INCLUDE_DIR}/common/internal)
include_directories(${PC_BLE_DRIVER_INCLUDE_DIR}/common/internal/transport)
set(UECC_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/uECC)

file (GLOB SOURCE_FILES
"src/adapter.cpp"
Expand All @@ -41,8 +45,6 @@ if(WIN32)
)
endif()



file (GLOB UECC_SOURCE_FILES
"src/uECC/*.c"
)
Expand All @@ -69,11 +71,18 @@ else()
include(${CMAKE_CURRENT_LIST_DIR}/cmake/gcc.cmake)
endif()

foreach(SD_API_VER ${SD_API_VERS})
string(TOLOWER ${SD_API_VER} SD_API_VER_L)
set(CURRENT_TARGET pc-ble-driver-js-${SD_API_VER_L})
# There are several nrf-ble-driver libraies corresponding to SoftDevices. They
# expose a common API with some difference in features available. For now, we
# statially link to each one we need be creating several libraries, and select
# which resulting functions to use in JS code. We need more than one because
# nRF51 devices are not supported by SoftDevices v3 and above, but we need later
# SoftDevices for features for nRF52.
#
# Compile a node library with SD API v2 for nRF51, and one with v3 for nRF52.
foreach(SD_API_VER "2" "3")
Comment thread
alwa-nordic marked this conversation as resolved.
set(CURRENT_TARGET pc-ble-driver-js-sd_api_v${SD_API_VER})

add_library(${CURRENT_TARGET} SHARED ${SOURCE_FILES} ${UECC_SOURCE_FILES} ${LIB_PLATFORM_SRC_FILES} ${PLATFORM_SOURCE_FILES})
add_library(${CURRENT_TARGET} SHARED ${SOURCE_FILES} ${UECC_SOURCE_FILES} ${PLATFORM_SOURCE_FILES})

# This line will give our library file a .node extension without any "lib" prefix
set_target_properties(${CURRENT_TARGET}
Expand All @@ -82,10 +91,9 @@ foreach(SD_API_VER ${SD_API_VERS})
PREFIX ""
SUFFIX ".node")

string(REGEX MATCH "[0-9]+$" _SD_API_VER_NUM "${SD_API_VER}")
set_target_properties(${CURRENT_TARGET} PROPERTIES COMPILE_OPTIONS -DNRF_SD_BLE_API_VERSION=${_SD_API_VER_NUM})
set_target_properties(${CURRENT_TARGET} PROPERTIES COMPILE_OPTIONS -DNRF_SD_BLE_API_VERSION=${SD_API_VER})

target_include_directories(${CURRENT_TARGET} PRIVATE ${PC_BLE_DRIVER_${SD_API_VER}_PUBLIC_INCLUDE_DIRS})
target_include_directories(${CURRENT_TARGET} PRIVATE ${CMAKE_JS_INC} ${UECC_INCLUDE_DIR})

if(WIN32)
# suppress C4251 v8/msvc related warning, for more info: https://github.com/nodejs/node/pull/15570
Expand All @@ -95,14 +103,30 @@ foreach(SD_API_VER ${SD_API_VERS})
set_target_properties(${CURRENT_TARGET} PROPERTIES COMPILE_DEFINITIONS "_CRT_SECURE_NO_WARNINGS")
set_target_properties(${CURRENT_TARGET} PROPERTIES LINK_FLAGS "/DELAYLOAD:node.exe" )
elseif(APPLE)
target_link_libraries(${CURRENT_TARGET} "-framework CoreFoundation")
target_link_libraries(${CURRENT_TARGET} "-framework IOKit")
target_link_libraries(${CURRENT_TARGET} PRIVATE "-framework CoreFoundation")
target_link_libraries(${CURRENT_TARGET} PRIVATE "-framework IOKit")
set_property(TARGET ${CURRENT_TARGET} PROPERTY MACOSX_RPATH ON)
else()
# Assume Linux
target_link_libraries(${CURRENT_TARGET} "udev")
target_link_libraries(${CURRENT_TARGET} PRIVATE "udev")
endif()

# actual shared and static libraries built from the same object files
target_link_libraries(${CURRENT_TARGET} ${CMAKE_JS_LIB} ${PC_BLE_DRIVER_${SD_API_VER}_STATIC_LIB})
target_link_libraries(${CURRENT_TARGET} PRIVATE ${CMAKE_JS_LIB} nrf::nrf_ble_driver_sd_api_v${SD_API_VER}_static)

get_target_property(ble_driver_if_dir nrf::nrf_ble_driver_sd_api_v${SD_API_VER}_static INTERFACE_INCLUDE_DIRECTORIES)
set(CONNECTIVITY_SD_API_V${SD_API_VER}_PATH "${ble_driver_if_dir}/../../share/nrf-ble-driver/hex/sd_api_v${SD_API_VER}/*.hex" CACHE FILEPATH "Path with wildcards to connectivity firmware files")
file(GLOB_RECURSE connectivity_firmware ${CONNECTIVITY_SD_API_V${SD_API_VER}_PATH})

set_property(
TARGET ${CURRENT_TARGET}
PROPERTY RESOURCE ${connectivity_firmware}
)

set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR})
install(
TARGETS ${CURRENT_TARGET}
RUNTIME DESTINATION "build/Release/"
LIBRARY DESTINATION "build/Release/"
RESOURCE DESTINATION "pc-ble-driver/hex/"
)
endforeach(SD_API_VER)
72 changes: 0 additions & 72 deletions Installation.md

This file was deleted.

38 changes: 32 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
# pc-ble-driver-js

pc-ble-driver-js provides a Node.js interface to the [pc-ble-driver](https://github.com/NordicSemiconductor/pc-ble-driver) C/C++ library.
High-level Node.js API for Bluetooth Low Energy (BLE) using nRF51 and nRF52 hardware.

## Usage
See the [examples](examples) folder.

## Overview

The pc-ble-driver-js library allows an nRF5 connectivity chip running Nordic Semiconductor's SoftDevice to be controlled by a Node.js application. The communication with the connectivity chip happens over serial port using [BLE Serialization](https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v12.0.0%2Flib_serialization.html). The pc-ble-driver-js library is higher-level than pc-ble-driver and leans towards 'convention over configuration'. This module may be useful for tasks ranging from automated BLE testing to [desktop applications](https://www.nordicsemi.com/eng/Products/Bluetooth-low-energy/nRF-Connect-for-desktop) and BLE gateways.

## Installation

To install pc-ble-driver-js for use in a Node.js project, simply:

$ npm install pc-ble-driver-js

This will work as long as precompiled binaries exist for your platform/runtime environment, ref. the files attached to the [Releases](https://github.com/NordicSemiconductor/pc-ble-driver-js/releases). If not, then it will attempt to build the binaries from source, which requires some additional setup as described in [Installation.md](./Installation.md).
The install script will try to download precompiled binaries for your platform/runtime environment from our [Releases](https://github.com/NordicSemiconductor/pc-ble-driver-js/releases). If not available, it will attempt to build the binaries from source, which requires a C++ compiler and the pc-ble-driver library. See [Building](#building).

### Installing in Electron apps

If you want to use pc-ble-driver-js with the electron runtime, you must set the runtime to Electron in .npmrc in the root of your project. Then install pc-ble-driver-js again. Example .npmrc file content:

runtime = Electron
target = 1.16.6
disturl = https://atom.io/download/atom-shell

## Building

If there are no precompiled binaries for your platform, the install script will try to build them. You will need a working C++ compiler and the pc-ble-driver library available by cmake find_package.

The recommended way to get pc-ble-driver is using vcpkg. Clone the vcpkg repo, install nrf-ble-driver for the architecture of your node executable. Then set the environment variable `VCPKG_ROOT` to the full path of the vcpkg repository and it will get automatically picked up when doing `npm install`.

A full example of preparing building on Windows for 64-bit Node:

$ git clone https://github.com/NordicPlayground/vcpkg.git
$ ./vcpkg/bootstrap.bat
$ ./vcpkg/vcpkg install nrf-ble-driver:x64-windows

And then when installing:

$ set VCPKG_ROOT=/absolute/path/to/vcpkg/dir
$ npm install pc-ble-driver-js

## Hardware setup

Expand All @@ -23,9 +49,9 @@ A connectivity firmware needs to be flashed on the nRF5 IC before using pc-ble-d
The [examples](./examples) and [integration tests](./test) may be used as a starting point for development with pc-ble-driver-js. Examples include a [heart rate monitor](./examples/heart_rate_monitor.js) (BLE peripheral) and [heart rate collector](./examples/heart_rate_collector.js) (BLE master) and show the basic structure of an application built on pc-ble-driver-js. To run the heart rate monitor example, verify your nRF5 connectivity chip is set-up and connected to your PC and run:

$ node examples/heart_rate_monitor.js <PORT> <SD_API_VERSION>

To get more information about the command options you can run the command without any arguments.

## Architecture

All functionality of pc-ble-driver-js is exposed through its [api](./api/). Other directories in `pc-ble-driver-js/` are for building, binding to C/C++, and testing, and a developer building an application on top of pc-ble-driver-js need not concern themselves with these details.
Expand Down
Loading