This is an Espruino Web Tool that implements the Nordic UART Service (NUS) by Nordic Semiconductors for BLE use. This allows BLE devices to communicate using UART via Bluetooth Low Energy.
npm install espruino-ble-uart#### Short Description:
This is an Espruino Web Tool that implements the Nordic UART Service (NUS) by Nordic Semiconductors for BLE use. This allows BLE devices to communicate using UART via Bluetooth Low Energy.
This can be used with or without an Espruino board, this module searches for all NUS enabled devices.
#### Author:
The module is written by Gordon Williams (github.com/gfwilliams) for Espruino and is distributed under the Apache 2.0 License. I have merely uploaded and documented it for ease of use.
#### Installation:
In your terminal :
``bash
`
$ npm add espruino-ble-uart
`
#### Usage:
In your JavaScript code:
javascript
`
const uart = require( "espruino-ble-uart")
connect
---
##### Available functions:
1. : Connect to a new device - this creates a separate connection to the one write and eval use.
uart.connect(your_function)
Usage:
write
2. : Write to a device and call back when the data is written. Creates a connection if it doesn't exist
eval
3. : Evaluate an expression and call cb with the result. Creates a connection if it doesn't exist
isConnected
4. : Did write and eval manage to create a connection?
getConnection
5. : get the connection used by write and eval
close
6. : Close the connection used by write and eval
modal
7. : Utility function to fade out everything on the webpage and display a window saying 'Click to continue'. When clicked it'll disappear and 'callback' will be called. This is useful because you can't initialise Web Bluetooth unless you're doing so in response to a user input.
uart.modal(your_function)
Usage:
`
javascript
`
modal : function(callback) {
var e = document.createElement('div');
e.style = 'position:absolute;top:0px;left:0px;right:0px;bottom:0px;opacity:0.5;z-index:100;background:black;';
e.innerHTML = 'Click to Continue...';
e.onclick = function(evt) {
callback();
evt.preventDefault();
document.body.removeChild(e);
};
document.body.appendChild(e);
}
setTime
8. : Write the current time to the device. Note: This is for Espruino devices
uart.setTime(your_function)
Usage:
`
javascript
`
setTime : function(cb) {
var d = new Date();
var cmd = 'setTime('+(d.getTime()/1000)+');';
// in 1v93 we have timezones too
cmd += 'if (E.setTimeZone) E.setTimeZone('+d.getTimezoneOffset()/-60+');\n';
write(cmd, cb);
}
---
ā
##### Note on console output: