Avatar for sammachin

sammachin

Member since Nov 2016 • Last active Mar 2017
  • 2 conversations
  • 6 comments

Most recent activity

  • in Puck.js
    Avatar for sammachin

    Just thought I'd share the finished code for sending a word with a click of the button as a BLE HID Keyboard, not yet tried linking to the RasPi but works great with my iMac

    var kb = require("ble_hid_keyboard");
    NRF.setServices(undefined, { hid : kb.report });
    var reset_timer;
    var char_timer;
    var arr;
    
    var word = "Hello";
    
    
    function send(){
      LED3.set();
      arr = word.split("");
      char_timer = setInterval("sendChar()", 100);
      LED2.set();
      setTimeout("LED2.reset()",1000);
      LED3.reset();
    }
    
    function onTimeout() {
      setTimeout("LED1.reset()",5000);
      LED1.set();
      LED3.reset();
    }
    
    function sendChar(){
        if (arr.length !== 0){
            var char = arr.shift();
            if (char == char.toLowerCase())
            {
                sk = 0;
            }
            else
            {
                sk = 0x02;
            }
            kb.tap(kb.KEY[char.toUpperCase()], sk);
        }
        else{
            clearInterval(char_timer);
        }
    }
    
    setWatch(function() {
      send();
      }, BTN, {edge:"rising", debounce:50, repeat:true});
    
  • in Puck.js
    Avatar for sammachin

    ah yeah that worked (shift+alt) click on the bluetooth icon in the menu bar then select remove for the Puck and then reconnect via the WebIDE, now its sending the character :)

    Next challenge is to get this connected to my RasPi as a keyboard, any tips?

    :)

  • in Puck.js
    Avatar for sammachin

    hmm ok I'll have another go, I've taken out the 2nd character for now just to keep it simple.
    I've been having lots of problems with re-connecting tothe puck usually involving removing the battery and starting over

  • in Puck.js
    Avatar for sammachin

    I'm trying to setup my puck as a single button keyboard to send a character (or two) when the button is pressed, I'm not having much luck and struggling with how to debug it, as I understand it I have to disconnect the web bluetooth IDE before the puck can connect as a keyboard?
    I've flashed the code below to the puck then disconnect and press the button, the BLUE LED comes on for 10sec then the red one flashes as I would expect indicating its failed, I've tried scanning for new bluetooth devices (keyboards) from my Mac and iPhone after I disconnect but nothing is found.

    var kb = require("ble_hid_keyboard");
    NRF.setServices(undefined, { hid : kb.report });
    var reset_timer;
    
    function sendKB(){
      LED3.set();
      kb.tap(kb.KEY.H, kb.MODIFY.SHIFT, function() {
        kb.tap(kb.KEY.i, 0);
        });
      clearTimeout(reset_timer);
      LED2.set();
      setTimeout("LED2.reset()",1000);
      LED3.reset();
    }
    
    function onTimeout() {
      setTimeout("LED1.reset()",1000);
      LED1.set();
      LED3.reset();
    }
    
    setWatch(function() {
      reset_timer = setTimeout("onTimeout()",10000);
      sendKB();
      }, BTN, {edge:"rising", debounce:50, repeat:true});
    

    I'm running 1.9.1 on my puck, updated to that this morning

  • in JavaScript
    Avatar for sammachin

    Ah yeah those messages are a little larger they're 6k WAV with the header but I can break it up into 600 byte raw samples I forgot I was doing some conversion on the server!

    I'll try smaller message sizes and report back

  • in JavaScript
    Avatar for sammachin

    I've got the ws client implementation working, however my server sends binary messages over a websocket, (RAW PCM Audio frames) Is there any way to handle these in espruino, i'd like to so some visualisations of the data with neopixels eventually.

    It seems that a binary message doesn't invoke the on message event. I put logging of on raw in and this is what I get:

    >echo(0);
    =undefined
    Connected!
    RAW: HTTP/1.1 101 Switching Protocols
    U
    RAW: pgrade: websocket
    Connection: Upgrade
    Sec-WebSocket-Accept: BJcYBMUMFM4VKC/jom8iiI/n2Zo=
    Connected to server
    RAW: ~,RIFF$âWAVEfmt >}dataâ
    RAW: üÿøÿ÷ÿøÿøÿøÿøÿøÿøÿø
    RAW: ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø
    RAW: ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿø
    RAW: ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿø
    RAW: ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿø
    RAW: ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ
    RAW: øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿ
    RAW: øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿ
    RAW: øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿø
    RAW: ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿø
    RAW: ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿø
    RAW: ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿ
    RAW: øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø
    RAW: ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ
    RAW: øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­
    RAW: øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ
    RAW: øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø
    RAW: ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿø­ÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ
    RAW: øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ
    RAW: øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ
    RAW: øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿ
    RAW: øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ­øÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿøÿ
    >
    Disconnected
    Connected
    >
    
Actions