You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Hi! As I understand it, simblee had characteristics predefined that would change the state of pins when you wrote to them.

    Espruino is a bit more flexible - you can either write JavaScript code directly to the UART characteristic or you can make Espruino itself behave like simblee:

    JavaScript

    $ gatttool --device=fc:cc:b8:22:b0:42 --addr-type=random -I
    [fc:cc:b8:22:b0:42][LE]> connect
    Attempting to connect to fc:cc:b8:22:b0:42
    Connection successful
    [fc:cc:b8:22:b0:42][LE]> char-desc
    handle: 0x0001, uuid: 00002800-0000-1000-8000-00805f9b34fb
    handle: 0x0002, uuid: 00002803-0000-1000-8000-00805f9b34fb
    handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb
    handle: 0x0004, uuid: 00002803-0000-1000-8000-00805f9b34fb
    handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb
    handle: 0x0006, uuid: 00002803-0000-1000-8000-00805f9b34fb
    handle: 0x0007, uuid: 00002a04-0000-1000-8000-00805f9b34fb
    handle: 0x0008, uuid: 00002803-0000-1000-8000-00805f9b34fb
    handle: 0x0009, uuid: 00002aa6-0000-1000-8000-00805f9b34fb
    handle: 0x000a, uuid: 00002800-0000-1000-8000-00805f9b34fb
    handle: 0x000b, uuid: 00002800-0000-1000-8000-00805f9b34fb
    handle: 0x000c, uuid: 00002803-0000-1000-8000-00805f9b34fb
    handle: 0x000d, uuid: 6e400003-b5a3-f393-e0a9-e50e24dcca9e
    handle: 0x000e, uuid: 00002902-0000-1000-8000-00805f9b34fb
    handle: 0x000f, uuid: 00002803-0000-1000-8000-00805f9b34fb
    handle: 0x0010, uuid: 6e400002-b5a3-f393-e0a9-e50e24dcca9e
    [fc:cc:b8:22:b0:42][LE]> char-write-req 0x0010 4c45442e746f67676c6528290a
    Characteristic value was written successfully
    [fc:cc:b8:22:b0:42][LE]> char-write-req 0x0010 4c45442e746f67676c6528290a
    Characteristic value was written successfully
    

    Here you use 0x0010 because that's the handle for uuid 6e400002-b5a3-f393-e0a9-e50e24dcca9e which is the Nordic UART transmit characteristic.

    4c45442e746f67676c6528290a is the hex value of "LED.toggle()\n" which you get using the JavaScript code:

    "LED.toggle()\n".split("").map(x=>(256+x.charCodeAt()).toString(16).substr(-2)).join("")
    

    So you could change this to D3.write(1)\n for instance to change the state of pin D3.

    Simblee clone

    • Connect with the Web IDE
    • Upload this code:

      NRF.setServices({
      "35ac0001-18b0-e8b7-3feb-62cec301da00" : {
      "35ac0002-18b0-e8b7-3feb-62cec301da00" : {
        value : [0,0,0],
        maxLen : 3,
        writable : true,
        onWrite : function(evt) {
          digitalWrite([D25,D26,D27,D28,D29,D30,D31,D3], evt.data[0]);
          digitalWrite([D4,D5,D22,D29,D19,D18,D17,D16], evt.data[1]);
          digitalWrite([D15,D14,LED2,LED1], evt.data[2]);
        }
      }
      }
      });
      

    This will create a characteristic with uuid 35ac0002-18b0-e8b7-3feb-62cec301da00 that will write to all the pins of the MDBT42 module based on the 3 bytes you send to it.

    • disconnect and use gatttool:

      $ gatttool --device=fc:cc:b8:22:b0:42 --addr-type=random -I
      [fc:cc:b8:22:b0:42][LE]> connect
      Attempting to connect to fc:cc:b8:22:b0:42
      Connection successful
      [fc:cc:b8:22:b0:42][LE]> char-desc 
      handle: 0x0001, uuid: 00002800-0000-1000-8000-00805f9b34fb
      handle: 0x0002, uuid: 00002803-0000-1000-8000-00805f9b34fb
      handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb
      handle: 0x0004, uuid: 00002803-0000-1000-8000-00805f9b34fb
      handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb
      handle: 0x0006, uuid: 00002803-0000-1000-8000-00805f9b34fb
      handle: 0x0007, uuid: 00002a04-0000-1000-8000-00805f9b34fb
      handle: 0x0008, uuid: 00002803-0000-1000-8000-00805f9b34fb
      handle: 0x0009, uuid: 00002aa6-0000-1000-8000-00805f9b34fb
      handle: 0x000a, uuid: 00002800-0000-1000-8000-00805f9b34fb
      handle: 0x000b, uuid: 00002800-0000-1000-8000-00805f9b34fb
      handle: 0x000c, uuid: 00002803-0000-1000-8000-00805f9b34fb
      handle: 0x000d, uuid: 6e400003-b5a3-f393-e0a9-e50e24dcca9e
      handle: 0x000e, uuid: 00002902-0000-1000-8000-00805f9b34fb
      handle: 0x000f, uuid: 00002803-0000-1000-8000-00805f9b34fb
      handle: 0x0010, uuid: 6e400002-b5a3-f393-e0a9-e50e24dcca9e
      handle: 0x0011, uuid: 00002800-0000-1000-8000-00805f9b34fb
      handle: 0x0012, uuid: 00002803-0000-1000-8000-00805f9b34fb
      handle: 0x0013, uuid: 35ac0002-18b0-e8b7-3feb-62cec301da00
      [fc:cc:b8:22:b0:42][LE]> char-write-req 0x0013 000001  <----------- LED1 turns on
      Characteristic value was written successfully
      [fc:cc:b8:22:b0:42][LE]> char-write-req 0x0013 000002  <----------- LED2 turns on
      Characteristic value was written successfully
      [fc:cc:b8:22:b0:42][LE]> char-write-req 0x0013 000002  <----------- both LEDS turns on
      Characteristic value was written successfully
      [fc:cc:b8:22:b0:42][LE]> char-write-req 0x0013 000000 <----------- both LEDS turns off
      Characteristic value was written successfully
      

    So you could make this work in a very similar way to simblee - however chances are the characteristic handles would be different even if you made the UUIDs the same.

    Hope that helps!

About

Avatar for Gordon @Gordon started