Unlock iPhone from obniz

このエントリーをはてなブックマークに追加

What's this

as bluetooth-keyboard, obniz unlock iPhone.

How does it work

Smartphone can connect to a bluetooth keyboard.
RN42 module can behave bluetooth keyboard.

A RN42 is now connected to an obniz.

Now, You can send “key typings” from javascript.

Program

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
<script src="//code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://unpkg.com/obniz@2.0.2/obniz.js"></script>
</script>
</head>
 
<body>
<div id="obniz-debug"></div>
<button id="config">config rn42</button>

<script>
var obniz = new Obniz("OBNIZ ID HERE");
obniz.onconnect = async function () {
  obniz.io11.output(true); // regulator required 5v to 3.3v
  obniz.io8.output(false);
  var rn42 = obniz.wired("RN42", 9, 10);

  var unlockBtn = obniz.wired("Button", 0, 2);
  var msgBtn = obniz.wired("Button", 4, 6);

  msgBtn.onChange(function(pressed){
    if (pressed) {
      rn42.send("hello\nThis is writtern from obniz");
    }
  });

  unlockBtn.onChange(function(pressed){
    if (pressed) {
      var passcode = [1,2,3,4,5,6];
      rn42.send("\n");
      obniz.freeze(500);
      rn42.send("\n");
      obniz.freeze(500);
      for (var i=0; i<passcode.length; i++) {
        rn42.send(""+passcode[i]);
        obniz.freeze(400);
      } 
    }
  });

  $("#config").click(function(){
    rn42.config({
      display_name: "obniz",
      master_slave: "slave",
      profile: "HID",
      auth: "just-work",
      power: 16,
    })
  })
}
</script>
</body>
</html>