jasongin / noble-uwp

Noble (Node.js Bluetooth LE) with Windows 10 UWP bindings
MIT License
83 stars 45 forks source link

Could not get localName in advertisement data? #62

Closed hanhdt closed 6 years ago

hanhdt commented 6 years ago

When I'm scanning devices, but get advertisement data without localName like this:

advertisement: { 
     localName: null,
     txPowerLevel: null,
     manufacturerData: undefined,
     serviceUuids: [ '1803', '1804' ],
     serviceData: [ {} ]
 }

Do I have any workaround for this?

Thanks.

jasongin commented 6 years ago

Typically the advertisement packets that are periodically broadcast for passive discovery do not include the name and some other details. But when you use noble-uwp to start scanning, it does an active scan, and it waits for a response to the active scan request (and that response typically does include the device name) before emitting a 'discover' event.

Are you seeing this behavior for all kinds of devices, or just a particular one?

hanhdt commented 6 years ago

Hi, Thanks for answering my question.

Yes, I understand. In fact, I tested with my specific hardware only. It's fine when I use with noble and ble adapter, I can see this. But not for noble-uwp.

Thanks.

jartholomew commented 6 years ago

Hi, I have encountered the same issue using noble-uwp in an electron app. As @hanhdt mentioned above, localName is null on peripheral discovery:

{  
   "localName":null,
   "txPowerLevel":4,
   "manufacturerData":{  
      "type":"Buffer",
      "data":[  107, 0, 47, 12, 64, 60  ]
   },
   "serviceUuids":[  "180d", "feee", "fea5"  ],
   "serviceData":[  {  }  ]
}

but if I write the advertisement object to the console:

console.dir(peripheral.advertisement);

the localName appears:

Object { 
   "localName": "Polar H10 34BE152A",
   "txPowerLevel":4,
   "manufacturerData":{  
      "type":"Buffer",
      "data":[  107, 0, 47, 12, 64, 60  ]
   },
   "serviceUuids":[  "180d", "feee", "fea5"  ],
   "serviceData":[  {  }  ]
}
jartholomew commented 6 years ago

i found a workaround from this post:

https://stackoverflow.com/questions/17546953/cant-access-object-property-even-though-it-exists-returns-undefined

setTimeout(function()
{
    var foo = peripheral; 

}, 100);
hanhdt commented 6 years ago

Yes, it works for me. I can get localName after deplayed periods.

Thank you @jartholomew and @jasongin .