From 9a2ce4739b2dd1b7f84e05a054cbba283f6d29f6 Mon Sep 17 00:00:00 2001 From: johnnyman727 Date: Wed, 6 Jan 2016 22:28:42 -0800 Subject: [PATCH] Adds initial files for BLE start guide --- _layouts/default.html | 4 + modules.md | 1 + modules/_module_footer.html | 4 + modules/ble.html | 10 +++ modules/ble.md | 155 ++++++++++++++++++++++++++++++++++++ 5 files changed, 174 insertions(+) create mode 100644 modules/ble.html create mode 100644 modules/ble.md diff --git a/_layouts/default.html b/_layouts/default.html index 8005697..7bca900 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -123,6 +123,10 @@

ambient +
  • + ble +
  • climate diff --git a/modules.md b/modules.md index 18e9ba8..8690738 100644 --- a/modules.md +++ b/modules.md @@ -56,6 +56,7 @@ If you've already tried out your modules, move on to [Tweet.](tweet.html) * [Accelerometer](modules/accelerometer.html) * [Ambient (Light + Sound)](modules/ambient.html) +* [BLE](modules/ble.html) * [Climate](modules/climate.html) * [GPS](modules/gps.html) * [Infrared](modules/ir.html) diff --git a/modules/_module_footer.html b/modules/_module_footer.html index 9401574..322fb61 100644 --- a/modules/_module_footer.html +++ b/modules/_module_footer.html @@ -14,6 +14,10 @@

    Choose another module

    "moduleLink">Ambient Light + Sound
  • +
  • + BLE +
  • Climate diff --git a/modules/ble.html b/modules/ble.html new file mode 100644 index 0000000..b0b3f04 --- /dev/null +++ b/modules/ble.html @@ -0,0 +1,10 @@ +--- +layout: default +--- + +{% capture include_install %} +{% include_relative ble.md %} +{% endcapture %} +{{ include_install | markdownify }} + +{% include_relative _module_footer.html %} diff --git a/modules/ble.md b/modules/ble.md new file mode 100644 index 0000000..15a9c2a --- /dev/null +++ b/modules/ble.md @@ -0,0 +1,155 @@ +{::options parse_block_html="true" /} + +
    +
    + +## Bluetooth Low Energy + +[ View source on Github](https://github.com/sandeepmistry/noble) + +### Step 1 + +Make a directory inside your "tessel-code" folder called "ble", change directory into that folder, and initialize a tessel project: + +`mkdir ble; cd ble; t2 init` + +### Step 2 +
    +
    + +
    +
    + +Plug the BLE module into either of Tessel's USB ports, then plug Tessel into your computer via USB. + +
    +
    + +![](http://i.imgur.com/aaQT2wC.jpg) + +
    +
    + +
    +
    + +### Step 3 + +Make sure your Tessel is connected to a wifi network as shown on the [wifi page](/wifi.html). Then gain root access to the Tessel shell: + +`t2 root` + +This command gives you direct access to the Linux system running on Tessel. We need this in order to power up the USB dongle. Run this command: +`hciconfig hci0 up` + +Then exit the root shell: + +`exit` + +### Step 4 + +
    +
    + +
    +
    + +Install by typing `npm install noble --force` into the command line (the `--force` flag is in case you are on OSX. The library is compatible with Linux (which Tessel uses) but not OSX, so npm blocks downloads to incompatible systems). + +
    +
    + +![](//i.imgur.com/7ZJQwQI.jpg) + +
    +
    + +
    +
    + +### Step 5 + +
    +
    + +
    +
    + +Rename "index.js" to "ble.js" and replace the file's contents with the following: + +{% highlight js %} +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/publicdomain/zero/1.0/ + +/********************************************* +This basic example scans for BLE peripherals and +prints out details when found +*********************************************/ +// Import the BLE library +var noble = require('noble'); +// USB modules don't have to be explicitly connected + +// Wait for the module to report that it is powered up first +noble.on('stateChange', function(state) { + if (state === 'poweredOn') { + console.log('beginning to scan...'); + // Begin scanning for BLE peripherals + noble.startScanning(); + } +}); + +// When a peripheral is discovered +noble.on('discover', function(peripheral) { + // Print out the address + console.log('peripheral found at:', peripheral.address); +}); + +console.log('waiting for power up...'); + +{% endhighlight %} + +Save the file. + +
    +
    + +
    +
    + +### Step 6 + +
    +
    + +
    +
    + +In your command line, `t2 run ble.js` + +Be sure your BLE peripheral(s) are enabled! You should see Tessel output the address of any nearby BLE peripherals. + +**Bonus:** Make your BLE dongle advertise as a peripheral. Hint: you will need the `bleno` library instead of `noble`. + +To see what else you can do with the BLE dongle, read the [noble](https://github.com/sandeepmistry/noble) and [bleno](https://github.com/sandeepmistry/bleno) documentation. + +
    +
    + +![](http://i.imgur.com/KnXf6uL.gif) + +
    +
    + +
    +
    + +### Step 7 + +What else can you do with a BLE module? Get inspired by a [community-created project.](http://tessel.io/projects) + +What are you making? [Share your invention!](//tessel.io/projects) + +If you run into any issues you can check out the [module forums](http://forums.tessel.io/c/modules). + +
    +