Skip to content

Instantly share code, notes, and snippets.

@loginov-rocks
Created August 26, 2018 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loginov-rocks/26d9714acbfbcb723c79bb8e23128e3c to your computer and use it in GitHub Desktop.
Save loginov-rocks/26d9714acbfbcb723c79bb8e23128e3c to your computer and use it in GitHub Desktop.
How to make a web app for your own Bluetooth Low Energy device? Step 4
// Get references to UI elements
let connectButton = document.getElementById('connect');
let disconnectButton = document.getElementById('disconnect');
let terminalContainer = document.getElementById('terminal');
let sendForm = document.getElementById('send-form');
let inputField = document.getElementById('input');
// Connect to the device on Connect button click
connectButton.addEventListener('click', function() {
connect();
});
// Disconnect from the device on Disconnect button click
disconnectButton.addEventListener('click', function() {
disconnect();
});
// Handle form submit event
sendForm.addEventListener('submit', function(event) {
event.preventDefault(); // Prevent form sending
send(inputField.value); // Send text field contents
inputField.value = ''; // Zero text field
inputField.focus(); // Focus on text field
});
// Launch Bluetooth device chooser and connect to the selected
function connect() {
//
}
// Disconnect from the connected device
function disconnect() {
//
}
// Send data to the connected device
function send(data) {
//
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment