espruino-ble-uart

1.0.3 • Public • Published

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:
  1. connect : Connect to a new device - this creates a separate connection to the one write and eval use.

    Usage: uart.connect(your_function)

  2. write : Write to a device and call back when the data is written. Creates a connection if it doesn't exist

  3. eval : Evaluate an expression and call cb with the result. Creates a connection if it doesn't exist

  4. isConnected : Did write and eval manage to create a connection?

  5. getConnection : get the connection used by write and eval

  6. close : Close the connection used by write and eval

  7. 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);
    }
  8. setTime : Write the current time to the device. Note: This is for Espruino devices

    Usage: 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.

Package Sidebar

Install

npm i espruino-ble-uart

Weekly Downloads

0

Version

1.0.3

License

Apache-2.0

Unpacked Size

24.2 kB

Total Files

3

Last publish

Collaborators

  • kevinjohnmulligan