obniz developer team
Published

Send text messages on UART

If you enter a text message on a page opened on your smartphone, it will be sent from obniz via UART.

BeginnerFull instructions provided1 hour654

Things used in this project

Hardware components

obniz
Cambrian Robotics obniz
×1

Story

Read more

Code

source code

HTML
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script
      src="https://unpkg.com/obniz@3.x/obniz.js"
      crossorigin="anonymous"
    ></script>
    <script
      src="https://code.jquery.com/jquery-3.4.1.js"
      integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
      crossorigin="anonymous"
    ></script>
    <link
      rel="stylesheet"
      href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
      integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
      crossorigin="anonymous"
    />
    <title>Send Text Messages on UART</title>
  </head>
  <body>
    <div class="container">
      <h2 class="text-center" style="margin:40px">
        Send Text Messages on UART
      </h2>
      <form id="messageform" class="text-center row">
        <div class="col-xs-4 col-md-3"></div>
        <div id="formarea" class="text-center col-xs-4 col-md-6">
          <textarea id="textarea" name="text" rows="1" cols="20"></textarea>
          <div class="text-center">
            <button id="send" class="btn btn-success" style="margin:20px">
              Send
            </button>
          </div>
        </div>
        <div class="col-xs-4 col-md-3"></div>
      </form>
    </div>
    <script>
      $(() => {
        let obniz = new Obniz("OBNIZ_ID_HERE");
      
        obniz.onconnect = async () => {
          await obniz.uart0.start({ tx: 0, rx: 1, gnd: 11 });
      
          $("#messageform").submit(async e => {
            await e.preventDefault();
      
            let message = $("#textarea").val();
            await obniz.uart0.send(message + "\r\n");
            $("#textarea").val("");
          });
      
          $(window).on("beforeunload", async e => {
            await obniz.uart0.end();
            await obniz.close();
            return;
          });
        };
      });
    </script>
  </body>
</html>

Credits

obniz developer team
80 projects • 35 followers
Development board "obniz" is controlled via the internet.
Contact

Comments

Please log in or sign up to comment.