You are reading a single comment by @user104759 and its replies. Click here to read the full conversation.
  • Hi All

    Thanks allobjects that helped but my progress is still quite slow, i have managed to connect to the train and disconnect but can't work out the best way to send the buffer. I am still trying to get my head around javascript so maybe missing something quite obvious

    here's my current code

    var devices;
    var gatt;
    var DevName="e0:7d:ea:0c:03:29";
    var serviceUUID="00001623-1212-efde-1623-785­feabcd123";
    var characteristicUUID="00001624-1212-efde-1­623-785feabcd123";
    var MessageToSend=[0x81, 0x00, 0x11, 0x51, 0x00, 0x64];
    pinMode(D15, 'input_pulldown');
    global.LED2=D2;

    NRF.connect("e0:7d:ea:0c:03:29").then(fu­nction(g) {
    console.log("Starting connecting");
    gatt = g;
    return gatt.getPrimaryService("00001623-1212-ef­de-1623-785feabcd123");
    }).then(function(service) {
    return service.getCharacteristic("00001624-1212­-efde-1623-785feabcd123");
    }).then(function(characteristic) {
    return characteristic.writeValue(MessageToSend)­;
    }).then(function() {
    //gatt.disconnect();
    console.log("Done!");
    });

    function send_message() {
    console.log("Moving Train");
    NRF.nfcSend(new Uint8Array([0x81, 0x00, 0x11, 0x51, 0x00, 0x64]));
    }

    function train_disconnect() {
    console.log("Disconnecting");
    gatt.disconnect();
    }

    setInterval(function() {
    digitalWrite(LED2, digitalRead(D15));
    if (digitalRead(D15) == 1) {

    send_message();
    

    }
    console.log("Button pressed", digitalRead(D15));
    }, 300);

    any advice would be greatly appreciated

    Cheers

    James

  • Hello James, any chance you would re-edit your code posting so that line numbers will appear along with color hilighting?

    Hilight the code block, then click the < / > code button between the Quote button and Preview button,

    or,

    Place three backticks (below the tilde key and next to the numeral 1 key) just before and just after the code block.

    This will enhance and make reading easier.

About

Avatar for user104759 @user104759 started