UART.js Library

This library is designed to provide a consistent API for accessing Serial/Bluetooth devices from the web using Web Serial and Web Bluetooth.

It is designed to more or less mimic the Puck.js library, but adds support for Web Serial devices.

To work, it needs to be run from a website that's served over HTTPS (not HTTP). While you can set one up yourself with Let's Encrypt, we're not going to cover that here. Instead, we'll use GitHub Pages.

<html>
 <head>
 </head>
 <body>
  <script src="https://www.espruino.com/js/uart.js"></script>
  <button onclick="UART.write('LED1.set();\n');">LED On!</button>
  <button onclick="UART.write('LED1.reset();\n');">LED Off!</button>
 </body>
</html>

You'll now have your own webpage at: https://your_username.github.io/UARTTest/test.html

You can always just click 'Try Me!' above

As well as UART.write for sending data, UART.eval is available for reading back data:

<html>
 <head>
 </head>
 <body>
  <script src="https://www.espruino.com/js/uart.js"></script>
  <script>
  function getTemperature() {
    UART.eval('E.getTemperature()', function(t) {
      document.getElementById("result").innerHTML = t;
    });
  }
  </script>
  <button onclick="getTemperature()">Get Temperature</button>
  <span id="result"></span>
 </body>
</html>

For further details, check out the Web Bluetooth page, the UART.js repository, and the UART.js code itself.

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.