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

Commit b0d937f

Browse files
authored
Merge pull request #887 from iankchristie/fileServing
File serving
2 parents 94cb9a8 + 45b3892 commit b0d937f

File tree

3 files changed

+80
-4
lines changed

3 files changed

+80
-4
lines changed

nodejs/FatBeaconPeripheral/FatBeacon.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var bleno = require('bleno');
22
var eddystoneBeacon = require('eddystone-beacon');
33
var webpageCharacteristic = require('./webpageCharacteristic');
4+
var fs = require('fs');
45

56
var SERVICE_UUID = 'ae5946d4-e587-4ba8-b6a5-a97cca6affd3';
67

@@ -54,8 +55,12 @@ AdvertisementData.makeUrlBuffer = function(name) {
5455
/*********************************************************/
5556

5657
var characteristic = new webpageCharacteristic();
57-
var data = new Buffer.from('Hello World of FatBeacon!');
58-
characteristic.onWriteRequest(data, 0, null, null);
58+
59+
fs.readFile("./html/fatBeaconDefault.html", function(err, data) {
60+
if(err) throw err;
61+
characteristic.onWriteRequest(data, 0, null, null);
62+
console.log(service);
63+
});
5964

6065
var service = new bleno.PrimaryService({
6166
uuid: SERVICE_UUID,
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
5+
<link rel="shortcut icon" type="image/x-icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAABC1BMVEX///8+gsM/gsM/gsM/gsQ/gsM/gsM/gsM+gcM/gsM/gsM/gsM/gsM+gsM/gsM/gsM/gsM/gsM9gMI/gsM/gsM/gsM+gcM/gsM/gsM/gsM/gsM/gsM/gsM+gcM/gsM9gcI5f8I/gsM/gsM/gsU8f8E8gMI/gsM/gsM/gsM/gsM/gsM/gsM/gsM/gsM/gsM/gsM/gsM/gsM/gsM/gsM/gsM/gsM+gsM/gcM/gsM/gsM/gsM+gcM/gsM/gsM/gsM+gsM+gsM/gsM/gsM9gMM9gME/gsM9gMI8gcM+gcM/gsM+gMI+gMM/gsM9gcI/gcM+gcM9gMI/gsM+gsM8f8M8gME7gME9gcJAg8T///8dQjXcAAAAV3RSTlMBF4XX/f3VgxdL7bVTI0lB81kLZ6FbCeFpH9nNfx/fBwPJlwMDA6c96eu/XWVfvblrx7OjF/c1F6Ut9R11qzkfLZ3BCQc/BwsLkQ0NjwshIwWpBQUFBQXrCtlNAAAAAWJLR0QAiAUdSAAAAAd0SU1FB+AIEREoJpDxKAkAAADMSURBVBjTY2AAAkYmZhZWNnYOBijg5OLm4eXl4ebig/D5BQSFhEVEhIVEBfhBfDFxCUkpaRkZaWZZCTl5oIAom4KikjIDg4qSoiqbKFBAjV1dQwysVFOdXQRIa2kLc0MM49bR1QNS+gaChhABRUEDIyDFZGxiagbim5maWzABaUsraxtbBjs7BlsbeysHkIyjk7OLq4CAq5u7kyNYq4enl7pAeLiAq7ePL9TtfkA+UMQf5heGADWQQGAQXIAhODA83DaEAQmEqgWGQVgAlbAZM4elADkAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTYtMDgtMTdUMTc6NDA6MzgtMDQ6MDDPiIKeAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE2LTA4LTE3VDE3OjQwOjM4LTA0OjAwvtU6IgAAAABJRU5ErkJggg==">
6+
<title>FatBeacon demo</title>
7+
<style>
8+
body {
9+
margin: 0;
10+
padding: 0;
11+
font-family: sans-serif;
12+
color: #444;
13+
background: #f5f5f5;
14+
}
15+
.header {
16+
display: flex;
17+
background: #3F82C4;
18+
height: 100px;
19+
}
20+
.card {
21+
background: #fff;
22+
padding: 20px;
23+
margin: 30px 30px 0px 30px;
24+
border: 1px solid #ccc;
25+
box-shadow: 0px 0px 5px #aaa;
26+
}
27+
p {
28+
font-size: 15px;
29+
}
30+
a {
31+
color: #3F82C4;
32+
}
33+
h1 {
34+
margin: 35px 0px 0px 10px;
35+
display: inline-block;
36+
font-size: 18px;
37+
color: #fff;
38+
}
39+
svg {
40+
margin-left: 30px;
41+
display: inline-block;
42+
width: 50px;
43+
}
44+
</style>
45+
</head>
46+
<body>
47+
<div class="header">
48+
<svg viewBox="0 0 171 202"><g fill="#fff"><path d="M141.2 85.3c0-31-25-56-56-56-30.7 0-55.8 25-55.8 56 0 17 7.8 32.5 20 42.8l10-10c-9.8-7.6-16-19.4-16-32.7 0-23.2 18.8-42 42-42 23 0 41.8 18.8 41.8 42 0 13.3-6.2 25-16 32.8l10 10c12.2-10.2 20-25.6 20-42.7"/><path d="M14 85.3C14 46 46 14 85.3 14s71.3 32 71.3 71.3c0 21.4-9.5 40.6-24.5 53.7l10 10c17.6-15.7 28.6-38.4 28.6-63.7 0-47-38.2-85.3-85.3-85.3C38.3 0 0 38.2 0 85.3c0 25.3 11 48 28.5 63.6l10-10C23.5 126 14 106.7 14 85.3"/><path d="M89.2 200.3c-2 2-5.5 2-7.6 0l-35.8-35.8c-2-2-2-5.5 0-7.6l35.8-36c2-2 5.5-2 7.6 0l35.8 36c2 2 2 5.4 0 7.5l-35.8 35.8z"/></g></svg>
49+
<h1>Welcome to FatBeacon!</h1>
50+
</div>
51+
<div class="card">
52+
<p>A FatBeacon is an experimental beacon type for offline web pages. A FatBeacon does two things:</p>
53+
<ul>
54+
<li>It advertises the name of the device</li>
55+
<li>Runs a <a href="https://developer.bluetooth.org/TechnologyOverview/pages/gatt.aspx">GATT</a> service that offers up a simple web page.</li>
56+
</ul>
57+
<p>When you select a FatBeacon from the list of nearby beacons, the app connects to it and downloads to page to your phone before displaying it. This means you can interact with a FatBeacon with no data connectivity at all.</p>
58+
</div>
59+
</body>
60+
</html>

nodejs/FatBeaconPeripheral/webpageCharacteristic.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,24 @@ var WebpageCharacteristic = function() {
1111

1212
this._value = Buffer.alloc(0);
1313
this._updateValueCallback = null;
14+
15+
this._mtuSize = 251; // 5 less than the specified mtu
16+
this._start = 0;
17+
this._end = this._mtuSize;
1418
};
1519

1620
util.inherits(WebpageCharacteristic, bleno.Characteristic);
1721

1822
WebpageCharacteristic.prototype.onReadRequest = function(offset, callback) {
19-
console.log(`Reading - ${this._value}`);
20-
callback(this.RESULT_SUCCESS, this._value);
23+
var tempBuffer = this._value.slice(this._start, this._end);
24+
callback(this.RESULT_SUCCESS, tempBuffer);
25+
26+
this._start = this._end;
27+
this._end = this._end + this._mtuSize;
28+
if(this._start >= this._value.length) {
29+
this._start = 0;
30+
this._end = this._mtuSize;
31+
}
2132
};
2233

2334
WebpageCharacteristic.prototype.onWriteRequest = function(data, offset, withoutResponse, callback) {

0 commit comments

Comments
 (0)