-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a Fat Beacon support and an example #42
base: master
Are you sure you want to change the base?
Changes from 8 commits
7d50752
eb27b3b
765c1fa
cb939a0
2832a63
9e735c1
5c8598b
0f251f3
985d7ad
cb592f8
b790890
425e56d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<html> | ||
<head> | ||
<title>Fat Beacon Demo</title> | ||
<meta charset='UTF-8'> | ||
<meta name='description' content='Fat Beacon Demo'/> | ||
</head> | ||
<body> | ||
<h1>HelloWorld</h1> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="171" height="202"><g fill="#3F82C4" fill-rule="evenodd"><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> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Simplest way to create a Eddystone-FatBeacon | ||
|
||
// might want to include something like this https://www.npmjs.com/package/html-minify | ||
|
||
var eddystoneBeacon = require('./../../index'); | ||
var fs = require('fs'); | ||
|
||
fs.readFile('index.html', function(err, data){ | ||
if (!err) { | ||
eddystoneBeacon.advertiseFatBeacon('Fat Beacon Demo', {html: data}); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Copyright 2016 IBM Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
**/ | ||
var bleno = require('bleno'); | ||
var util = require('util'); | ||
|
||
var currentMTU = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should kill these globals and use bleno.mtu anyway |
||
var queueOffset = 0; | ||
|
||
bleno.on('mtuChange', function(mtu) { | ||
//console.log('on -> mtuChange: ' + mtu); | ||
currentMTU = mtu; | ||
}); | ||
|
||
bleno.on('accept', function(){ | ||
queueOffset = 0; | ||
}); | ||
|
||
function HTMLCharacteristic(html) { | ||
this._html = html; | ||
this._buffer = new Buffer(this._html, 'utf8'); | ||
bleno.Characteristic.call(this, { | ||
uuid: 'd1a517f0249946ca9ccc809bc1c966fa', | ||
properties: ['read'], | ||
descriptors: [ | ||
new bleno.Descriptor({ | ||
uuid: '2901', | ||
value: 'HTML' | ||
}) | ||
] | ||
}); | ||
} | ||
|
||
util.inherits(HTMLCharacteristic,bleno.Characteristic); | ||
|
||
HTMLCharacteristic.prototype.onReadRequest = function(offset, callback) { | ||
//var buf = new Buffer(this._html, 'utf8'); | ||
if (queueOffset < this._buffer.length) { | ||
var transfer = currentMTU - 5; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hayesjordan can you comment on why physical web is using -5 instead of -3 overhead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no specific reason for using -5, it can be anything less than 0. The only reason for it is to by pass the Android OS on the client device. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its currently oddly implemented on the android side. Transfer is defaulted to 20 (which would be default (23) -3 as Id expect, but then when mtu changes its mtu (505)-5 Seems like if you wanted it to be mtu-5 then transfer defined above there should be 18 not 20 for consistancy.. though it seems like it should be the size of the BLE spec overhead, which I think is 3. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was not aware of a BLE spec for overhead, but the numbers didn't seem to be important at the time. I was only trying to keep them for easy multiples when I was debugging this is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I come from the embedded world more, and I know 20 bytes of the 23 is typical for the nordic devices, I presume this is in the spec, perhaps its their limitations. Ill keep researching and maybe @sandeepmistry can illuminate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like as low as 1 actually. Ive heard 20 quoted a ton on nrf, wonder if thats correct over there. 3.4.7.1 Handle Value Notification 3.4.4.4 Read Response There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jacobrosenthal 23 bytes is the minimum MTU (and default). I'm reading from unofficial sources the maximum is 517 bytes. On Linux, bleno currently has a maximum MTU of 256 bytes, we can bump this up once we find the official maximum MTU size. 20 bytes is right for the maximum notification data size: 23 - 3 and 22 for the maximum size of read data if the MTU is 23: 23 -1 |
||
var end = queueOffset + transfer >= this._buffer.length ? this._buffer.length: queueOffset + transfer; | ||
var slice = this._buffer.slice(queueOffset, end); | ||
callback(this.RESULT_SUCCESS, slice); | ||
queueOffset = end; | ||
} else if (queueOffset === this._buffer.length) { | ||
callback(this.RESULT_SUCCESS, new Buffer()); | ||
queueOffset++; | ||
} | ||
|
||
} | ||
|
||
module.exports = HTMLCharacteristic; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about adding this in a separate file and using the
fs
module to read the contents?