cubing/bluetooth

cubing/bluetooth supports connecting to a variety of Bluetooth devices, particularly smart cubes. A few other devices (smart timers, cube robots) are also supported.

Connect to a smart puzzle

Connect to a smart puzzle and listen like this:

import { connectSmartPuzzle } from "https://cdn.cubing.net/v0/js/cubing/bluetooth";

const puzzle = await connectSmartPuzzle();
puzzle.addAlgLeafListener((e) => {
 console.log(e.latestAlgLeaf);
});

You may find it useful to start with the following example:

<twisty-player id="player"></twisty-player>
<button id="connect">Connect</button>
<twisty-alg-viewer for="player"></twisty-alg-viewer>

<script type="module">
import "https://cdn.cubing.net/v0/js/cubing/twisty";
import { connectSmartPuzzle, debugKeyboardConnect } from "https://cdn.cubing.net/v0/js/cubing/bluetooth";

const debug = new URL(location.href).searchParams.get("debug-keyboard") === "true";
const button = document.querySelector("button#connect");

async function connect() {
  const puzzle =
    debug
      ? await debugKeyboardConnect()
      : await connectSmartPuzzle();

  button.textContent = "↔️ Connected!";
  button.disabled = true;

  const twistyPlayer = document.querySelector("twisty-player");
  puzzle.addAlgLeafListener((e) => {
    twistyPlayer.experimentalAddAlgLeaf(e.latestAlgLeaf, {
      cancel: true,
    });
  });
}

if (debug) {
  button.textContent += " (keyboard)";
}
button.addEventListener("click", connect);
</script>

Try it.

Advanced example

See https://bluetooth.cubing.net/ for an example solve reconstruction tool for Bluetooth cubes.

Fallback

If you try and fail to connect to a smart puzzle two times, cubing.js will open up scanning to all Bluetooth devices on the third time automatically.

Compatibility

Note that smart puzzle manufaturers use proprietary protocols that they purposely obfuscate and change without warning. This means that it often takes time-consuming reverse engineering to support a new smart puzzle. cubing.js is able to connect to at least one version of each of the following:

Manufacturer Move stream Orientation
(depending on the model)
Known to have incompatible versions
GiiKER ✅ Yes N/A ☑️ No
Xiaomi Mi
GoCube ✅ Yes ✅ Yes ☑️ No
Rubik's Connected N/A
Gan ✅ Yes ✅ Yes ❌ Yes
HEYKUBE ✅ Yes N/A ☑️ No
QiYi ✅ Yes N/A ☑️ No
Moyu ❌ No N/A N/A

Please let us know by filing an issue if you find more incompatibilities.

If you work with a smart cube manufacturer and would like to talk about supporting an open protocol, please feel welcome to contact us as well!