LateralView / ios-limabandsdk

A client library for managing different brands of Bluetooth wristband devices
MIT License
6 stars 2 forks source link

Mi Band 2 not found as device #1

Open lordinferno1 opened 6 years ago

lordinferno1 commented 6 years ago

It looks that the scan method is not working since it doesnt find any "Mi Band 2" device, I tried setting filterBySignalLevel to false and true and changing the rssiFilterValue but it never finds a device.

leandrinux commented 6 years ago

Hi! In the FitnessDeviceManager file you will find a line of code that says the following:

let isValidDevice = (isConnectable == true) && isValidName && passesSignalFilter

I suggest you to place a breakpoint there so you will be able to know which one of the three criteria is causing your device not to be recognized as a MiBand2 wristband. I'm guessing this might have something to do with the name that the wristband is using when it advertises itself. In FitnessDeviceFactory there's a list of valid prefixes, you could add your band's name in there for testing purposes. Right now the SDK will recognize any band with a name that starts with MI.

Getting this to work requires some trial and error since even similar wristbands might have slight differences that produce these errors.

lordinferno1 commented 6 years ago

I couldnt test what you wrote, but the band started to appear once I disconnected it from Settings->Bluetooth. Im not sure when did it connect to the iPhone since it was the first time I used it.

The only problem I have now is that once it is connected I try to use the FitnessDevice.initialize method, it always fails during the pair operation, I debugged and saw that there is a point when this function is called

if let characteristic = self.characteristic(serviceUUID: serviceUUID, UUID: characteristicUUID)

and the service with the UUID(FEE0) is found but the characteristic with UUID(FF0F) isnt, so I cannot retrieve any other information.

Could the uuid for the characteristic changed to another one? These are the characteristics found for the service "FEE0":

leandrinux commented 6 years ago

FitnessDevice is an abstract class, so you should check what's going on in the MibandDevice file instead. In my experience, if you don't go through the entire initialization process what's going to happen is that the wristband will work for a while, then automatically disconnect.

Each of the operations of the initialization process are implemented in separate operation files such as MibandOperationPair. I believe it's possible that there are some firmware differences between the band you're using and the one I used. I don't have the band right now so I can't give you the list of services & characteristics that I have available. I'd try commenting out the self.pair.execute call of the initialize method and move forward with the rest of the process. You could also comment out getDeviceInfo and setUserInfo (you only need that for certain operations such as obtaining the history of steps).

For debugging I used an iOS app called LightBlue Explorer, it's quite powerful and it helps a lot in understanding how the band works.