Skip to content

Instantly share code, notes, and snippets.

@Umajin
Last active Jan 29, 2019
Embed
What would you like to do?
//
// ble.js
// Getting Started with BLE
//
// Created by Dianyi Jiang on 29/01/19.
// Copyright © 2019 Umajin. All rights reserved.
//
// print msg when bluetooth is Enabled
registerAction("ble_enabled", "", "Bluetooth Enabled", "");
function ble_enabled() {
var msg = "the bluetooth is enabled";
printMsg(msg);
}
// print msg when bluetooth is Disabled
registerAction("ble_disabled", "", "Bluetooth Disabled", "");
function ble_disabled() {
var msg = "the bluetooth is disabled";
printMsg(msg);
}
// print msg when bluetooth is Connected
registerAction("ble_connected", "", "Bluetooth Connected", "");
function ble_connected() {
var msg = "the bluetooth is connected";
printMsg(msg);
}
// action of pressing read button
registerAction("read_esp32", "", "Read ESP32", "");
function read_esp32() {
var msg = "Reading ESP32...";
printMsg(msg);
// for more infomation about this methon, plesae go to https://developer.umajin.com/jsmain/#getBluetoothCharacteristic__anchor
getBluetoothCharacteristic(
"4fafc201-1fb5-459e-8fcc-c5c9c331914b", // service UUID
"beb5483e-36e1-4688-b7f5-ea07361b26a8", // characteristic UUID
"esp32_callback" // callback which taks a value string
);
}
// the callback of getBluetoothCharacteristic
function esp32_callback(arg) {
printMsg(arg);
}
function printMsg(msg) {
var textComp = findComponent("Landing Page", "text", "Text");
setProperty(textComp, "text", msg);
print(msg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment