Avatar for gerardwr

gerardwr

Member since Jun 2020 • Last active Oct 2020
  • 4 conversations
  • 63 comments

Most recent activity

  • in Interfacing
    Avatar for gerardwr

    I always think it's ME, not this time ;-)

  • in Interfacing
    Avatar for gerardwr

    Update : working now!

    Reading the code from @Zakaton and @Gordon's response I added a characteristic.handle_cccd = 0x0038; statement.

          c.handle_cccd = 0x0038;
          return c.startNotifications();
    

    Now the Notifications are coming through.

    Device connected: A4:C1:38:4E:75:A0 public
    Service: ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6
    Characteristic: ebe0ccc1-7a0a-4b0c-8a1a-6ff2997da3a6
    C: BluetoothRemoteGATTCharacteristic: {
      "uuid": "ebe0ccc1-7a0a-4b0c-8a1a-6ff2997da3a6",
      "handle_value": 54, "handle_decl": 53,
      "properties": { "broadcast": false, "read": true, "writeWithoutResponse": false, "write": false,
        "notify": true, "indicate": false, "authenticatedSignedWrites": false }
     }
    Done!
    temp: 2484  Hum: 53
    temp: 2487  Hum: 53
    temp: 2486  Hum: 53
    

    Thanks for the inspiration.

  • in Interfacing
    Avatar for gerardwr

    BTW : My device is a Xiaomi BLE Thermometer type LYWSD03MMC

  • in Interfacing
    Avatar for gerardwr

    Hi,

    I have the same error as the topic starter, not sure if my problem is related, I'm rather new to Espruino/BLE so it may be a "user error".

    Here's my code, and the output it produces. It seems to run OK until the point when Notifications are enabled:

    var d;
    var out="";
    
    function getData(){
      print("Getting data now");
      g.drawString("Getting data now",0,60);
        NRF.connect("A4:C1:38:4E:75:A0 public").then(function(device) {
          print("Device connected:",device.device.id);
          out=device.device.id;
          g.drawString(out,0,80);
          d=device;
          return d.getPrimaryService("EBE0CCB0-7A0A-4B0C-­8A1A-6FF2997DA3A6");
        }).then(function(s) {
          out=s.uuid;
          g.drawString(out,0,105);
          if(s) { print("Service:",s.uuid); }
          else { print("S-error"); }
          return s.getCharacteristic("EBE0CCC1-7A0A-4B0C-­8A1A-6FF2997DA3A6");
        }).then(function(c) {
          print("Characteristic:",c.uuid);
          print("C:",c);
          out=c.uuid;
          g.drawString(out,0,130);
          c.on('characteristicvaluechanged', function(event) {
            buf =E.toString(event.target.value.buffer);
            g.drawString(buf,0,155);
            print(buf);
            print(event.target.value.buffer);
            // For 26.0 degrees and 54% is like : new Uint8Array([47, 10, 54, 98, 10]).buffer
            b=event.target.value.buffer;
            temp=b[1]*256+b[0];
            hum=b[2];
            print("temp:",temp, " Hum:",hum);
          }); // c.on
          return c.startNotifications();
        }).then(function() {
        console.log("Done!");
    
      });
    } // end getData function
    
    
    
    setWatch(function(){
      print("Bangle setwatch on TOP button activated");
      g.clear();
      g.setFont("Vector",15);
      getData();
    },BTN ,{ repeat:true,debounce:25 }
    );
    
    /*
    WEBIDE OUTPUT
    
                     _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v06 (c) 2019 G.Williams
    >
    Bangle setwatch on TOP button activated
    Getting data now
    Device connected: A4:C1:38:4E:75:A0 public
    Service: ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6
    Characteristic: ebe0ccc1-7a0a-4b0c-8a1a-6ff2997da3a6
    C: BluetoothRemoteGATTCharacteristic: {
      "uuid": "ebe0ccc1-7a0a-4b0c-8a1a-6ff2997da3a6",
      "handle_value": 54, "handle_decl": 53,
      "properties": { "broadcast": false, "read": true, "writeWithoutResponse": false, "write": false,
        "notify": true, "indicate": false, "authenticatedSignedWrites": false }
     }
    Uncaught Error: Unhandled promise rejection: CCCD Handle not found
    > 
    
    */
    

    The NrfConnect output for the Notification is below.

    I know the handle for the notification is 0x0038. When I connect to the device using RPI-gatttool using this handle it starts Notifications immediately.:

    pi@raspberrypi3:~/Mydata/python/Xiaomi $ gatttool -b a4:c1:38:4e:75:a0 --char-write-req --handle='0x0038' --value="0100" --listen
    Characteristic value was written successfully
    Notification handle = 0x0036 value: c5 09 3a 4e 0a 
    Notification handle = 0x0036 value: c4 09 39 4e 0a 
    

    Do I need to specify this handle specifically before using startNotifcations, and if so, how do I do that?

    Any help is welcome.

  • in JavaScript
    Avatar for gerardwr

    Thanks for the extensive explanation, sounds like a perfect addition for the reference. It's clear for me now.

    Coming from other languages it feels "natural" to start with an "open" command, so that's the reason why I chose Storagefile in the 1st place.

    This says it all!

    Normal Storage functions are what I'd recommend you use for basically everything unless you intend to append textual data (eg a log file). They're much more efficient to write and read.

  • in JavaScript
    Avatar for gerardwr

    When I started using Espruino a few weeks ago, I was "fresh" re. Espruino. I found the extensive description really confusing. So I just picked one.

    Now being a somewhat "less fresh" user I still wonder why there are 2 different file types. I read and reread the documentation, and still have no idea why the differences. It's probably me .....

    Just making sure, my posts were not meant as a gripe, but an attempt to add to the discusion that @MaBe kicked of.

  • in JavaScript
    Avatar for gerardwr

    Tested my code once more to verify that both news.txt and news.txt\1 are recognised.
    IT DOES NOT :O

    var Storage = require("Storage");
    l=Storage.list();
    print(l);
    function exists(name){
      return Boolean(Storage.open(name,"r").addr);
    }
    print(exists("news.txt"));
    print(exists("news.txt\1"));
    print(exists("nonews.txt"));
    print(exists("ABC.txt"));
    

    Output is:

    [
    "news.txt\1",
    "weath0.txt\1",
    "weath1.txt\1",
    "stocks.txt\1",
    "messages.txt\1",
    "ABC.txt"
    ]
    true
    false
    false
    false

    The mix of the 2 storage versions does not feel like a blessing anymore :)

  • in JavaScript
    Avatar for gerardwr

    When I check for files without an added chunk number (f.i. file ABC.txt) it is recognised perfectly with your code, output is:

    [
    "news.txt\1",
    "weath0.txt\1",
    "weath1.txt\1",
    "stocks.txt\1",
    "messages.txt\1",
    "ABC.txt"
    ]
    exists

    As @fanoush explained there are 2 methods to store a file, I happened to use the files with the added chunk number.

  • in JavaScript
    Avatar for gerardwr

    Fair enough @MaBe but news.txt\1 is not recognised either.

    s = require('Storage');
    print(s.list());
    filename = 'news.txt\1';
    if (s.read(filename)!==undefined) {
      print("exists");
    } else {
      print("does not exists");
    }
    

    Output is:

    [
    "news.txt\1",
    "weath0.txt\1",
    "weath1.txt\1",
    "stocks.txt\1",
    "messages.txt\1"
    ]
    does not exists

  • in JavaScript
    Avatar for gerardwr

    OK, thanks, but all of my files have a .txt extension, and those are not recognised by your code :(

    s = require('Storage');
    
    print(s.list());
    
    filename = 'news.txt';
    if (s.read(filename)!==undefined) {
      print("exists");
    } else {
      print("does not exists");
    }
    

    Output is:

    [
    "news.txt\1",
    "weath0.txt\1",
    "weath1.txt\1",
    "stocks.txt\1",
    "messages.txt\1"
    ]
    does not exists

Actions