Mi Band 2 disconnects automatically and does not reconnect automatically even after coming in range and also I have enabled the reconnect automatically on the settings page.
// either we've been disconnected because the device is out of range
// or because of an explicit @{link #disconnect())
// To support automatic reconnection, we keep the mBluetoothGatt instance
// alive (we do not close() it). Unfortunately, we sometimes have problems
// reconnecting automatically, so we try to fix this by re-creating mBluetoothGatt.
// Not sure if this actually works without re-initializing the device...
Rather than using the BluetoothGatt instance to reconnect automatically, we can save the MAC address of the band when first connected and then reconnect automatically using that MAC address.
I have this idea but don't know how to implement it.
I am having this same problem with my Pebble2. The watch disconnects, and I have to manually reconnect even though the reconnect automatically option in Gadgebridge is selected. Disconnection doesn't seem to be related to anything that I'm doing on the phone. It happens multiple times over the course of the day.
Android version 4.4.
My android version is 6.0
Mine is 7.1.1.
I seem to be having problems with automatic reconnection as well.
It reconnects for me but not after a certain point. It might be the retry amount is exceeded too quickly.
Hmm, today GadgetBridge got OOM killed when restarted, it did not reconnect. I can probably provide logs if needed. Using Pebble Time.
@Avamander Can you please provide the Log file ? Let's see what's in there. For Mi2 I might have the solution. If it can work on every device than i'll provide the code.
03-11 18:09:27.333 897 3785 I ActivityManager: vis IF 11178 kB: nodomain.freeyourgadget.gadgetbridge (15286) service
03-11 18:09:27.333 897 3785 I ActivityManager: nodomain.freeyourgadget.gadgetbridge/.externalevents.NotificationListener<=Proc{897:system/1000}
03-11 18:17:44.698 897 3934 I ActivityManager: vis IF 11519 kB: nodomain.freeyourgadget.gadgetbridge (15286) service
03-11 18:17:44.698 897 3934 I ActivityManager: nodomain.freeyourgadget.gadgetbridge/.externalevents.NotificationListener<=Proc{897:system/1000}
03-11 18:21:00.175 897 1299 I ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=nodomain.freeyourgadget.gadgetbridge/.activities.ControlCenter bnds=[224,880][360,1064] (has extras)} from pid 4264
03-11 18:22:50.093 897 5645 I ActivityManager: vis IF 18385 kB: nodomain.freeyourgadget.gadgetbridge (15286) service
03-11 18:22:50.093 897 5645 I ActivityManager: nodomain.freeyourgadget.gadgetbridge/.externalevents.NotificationListener<=Proc{897:system/1000}
03-11 18:27:20.799 897 2890 I ActivityManager: START u0 {flg=0x10008000 cmp=nodomain.freeyourgadget.gadgetbridge/.activities.ControlCenter bnds=[0,102][720,230]} from pid -1
03-11 18:27:26.485 897 908 I ActivityManager: START u0 {cmp=nodomain.freeyourgadget.gadgetbridge/.activities.appmanager.AppManagerActivity (has extras)} from pid 15286
03-11 18:27:32.872 897 1234 I ActivityManager: START u0 {cmp=nodomain.freeyourgadget.gadgetbridge/.activities.ExternalPebbleJSActivity (has extras)} from pid 15286
03-11 18:29:26.854 897 7968 I ActivityManager: vis T 44769 kB: nodomain.freeyourgadget.gadgetbridge (15286) service
03-11 18:29:26.854 897 7968 I ActivityManager: nodomain.freeyourgadget.gadgetbridge/.externalevents.NotificationListener<=Proc{897:system/1000}
03-11 18:35:19.563 897 9209 I ActivityManager: vis IF 35489 kB: nodomain.freeyourgadget.gadgetbridge (15286) service
03-11 18:35:19.563 897 9209 I ActivityManager: nodomain.freeyourgadget.gadgetbridge/.externalevents.NotificationListener<=Proc{897:system/1000}
03-11 18:39:20.013 897 1846 I ActivityManager: Process nodomain.freeyourgadget.gadgetbridge (pid 15286) has died.
03-11 18:39:20.013 897 1846 W ActivityManager: Scheduling restart of crashed service nodomain.freeyourgadget.gadgetbridge/.service.DeviceCommunicationService in 1000ms
03-11 18:39:20.013 897 1846 W ActivityManager: Scheduling restart of crashed service nodomain.freeyourgadget.gadgetbridge/.externalevents.NotificationListener in 11000ms
03-11 18:39:20.023 897 897 V NotificationService: notification listener connection lost: ComponentInfo{nodomain.freeyourgadget.gadgetbridge/nodomain.freeyourgadget.gadgetbridge.externalevents.NotificationListener}
03-11 18:39:20.033 897 1126 I WindowState: WIN DEATH: Window{42df4e70 u0 nodomain.freeyourgadget.gadgetbridge/nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter}
03-11 18:39:20.103 897 1360 I WindowState: WIN DEATH: Window{42e67ca8 u0 nodomain.freeyourgadget.gadgetbridge/nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AppManagerActivity}
03-11 18:39:21.024 897 928 I ActivityManager: Start proc nodomain.freeyourgadget.gadgetbridge for service nodomain.freeyourgadget.gadgetbridge/.service.DeviceCommunicationService: pid=9449 uid=10510 gids={50510, 3002, 3001, 1028}
03-11 18:41:23.897 897 9586 I ActivityManager: vis IF 13758 kB: nodomain.freeyourgadget.gadgetbridge (9449) service
03-11 18:41:23.897 897 9586 I ActivityManager: nodomain.freeyourgadget.gadgetbridge/.externalevents.NotificationListener<=Proc{897:system/1000}
03-11 18:47:22.008 897 10842 I ActivityManager: vis IF 11290 kB: nodomain.freeyourgadget.gadgetbridge (9449) service
03-11 18:47:22.008 897 10842 I ActivityManager: nodomain.freeyourgadget.gadgetbridge/.externalevents.NotificationListener<=Proc{897:system/1000}
If more is needed, I'll have to wait it to reoccur.
@yash-bhavsar please do provide your code: if you think it helps even one single device we can then make sure it does no harm to the other devices.
@danielegobbetti I was to find the workaround by using the MAC address idea but, no it failed so now back to square one
I'm experiencing this, too, with a Mi Band 2. In the Pebble tab there is a possibility to select the amount of reconnects. Would it be possible to implement this for the Mi, too?
I had this problem few times with Mi Band 1S, very rarely but still.
PROBLEM SOLVED.................................
ok guys here's the catch. I bought my band 2 three days back and I immediately faced this issue. it was disconnecting in few seconds upto few minutes. I checked internet for this problem and most people were talking about 4.1 Bluetooth etc.
I checked some links and tried unpairing etc. Tried "Don't Optimize Battery" on Mi Fit App from Settings -> Battery. It didn't worked. Then I tried installing an app which was focused to keep the Bluetooth connection forcefully up with the band. But nothing worked and I was really frustrated.
Then it came to my mind that its not the Bluetooth but its the Mi Fit App that it being getting killed. Though the "Don't Optimize Battery" on Mi Fit App should have worked but there was something else. There was a default app manager installed on my phone which was cleaning memory, I went into its setting and unchecked the Mi Fit App from being cleaned up. It was of some help but still app was getting killed. Then I looked further and found there was a default battery optimization app which was killing the app when phone was locked/sleep. I unchecked My Fit App from there as well and till then 1 or 2 disconnections in 3 days probably when I was away from phone.
So look for app managers and battery optimization softwares on your phones which are killing Mi Fit App.
Good Luck
Infinix Note 3 Prox - Android 7.0
@tausif1 thanks for the hint! I'm sure there are more reasons for reconnection problems, but it's good to have one less :+1:
I can confirm reconnections for multiple reasons.
Battery savers is one thing at least in Miui Roms.
Miui battery saver fails to exclude gadgetbridge and kills services even if you go to the settings and exclude it (no restrictions) and also add it to Autostart permissions.
I have found a solution to this.
The problem seems to be in the AndroidManifest.xml file.
All activities which are mentioned as ".activity..." instead of full package names fail to be detected.
Replacing all ".entries" in Manifest with complete package name solves this.
(for example ".GBActivity" should be replaced by "nodomain.freeyourgadget.gadgetbridge.GBactivity" etc)
I also discovered that this is power related issue. If device is kept awake no disconnects or delays occur.
I have tried to solve this by adding Wakelock to NotificationListenerService with some good results.
If the cpu sleeps, then notificatins on mi band delay or are not received.
I also find a lot of "Failed to find mounted volume for /dev/null/Android/data/nodomain.freeyourgadget.gadgetbridge/files" errors I don;t know if this crashes something.
I am running Android 6.0.1 miui Global 8.2.4 rom on a Redmi 4 Prime.
I don't know how the MIUI battery saver works, but even if it kills all Gadgetbridge activities, the connection should be kept alive because it is done in a foreground service. All listeners are also part of the service, so should not get killed.
The shorthand notification for class names starting with '.' is explicitly supported and documented by Android, so I would be surprised if MIUI would fail to handle that.
See https://developer.android.com/guide/topics/manifest/activity-element.html#nm
Also see https://forum.xda-developers.com/redmi-note-3/how-to/guide-redmi-note-3-sd-mtk-multi-tasking-t3358433 for tips configuring MIUI.
cpfeiffer I doubt they know what they are doing in miui.
the logs are clear miui kills the tasks due to security. (not allowed to restart/autostart etc).
I will check it again but as i say it solved my problem killing the services after phone went to sleep and not restarting/autostarting on boot.
I connect my mi band 2 and checknotifications.
I then put it in the microwave (disconnects)
I send messages to my phone and see state NOT_CONNECTED.
I then move the band next to phone and send messages.
discovery starts, state changes to CONNECTED.
the band fails to keep connection and disconnects, tries many times in every message.
If I open the ui and click on the Not Connected message it connects fine.
Ok so autoreconnect fails clearly.
this is what autorecoonect does.
6759 I nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: Sending notification to MiBand2
07-27 00:37:05.968 26759 26759 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: about to add: 12:37:05 a.m.: Transaction task: generic received with 0 actions
07-27 00:37:05.981 26759 26759 W nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate: no cached services available for MI Band 2: F9:75:FF:C1:34:2D (UNKNOWN)
07-27 00:37:06.016 26759 26759 I nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService: Setting broadcast receivers to: true
07-27 00:37:06.022 1896 14859 D StatusBar: onNotificationPosted: Key: 0|nodomain.freeyourgadget.gadgetbridge|1|null|10260 GroupKey: 0|nodomain.freeyourgadget.gadgetbridge|1|null|10260 Connected: true
07-27 00:37:06.022 1896 1896 D PhoneStatusBar: updateNotification pkg=nodomain.freeyourgadget.gadgetbridge;id=1
07-27 00:37:08.241 26759 26770 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: connection state change, newState: 2 (success)
07-27 00:37:08.241 26759 26770 I nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: Connected to GATT server.
07-27 00:37:08.241 26759 26770 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: new device connection state: CONNECTED
07-27 00:37:08.243 26759 26792 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: About to run action: 27 July, 00:37: CheckInitializedAction: aborting? false
07-27 00:37:08.244 26759 26792 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: About to run action: 27 July, 00:37: NotifyAction on characteristic: 00000009-0000-3512-2118-0009af100700
07-27 00:37:08.245 26759 26770 I nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: Attempting to start service discovery:true
07-27 00:37:08.246 26759 26792 D nodomain.freeyourgadget.gadgetbridge.service.btle.actions.NotifyAction: use NOTIFICATION
07-27 00:37:08.268 26759 26770 D nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: discovered supported service: Generic Access: 00001800-0000-1000-8000-00805f9b34fb
07-27 00:37:08.268 26759 26770 I nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: characteristic: Device Name: 00002a00-0000-1000-8000-00805f9b34fb
...
...
07-27 00:37:08.275 26759 26770 I nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: characteristic: Unknown Characteristic: 0000fed3-0000-1000-8000-00805f9b34fb
07-27 00:37:08.275 26759 26770 I nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: characteristic: Unknown Characteristic: 0000fec1-0000-3512-2118-0009af100700
07-27 00:37:08.275 26759 26770 W nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder: Unable to notify characteristic: null
07-27 00:37:08.275 26759 26770 W nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder: Unable to notify characteristic: null
07-27 00:37:08.276 26759 26770 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: about to add: 12:37:08 a.m.: Transaction task: Initializing device with 3 actions
07-27 00:37:08.282 26759 26759 W nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate: no cached services available for MI Band 2: F9:75:FF:C1:34:2D (UNKNOWN)
07-27 00:37:08.344 26759 26759 I nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService: Setting broadcast receivers to: true
07-27 00:37:08.348 26759 26759 I nodomain.freeyourgadget.gadgetbridge.externalevents.BluetoothConnectReceiver: got connection attempt
07-27 00:37:08.352 26759 26759 I nodomain.freeyourgadget.gadgetbridge.externalevents.BluetoothConnectReceiver: won't connect to F9:75:FF:C1:34:2D(MI Band 2)
07-27 00:37:08.354 1896 1909 D StatusBar: onNotificationPosted: Key: 0|nodomain.freeyourgadget.gadgetbridge|1|null|10260 GroupKey: 0|nodomain.freeyourgadget.gadgetbridge|1|null|10260 Connected: true
07-27 00:37:08.355 1896 1896 D PhoneStatusBar: updateNotification pkg=nodomain.freeyourgadget.gadgetbridge;id=1
07-27 00:37:26.849 26759 26769 I nodomain.freeyourgadget.gadgetbridge.externalevents.NotificationListener: Processing notification from source com.miui.securitycenter with flags
and this is what clicking the ui does
7-27 00:37:38.872 1896 1896 D PhoneStatusBar: updateNotification pkg=nodomain.freeyourgadget.gadgetbridge;id=1
07-27 00:37:45.010 26759 26759 D nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService: Service startcommand: nodomain.freeyourgadget.gadgetbridge.devices.action.connect
07-27 00:37:45.018 26759 26759 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: disconnect()
07-27 00:37:45.019 26759 26792 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: Thread interrupted
07-27 00:37:45.019 26759 26792 I nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: Queue Dispatch Thread terminated.
07-27 00:37:45.021 26759 26759 I nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: Attempting to connect to MI Band 2
07-27 00:37:45.023 26759 28601 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: Queue Dispatch Thread started.
07-27 00:37:45.027 26759 26759 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: new device connection state: CONNECTING
07-27 00:37:45.051 2127 2200 W WtProcessController: do not trim { PackageName :nodomain.freeyourgadget.gadgetbridge Pid: 26759 Uid: 10260 Start by: activity Score:100 Old score:100 state:0 mBackgroundTimeInMillis:0 WakelockCount:0 wakelogsize:0 ActivityDestroied:false Activity size: 1 PackageInfo:{WhetstonePackageInfo#PacakgeName:nodomain.freeyourgadget.gadgetbridge uid:10260 uiMemoryThresold:0 nonUiMemoryThresold:0 Flag:5312,0x14c0 [,TRIMHEAPS,SOFT_RESET,ZRAM,FLAG_DEAL_SCHEDULE] Type:0[] } tasknum:302}
07-27 00:37:45.064 26759 26759 W nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate: no cached services available for MI Band 2: F9:75:FF:C1:34:2D (UNKNOWN)
07-27 00:37:45.158 26759 26759 I nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService: Setting broadcast receivers to: true
07-27 00:37:45.170 1896 3072 D StatusBar: onNotificationPosted: Key: 0|nodomain.freeyourgadget.gadgetbridge|1|null|10260 GroupKey: 0|nodomain.freeyourgadget.gadgetbridge|1|null|10260 Connected: true
07-27 00:37:45.170 1896 1896 D PhoneStatusBar: updateNotification pkg=nodomain.freeyourgadget.gadgetbridge;id=1
07-27 00:37:46.952 1584 2146 D PerfShielderService: nodomain.freeyourgadget.gadgetbridge|nodomain.freeyourgadget.gadgetbridge/nodomain.freeyourgadget.gadgetbridge.activities.ControlCenterv2|236|19725610696075|148|0
07-27 00:37:49.485 26759 26769 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: connection state change, newState: 2 (success)
07-27 00:37:49.486 26759 26769 I nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: Connected to GATT server.
07-27 00:37:49.486 26759 26769 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: new device connection state: CONNECTED
07-27 00:37:49.488 26759 26759 I nodomain.freeyourgadget.gadgetbridge.externalevents.BluetoothConnectReceiver: got connection attempt
07-27 00:37:49.491 26759 26759 I nodomain.freeyourgadget.gadgetbridge.externalevents.BluetoothConnectReceiver: won't connect to F9:75:FF:C1:34:2D(MI Band 2)
07-27 00:37:49.494 26759 26769 I nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: Attempting to start service discovery:true
07-27 00:37:49.511 26759 26769 D nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: discovered supported service: Generic Access: 00001800-0000-1000-8000-00805f9b34fb
07-27 00:37:49.511 26759 26769 I nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: characteristic: Device Name: 00002a00-0000-1000-8000-00805f9b34fb
07-27 00:37:49.512 26759 26769 I nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: characteristic: Appearance: 00002a01-0000-1000-8000-00805f
....
805f9b34fb
07-27 00:37:49.518 26759 26769 I nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: characteristic: Unknown Characteristic: 0000fec1-0000-3512-2118-0009af100700
07-27 00:37:49.518 26759 26769 W nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder: Unable to notify characteristic: null
07-27 00:37:49.518 26759 26769 W nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder: Unable to notify characteristic: null
07-27 00:37:49.519 26759 26769 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: about to add: 12:37:49 a.m.: Transaction task: Initializing device with 3 actions
07-27 00:37:49.520 26759 28601 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: About to run action: 27 July, 00:37: NotifyAction on characteristic: 00000009-0000-3512-2118-0009af100700
07-27 00:37:49.522 26759 28601 D nodomain.freeyourgadget.gadgetbridge.service.btle.actions.NotifyAction: use NOTIFICATION
07-27 00:37:49.523 26759 26797 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: descriptor write: 00002902-0000-1000-8000-00805f9b34fb (success)
07-27 00:37:49.524 26759 28601 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: About to run action: 27 July, 00:37: SetDeviceStateAction to INITIALIZING
07-27 00:37:49.526 26759 28601 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: About to run action: 27 July, 00:37: WriteAction on characteristic: 00000009-0000-3512-2118-0009af100700
07-27 00:37:49.526 26759 28601 D nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WriteAction: writing to characteristic: 00000009-0000-3512-2118-0009af100700: 0x 2 0x 8
07-27 00:37:49.528 26759 26770 D nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue: characteristic write: 00000009-0000-3512-2118-0009af100700 (success)
07-27 00:37:49.528 26759 26770 I nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: KEY AES SEND
07-27 00:37:49.528 26759 26770 I nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: RECEIVED DATA WITH LENGTH: 2
07-27 00:37:49.528 26759 26770 W nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: DATA: 0x 2
07-27 00:37:49.528 26759 26770 W nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: DATA: 0x 8
07-27 00:37:49.529 26759 26759 W nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate: no cached services available for MI Band 2: F9:75:FF:C1:34:
The problem with ".activities" does not apply it's my mistake.
You have to exclude GB in System Settings->Permisions ->autostart and System Settings Battery->apps battery use, on Miui roms and after that, you have to reboot at least once. There is also a chance you need to check these settings again after upgrading. Otherwise you might have Miui killing the services after sleeping and not letting them restart. You can check this at your logs.
No problem in AndroidManiftest though.
But reconnect doesn't work, that I can verify. Problem seems to be rediscovery of band services after each try of reconnect. Connection attempt is made but Services are not yet rediscovered although address of mi band is the same, so reregistering fails. No cached services error is definitely related.
Can;t we just skip the discoverServices part excpet connectFirstTime (which happens every time the app starts) and keep cached services updated? Devices do not change characteristics that often. We can make connections a lot faster that way (about 5 secs). Or we might put an option/button to rediscover if problems. How can we keep an updated cache?
I ll mess with that for a bit today.
Good news today!
I solved the reconnect to mi band 2 problem!
Seems that in some devices even when you disconnect the socket the connection wont end because of the cache. This does not happen if you disconnect first with a new instance of btgatt
BluetoothGatt mBluetoothGatt = device.connectGatt(appContext, false, new BluetoothGattCallback() {
};);
mBluetoothGatt.disconnect();
(source)
I have added that code to BtlEqueue:connect() about line 178
synchronized (mGattMonitor) {
// connectGatt with true doesn't really work ;( too often connection problems
if (remoteDevice.getName().toString() == "Mi Band 2") {
BluetoothGatt mBluetoothGatt = remoteDevice.connectGatt(mContext, false, new BluetoothGattCallback() {
});
mBluetoothGatt.disconnect();
}
mBluetoothGatt = remoteDevice.connectGatt(mContext, false, internalGattCallback);
The band connects faster and reconnects everytime a notificationevent occurs or if disconnected.
To test it I just put it in the microwave..(with the microwave off!!!) until disconnection occurred and after 5 minutes put it next to the phone and send a message to my phone.
I did this multiple times, logs verify reconnection successful every time.
I don't know what happens with other devices but mi band 2 works.
Is there a better way to do this?
Happens to me with a pebble 2 and a oneplus 2 on android 7.1.2.
@lazarosfs Thanks for digging into this. Regarding your question
Is there a better way to do this?
Short answer: "It's complicated".
The former may cause connection-lags, I've seen that too. The latter is usually fast, but maybe made slow by the former.
So maybe we need to perform an explicit disconnect before we explicitly connect.
@Soundtoxin This is unrelated to Pebble, since it uses a different bluetooth stack.
I did find the connection attempts made from the band when it's near but never succeeds.
The band reconnects succesfully using the above patch but:
I haven't really understood why a simple "mBluetoothtGatt.disconnect()" before attempting to connect does not work on me, but the above posted code (BluetoothGatt mBluetoothGatt = remoteDevice.connectGatt(mContext, false, new BluetoothGattCallback() { }); mBluetoothGatt.disconnect(); ) works.
As I have mentioned in another thread I have solved some of these bugs in my own attempts.
If anyone wishes to give feedback on those new options I added please download and test apk from here
My sources are here
It is based on 0.19.2
Reconnect works, multiple notifications in 18 parts works, you have an option to exclude the Chat Icon and get sender and message contents immediately. You can also adjust max number of parts per message you want.
I added viber,whatsapp,gmail and it works also fine with sms and maybe others that i have not tested like fb and fb messenger.
It shows always the last unread message from viber and whatsapp, even if multiple are unread and does not repeat same messages (it keeps a 10 msg history) to avoid duplicate msgs.
I have mostly tested it using transliteration in which I only keep alphabet and numbers (no symbols , pipes, commas etc) to keep the message short.
I ll try try to create pulls for those.
Thank you all for your great work and I wish you all happy holidays from Greece!
For me auto reconnect works fine:
FW: 1.0.1.47
GB: 0.19.4
LineageOS 14.1 Android 7.1.2
Under Android Settings => Battery => Battery optimization => GB is not optimized.
Energy profile (dont know if this is only under lineage) is balance and auto optimize is disabled
Any chance someone can make a copy of this issue for the Pebble? You say it's a different Bluetooth stack, but I'm also getting constantly disconnected. I set reconnect retries to 2000 and it still doesn't reconnect properly. Even when I'm asleep (not moving, phone and watch are within 3 feet of each other the entire time) I find that I wake up to a disconnected watch. It's basically never connected anymore because I can't be bothered to check constantly if it's connected or not.
Hello,
I tried every version for almost a year and always had disconnection issues.
Disconnection happened immediately after a notification, and reconnection never happened.
I just installed version 0.20.2, and I was pleased to see this does not happen anymore!
I checked the changelog but did not see any obvious change that could explain this improvement.
Is there any change that can explain why my issue is fixed?
Posting it here because #878 was closed:
My Band 2 sometimes does not reconnect after the phone has been out of range. It connects immediately when I press the card in GadgetBridge. I don't think it's ever disconnected when the phone stays in range.
My log: https://paste.fedoraproject.org/paste/8ef7kgkQPQrYrvrK5T1KpA
Android: Stock 6.0.1 Samsung J510FN, Baseband version J510FNXWU2AQG1
Gadgetbridge version: 0.22.2
Band FW: 1.0.1.54, Mili_pro.ft and Mili_pro.ft.en installed
I have exactly the same problem as @tradej and here is my log file:
Essentially the reconnect seems to work under perfect conditions (mi band 2 stays nearby at all times, not much interference) but as soon as it gets out of range even for a short time, GadgetBridge just gives up and never tries again ever. That makes the reconnect pretty useless under real life conditions, at least in it's current form.
I'd just like to add this problem seems to be phone-specific because I have got a Nokia 5 now, and the problem is gone (it occasionally doesn't reconnect, but that happens like once a month).
Ah, interesting! Mine is a Samsung Galaxy S4 Mini LTE/International version (serranoltexx/GT-I9195) with Android 7.1.2 and LineageOS 14.1.
I'm wondering though, how is a CPU-based timer phone specific? Maybe GadgetBridge relies on the bluetooth stack a little too much and should do a manual timer to trigger things again if the bluetooth driver somehow forgets about the device, or something like that. (Sorry if that idea makes no sense, I'm just guessing wildly)
CPU or the respective manufacturer. A colleague of mine has a Huawei and it's all sorts of wonky too (Mi Band 2 too).
Well, buggy CPUs usually means crashes and other bad stuff for all applications and I have none of that, so I doubt it's that - but could be bluetooth, maybe? :man_shrugging: what I find a bit suspect is that I don't even see reconnect attempts later, it just seems to give up entirely. That does seem a little like a bug in the application logic of GadgetBridge.
Most helpful comment
Posting it here because #878 was closed:
My Band 2 sometimes does not reconnect after the phone has been out of range. It connects immediately when I press the card in GadgetBridge. I don't think it's ever disconnected when the phone stays in range.
My log: https://paste.fedoraproject.org/paste/8ef7kgkQPQrYrvrK5T1KpA
Android: Stock 6.0.1 Samsung J510FN, Baseband version J510FNXWU2AQG1
Gadgetbridge version: 0.22.2
Band FW: 1.0.1.54,
Mili_pro.ftandMili_pro.ft.eninstalled