evothings. eddystone
Source: evothings-libraries/
Library for Eddystone beacons.
It is safe practise to call function evothings.scriptsLoaded to ensure dependent libraries are loaded before calling functions in this library.
Methods
Abstract types
Methods
calculateAccuracy(txPower, rssi)
Calculate the accuracy (distance in meters) of the beacon.
The beacon distance calculation uses txPower at 1 meters, but the Eddystone protocol reports the value at 0 meters. 41dBm is the signal loss that occurs over 1 meter, this value is subtracted by default from the reported txPower. You can tune the calculation by adding or subtracting to param txPower.
Note that the returned distance value is not accurate, and that it fluctuates over time. Sampling/filtering over time is recommended to obtain a stable value.
Example
// Note that beacon.txPower and beacon.rssi many be undefined,
// in which case calculateAccuracy returns null. This happens
// before txPower and rssi have been reported by the beacon.
var distance = evothings.eddystone.calculateAccuracy(
beacon.txPower, beacon.rssi);
Parameters
Name | Type | Optional | Description |
---|---|---|---|
txPower |
|
|
The txPower of the beacon. |
rssi |
|
|
The RSSI of the beacon, subtract or add to this value to tune the dBm strength. 41dBm is subtracted from this value in the distance algorithm used by calculateAccuracy. |
- Returns
-
Distance in meters, or null if unable to compute distance (occurs for example when txPower or rssi is undefined).
createLowPassFilter(cutOff)
Create a low-pass filter.
Example
// Create filter with cut off 0.8
var lowpass = evothings.eddystone.createLowPassFilter(0.8)
// Filter value (returns current filter value)
distance = lowpass.filter(distance)
// Get current value
distance = lowpass.value()
Parameter
Name | Type | Optional | Description |
---|---|---|---|
cutOff |
|
|
The filter cut off value. |
- Returns
-
Object with two functions: filter(value), value()
startAdvertise(namespace, instance, advertiseCallback, failCallback)
Start Advertising Eddystone Beacon.
Namespace may only be 10 hex bytes
Instance may only be 6 hex bytes
Will keep advertising indefinitely until you call stopAdvertise().
Example
evothings.eddystone.startAdvertise("0123456789ABCDEF0123", "0123456789AB");
Parameters
Name | Type | Optional | Description |
---|---|---|---|
namespace |
string |
|
Hex namespace string (10 bytes, 20 chars) |
instance |
string |
|
Hex instance string (6 bytes, 12 chars) |
advertiseCallback |
evothings.eddystone.advertiseCallback |
|
Success function called when advertising started |
failCallback |
|
Error callback: fail(error). |
startScan(scanCallback, failCallback)
Starts scanning for Eddystone devices.
Found devices and errors will be reported to the supplied callbacks.
Will keep scanning indefinitely until you call stopScan().
To conserve energy, call stopScan() as soon as you've found the device you're looking for.
Calling startScan() while scanning is in progress will produce an error.
Example
evothings.eddystone.startScan(
function(beacon)
{
console.log('Found beacon: ' + beacon.url);
},
function(error)
{
console.log('Scan error: ' + error);
});
Parameters
Name | Type | Optional | Description |
---|---|---|---|
scanCallback |
|
Success function called when a beacon is found. |
|
failCallback |
|
Error callback: fail(error). |
stopAdvertise(onSuccess, failCallback)
Stop Advertising Eddystone Beacon.
Example
evothings.eddystone.stopAdvertise();
Parameters
Name | Type | Optional | Description |
---|---|---|---|
onSuccess |
function() |
|
Success function called when advertising stoppped |
failCallback |
|
Error callback: fail(error). |
stopScan()
Stop scanning for Eddystone devices.
Example
evothings.eddystone.stopScan();
Abstract types
EddystoneDevice Object
Object representing a BLE device. Inherits from evothings.easyble.EasyBLEDevice. Which properties are available depends on which packets types broadcasted by the beacon. Properties may be undefined. Typically properties are populated as scanning processes.
Properties
Name | Type | Optional | Description |
---|---|---|---|
url |
string |
|
An Internet URL. |
txPower |
number |
|
A signed integer, the signal strength in decibels, factory-measured at a range of 0 meters. |
nid |
Uint8Array |
|
10-byte namespace ID. |
bid |
Uint8Array |
|
6-byte beacon ID. |
voltage |
number |
|
Device's battery voltage, in millivolts, or 0 (zero) if device is not battery-powered. |
temperature |
number |
|
Device's ambient temperature in 256:ths of degrees Celcius, or 0x8000 if device has no thermometer. |
adv_cnt |
number |
|
Count of advertisement frames sent since device's startup. |
dsec_cnt |
number |
|
Time since device's startup, in deci-seconds (10 units equals 1 second). |
failCallback(errorString)
This function is called when an operation fails.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
errorString |
string |
|
A human-readable string that describes the error that occurred. |
scanCallback(beacon)
This function is a parameter to startScan() and is called when a beacons is discovered/updated.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
beacon |
|
Beacon found during scanning. |