Created
August 26, 2018 23:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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