Skip to content

Commit

Permalink
Adds initial files for BLE start guide
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyman727 committed Jan 7, 2016
1 parent f0d8533 commit 9a2ce47
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 0 deletions.
4 changes: 4 additions & 0 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ <h1><a href="https://tessel.io/"><nobr><img src=
<a href="{{ site.baseurl }}/modules/ambient.html" class=
"side-bar-modules">ambient</a>
</li>
<li style="padding-left:10px;">
<a href="{{ site.baseurl }}/modules/ble.html" class=
"side-bar-modules">ble</a>
</li>
<li style="padding-left:10px;">
<a href="{{ site.baseurl }}/modules/climate.html" class=
"side-bar-modules">climate</a>
Expand Down
1 change: 1 addition & 0 deletions modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions modules/_module_footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ <h2>Choose another module</h2>
"moduleLink">Ambient <small>Light +
Sound</small></span></a>
</li>
<li>
<a href="ble.html"><span class=
"moduleLink">BLE</span></a>
</li>
<li>
<a href="climate.html"><span class=
"moduleLink">Climate</span></a>
Expand Down
10 changes: 10 additions & 0 deletions modules/ble.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
layout: default
---

{% capture include_install %}
{% include_relative ble.md %}
{% endcapture %}
{{ include_install | markdownify }}

{% include_relative _module_footer.html %}
155 changes: 155 additions & 0 deletions modules/ble.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{::options parse_block_html="true" /}

<div class="row">
<div class="large-12 columns">

## <img class="constrain-sm" src="//i.imgur.com/7qR5OZJ.png"> Bluetooth Low Energy

[<i class="fa fa-github"> View source on Github</i>](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
</div>
</div>

<div class="row">
<div class="large-6 columns">

Plug the BLE module into either of Tessel's USB ports, then plug Tessel into your computer via USB.

</div>
<div class="large-6 columns">

![](http://i.imgur.com/aaQT2wC.jpg)

</div>
</div>

<div class="row">
<div class="large-12 columns">

### 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

</div>
</div>

<div class="row">
<div class="large-6 columns">

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).

</div>
<div class="large-6 columns">

![](//i.imgur.com/7ZJQwQI.jpg)

</div>
</div>

<div class="row">
<div class="large-12 columns">

### Step 5

</div>
</div>

<div class="row">
<div class="large-12 columns">

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.

</div>
</div>

<div class="row">
<div class="large-12 columns">

### Step 6

</div>
</div>

<div class="row">
<div class="large-6 columns">

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.

</div>
<div class="large-6 columns">

![](http://i.imgur.com/KnXf6uL.gif)

</div>
</div>

<div class="row">
<div class="large-12 columns">

### 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).

</div>
</div>

0 comments on commit 9a2ce47

Please sign in to comment.