-
Notifications
You must be signed in to change notification settings - Fork 865
noble.js with Visual Studio 2017 and Win7
This page is about how to get noble.js up and running with the following setup:
- Windows 7 x64
- Node.js 6.10.3 x86!
- Python 2.7.13 (both x86 and x64)
- Visual Studio 2017
- Make sure you install the following "Workloads":
- "Node.js development"
- "Python development"
Now, before we do anything else: I could not get the native components to work properly with the compiler that comes with VS2017. I could not figure out what the problem was, but it turned out that there is a better way:
For compiling the native parts we will have to do this once:
npm install -g windows-build-tools
That's it.
- Open VS2017
- Create a new project from template
It should look something like this:
Let's start from scratch and create a "Blank node.js Console Application" and run the app (a classic "Hello World" example) in order to see that everything works fine.
Now we can use the built-in npm gui called "Install New npm Packages":
- In the search field type "noble"
- select
noble 1.8.1
- install package
Now npm will start doing it's magic which includes compiling native code from a generated vsproject.
I has to compile these two modules
- bluetooth-hci-socket
- usb
IF everything went fine, it should look like this:
Registry url: https://registry.npmjs.org/
Current Time: 18.06.2017 17:27:32
Last Refreshed: 03.06.2017 10:43:49
Number of Results: 503067
====Executing command 'npm install noble --save '====
> usb@1.2.0 install C:\dev\NodejsConsoleApp1\NodejsConsoleApp1\node_modules\usb
> node-pre-gyp install --fallback-to-build
[usb] Success: "C:\dev\NodejsConsoleApp1\NodejsConsoleApp1\node_modules\usb\src\binding\usb_bindings.node" is installed via remote
> bluetooth-hci-socket@0.5.1 install C:\dev\NodejsConsoleApp1\NodejsConsoleApp1\node_modules\bluetooth-hci-socket
> node-gyp rebuild
C:\dev\NodejsConsoleApp1\NodejsConsoleApp1\node_modules\bluetooth-hci-socket>if not defined npm_config_node_gyp (node "C:\Program Files (x86)\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
win_delay_load_hook.cc
Generating code
Finished generating code
binding.vcxproj -> C:\dev\NodejsConsoleApp1\NodejsConsoleApp1\node_modules\bluetooth-hci-socket\build\Release\\binding.node
binding.vcxproj -> C:\dev\NodejsConsoleApp1\NodejsConsoleApp1\node_modules\bluetooth-hci-socket\build\Release\binding.pdb (Full PDB)
nodejs-console-app1@0.0.0 C:\dev\NodejsConsoleApp1\NodejsConsoleApp1
`-- noble@1.8.1
+-- bluetooth-hci-socket@0.5.1
| +-- nan@2.6.2
| `-- usb@1.2.0
| `-- node-pre-gyp@0.6.30
[*snip*]
| | +-- process-nextick-args@1.0.7
| | +-- string_decoder@0.10.31
| | `-- util-deprecate@1.0.2
| `-- uid-number@0.0.6
+-- bplist-parser@0.0.6
`-- debug@2.2.0
`-- ms@0.7.1
====npm command completed with exit code 0====
And you will have some warnings mixed in:
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: xpc-connection@~0.1.4 (node_modules\noble\node_modules\xpc-connection):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for xpc-connection@0.1.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"ia32"})
npm WARN nodejs-console-app1@0.0.0 No repository field.
npm WARN nodejs-console-app1@0.0.0 No license field.
That's fine.
If there is a problem, it will most likely be the compiler and gyp will complain, that it couldn't find a VSBuild.exe to do it's job.
paste code into app.js
const noble = require('noble');
noble.on('stateChange',
function (state) {
if (state === 'poweredOn') {
console.log('startScanning')
noble.startScanning();
} else {
console.log('stopScanning')
noble.stopScanning();
}
});
noble.on('discover',
function (peripheral) {
peripheral.on('disconnect', function () {
console.log('disonnected from peripheral: ' + peripheral.uuid)
});
peripheral.connect(function (error) {
console.log('connected to peripheral: ' + peripheral.uuid);
});
});
Click Start.