espruino-ble-uart
v1.0.3
Published
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.
Downloads
9
Maintainers
Readme
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 :
$ npm add espruino-ble-uart
Usage:
In your JavaScript code:
const uart = require( "espruino-ble-uart")
Available functions:
connect
: Connect to a new device - this creates a separate connection to the onewrite
andeval
use.Usage:
uart.connect(your_function)
write
: Write to a device and call back when the data is written. Creates a connection if it doesn't existeval
: Evaluate an expression and call cb with the result. Creates a connection if it doesn't existisConnected
: Didwrite
andeval
manage to create a connection?getConnection
: get the connection used bywrite
andeval
close
: Close the connection used bywrite
andeval
modal
: 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.Usage:
uart.modal(your_function)
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 = '<div style="position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);font-family: Sans-Serif;font-size:400%;color:white;">Click to Continue...</div>'; e.onclick = function(evt) { callback(); evt.preventDefault(); document.body.removeChild(e); }; document.body.appendChild(e); }
setTime
: Write the current time to the device. Note: This is for Espruino devicesUsage:
uart.setTime(your_function)
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:
<UART> Web Serial not supported, No navigator.serial - Web Serial not enabled
Refers to the USB Serial port, if you are using BLE this message is irrelevant.