Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit d6aeef6

Browse files
committed
Add FatBeacon Implementation for Eddystone
This change sets up an eddystone-beacon to advertise a fatbeacon. It uses monkey-patching to override dependent functions at runtime, in order to attatch the Fatbeacon header. It is not connectable, as it contains no service or characteristic to read from.
1 parent fa38299 commit d6aeef6

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
var bleno = require('bleno');
2+
var eddystoneBeacon = require('eddystone-beacon');
3+
4+
/***********************Altering Library Functions**************************/
5+
/**
6+
* In order to broadcast in the fatbeacon format, we override several
7+
* functions in the advertisement-data module of the eddystone-beacon library.
8+
*/
9+
var AdvertisementData =
10+
require('eddystone-beacon/lib/util/advertisement-data');
11+
var Eir = require('eddystone-beacon/lib/util/eir');
12+
13+
var FAT_BEACON_FRAME_TYPE = 0x0e;
14+
var MAX_URL_LENGTH = 18;
15+
var SERVICE_UUID = 'feaa';
16+
17+
/**
18+
* this patch ensures that the correct Fatbeacon eir flag (0x06) is added
19+
* to the packet instead of the library standard flag.
20+
*/
21+
AdvertisementData.makeEirData = function(serviceData) {
22+
var eir = new Eir();
23+
eir.addFlags(0x06);
24+
eir.add16BitCompleteServiceList([SERVICE_UUID]);
25+
eir.addServiceData(SERVICE_UUID, serviceData);
26+
return eir.buffer();
27+
}
28+
29+
/**
30+
* This patch alters the method signature to accept a name instead of a url.
31+
* It also encodes the name in hex instead of the libraries url encoding
32+
* format. Lastly, it adds the Fatbeacon header to the packet.
33+
*/
34+
AdvertisementData.makeUrlBuffer = function(name) {
35+
console.log(`AdvertisementData.makeUrlBuffer called with: ${name}`);
36+
37+
var encodedName = Buffer.from(name);
38+
if (encodedName.length > MAX_URL_LENGTH) {
39+
throw new Error(`Encoded Name must be less than ${MAX_URL_LENGTH} bytes.` +
40+
` It is currently ${encodedName.length} bytes.`);
41+
}
42+
43+
var serviceData = Buffer.concat([
44+
Buffer.from([0x10, 0xba, FAT_BEACON_FRAME_TYPE]), //FatBeacon Header
45+
encodedName
46+
]);
47+
48+
return AdvertisementData.makeEirData(serviceData);
49+
}
50+
51+
/*********************************************************/
52+
53+
// Start Advertising name.
54+
eddystoneBeacon.advertiseUrl('New Fatbeacon');
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FatBeacon on Raspberry Pi
2+
=========================
3+
4+
This is a nodejs implementation of a Fatbeacon developed on a Raspberry Pi 3.
5+
It will advertise a connectable Fatbeacon over Bluetooth Low Energy (BLE).
6+
When the central (client) connects to the peripheral (Fatbeacon/server), the
7+
central will attempt to read the webpageCharacteristic, which serves a HTML.
8+
There is also the option to have this data be compressed with gzip.
9+
10+
Instructions for Raspbian:
11+
--------------------------
12+
1. Clone repository onto Pi. If you're using a Pi2 or earlier, make sure you
13+
have a bluetooth chip installed.
14+
2. Make sure you have nodejs
15+
16+
```$ node -v```
17+
18+
If not, then run
19+
20+
```$ sudo apt install nodejs```
21+
22+
3. For bleno make sure bluetooth, bluez, libbluetooth-dev, and libudev-dev
23+
are installed
24+
25+
```$ sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev```
26+
27+
4. Navigate to the repository directory and run
28+
29+
```$ sudo npm install```
30+
31+
This should download all required nodejs libraries.
32+
5. To run
33+
34+
```$ sudo node FatBeacon.js```

0 commit comments

Comments
 (0)