Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto reconnect #405

Merged
merged 7 commits into from
Dec 7, 2022
Merged

Auto reconnect #405

merged 7 commits into from
Dec 7, 2022

Conversation

doudar
Copy link
Owner

@doudar doudar commented Nov 27, 2022

This will attempt a scan/connect if no devices are set to "any" and any device NOT set to "none" is disconnected. Interval between scans is ~30 seconds.

Here's an initial firmware. Not much testing done yet. So far it seems to scan occasionally and not crash :)

As always, extract the firmware.zip, admin/admin and make sure it's named exactly firmware.bin for upload.

edit: see comments below for the latest build of the firmware from this branch.

@doudar
Copy link
Owner Author

doudar commented Nov 27, 2022

limited testing - it works pretty good so far. I'll try a regular ride with it here and make sure all is okay, then we should do some exception testing.

@doudar
Copy link
Owner Author

doudar commented Nov 27, 2022

Working well so far. one potential issue that needs to be addressed is if you have a device configured (i.e. a hr monitor) and the battery were to go dead mid ride, the remaining BLE communication to the client nd server is severely disrupted as it attempts reconnects.

I think I might be able to find a solution for this.

@doudar
Copy link
Owner Author

doudar commented Nov 27, 2022

It's better by increasing the connection timeout and decreasing the scan time. The issue is the initial scan needs to be fairly long to catch all devices on the first try. I think I can get it without interruption if I separate the scan times into two different timings. Say a 3 second scan for this method, and a 10 second scan time for other processes. At 3 seconds, we may not catch the device we're looking for on the first scan but this isn't an issue since we automatically re-scan.

@doudar
Copy link
Owner Author

doudar commented Nov 28, 2022

It's better by increasing the connection timeout and decreasing the scan time. The issue is the initial scan needs to be fairly long to catch all devices on the first try. I think I can get it without interruption if I separate the scan times into two different timings. Say a 3 second scan for this method, and a 10 second scan time for other processes. At 3 seconds, we may not catch the device we're looking for on the first scan but this isn't an issue since we automatically re-scan.

fixed this. new binary vv
EDIT: See newest binary lower in the comments

@eMadman
Copy link
Collaborator

eMadman commented Nov 29, 2022

Bench test seems to work well. Test procedure:
Start with connection to a PM, ensure the PM is selected in the BT devices list
Pull power on PM, monitor logs --> confirmed that it's always polling for a new connection

power on PM - SS2K reconnected automatically within ~30 seconds.

@eMadman
Copy link
Collaborator

eMadman commented Nov 29, 2022

Test #2:

Ride in Mywhoosh with PM & HRM
Disconnect HRM - verify it tries to reconnect every so often
Turn on HRM - verify automatic reconnect

@d-nx
Copy link

d-nx commented Dec 1, 2022

Tested the re-connect feature with my Echelon Sport:

Steps Taken:

  1. Set "Select New Power Meter:" to any
  2. Save Dropdowns
  3. Scan/Connect
  4. SS2K connects to Bike
  5. Disconnect power to Bike
  6. Re-Connect power to Bike, SS2K connects to bike automatically

@doudar
Copy link
Owner Author

doudar commented Dec 1, 2022

Tested the re-connect feature with my Echelon Sport:

Steps Taken:

  1. Set "Select New Power Meter:" to any

  2. Save Dropdowns

  3. Scan/Connect

  4. SS2K connects to Bike

  5. Disconnect power to Bike

  6. Re-Connect power to Bike, SS2K connects to bike automatically

Nice!

Is this ready to be merged into Develop or should we make changes or require further testing?

@d-nx
Copy link

d-nx commented Dec 2, 2022

Tested the re-connect feature with my Echelon Sport:
Steps Taken:

  1. Set "Select New Power Meter:" to any
  2. Save Dropdowns
  3. Scan/Connect
  4. SS2K connects to Bike
  5. Disconnect power to Bike
  6. Re-Connect power to Bike, SS2K connects to bike automatically

Nice!

Is this ready to be merged into Develop or should we make changes or require further testing?

The only 'weird' thing I noticed was that my bike's name didn't show up under power. Even though it connected, the name didn't show up on the dropdown.

IMO it works. Send it!

@doudar
Copy link
Owner Author

doudar commented Dec 2, 2022

Tested the re-connect feature with my Echelon Sport:
Steps Taken:

  1. Set "Select New Power Meter:" to any
  2. Save Dropdowns
  3. Scan/Connect
  4. SS2K connects to Bike
  5. Disconnect power to Bike
  6. Re-Connect power to Bike, SS2K connects to bike automatically

Nice!
Is this ready to be merged into Develop or should we make changes or require further testing?

The only 'weird' thing I noticed was that my bike's name didn't show up under power. Even though it connected, the name didn't show up on the dropdown.

IMO it works. Send it!

Thx! The BLE names are a little different issue I’ll have to fix in the http server. Right now they’re read from only the variable that holds devices found during the (last) scan. If a device is actively connected, it won’t be found during the scan. I think I could fix this by simply adding saved devices to that string before sending. It will occasionally result in duplicates in the list but that’s better than the problem you describe.

@doudar
Copy link
Owner Author

doudar commented Dec 2, 2022

@d-nx & @eMadman , I fixed bluetooth scanner.html according to the issue by @d-nx . In order to test it, you can manually upload bluetoothscanner.html from this branch via the firmware updater web page. https://github.com/doudar/SmartSpin2k/blob/auto_reconnect/data/bluetoothscanner.html

@d-nx
Copy link

d-nx commented Dec 2, 2022

@d-nx & @eMadman , I fixed bluetooth scanner.html according to the issue by @d-nx . In order to test it, you can manually upload bluetoothscanner.html from this branch via the firmware updater web page. https://github.com/doudar/SmartSpin2k/blob/auto_reconnect/data/bluetoothscanner.html

I updated the .html file but I'm still seeing the same issue:

Screen Shot 2022-12-02 at 2 48 02 PM

@doudar
Copy link
Owner Author

doudar commented Dec 2, 2022

Ahh! Thanks for the picture. I remember this issue now. It's because the html is only looking for the cycling power characteristic for PMs. Since you have an Echelon, it's not getting added to the drop-down. I think this is an easy fix. I'll see if I can add it tonight.

@doudar
Copy link
Owner Author

doudar commented Dec 2, 2022

@d-nx , please let me know if this displays your Echelon after uploading the bluetoothscanner.html.

You'll probably need to reboot as well to clear any active connections.

https://github.com/doudar/SmartSpin2k/blob/auto_reconnect/data/bluetoothscanner.html

@d-nx
Copy link

d-nx commented Dec 2, 2022

@d-nx , please let me know if this displays your Echelon after uploading the bluetoothscanner.html.

You'll probably need to reboot as well to clear any active connections.

https://github.com/doudar/SmartSpin2k/blob/auto_reconnect/data/bluetoothscanner.html

It's working a bit better but now I have some duplicates:
Screen Shot 2022-12-02 at 5 37 57 PM

Cleared active connections, rebooted but still see doubles.

@d-nx
Copy link

d-nx commented Dec 2, 2022

Also, it's not allowing me to select 'none' so I can disconnect from the bike.

@doudar
Copy link
Owner Author

doudar commented Dec 2, 2022

Also, it's not allowing me to select 'none' so I can disconnect from the bike.

I can't seem to duplicate this - is there a certain browser you're using? I've tried on Windows Chrome, Edge, and IPhone Safari and Chrome.

As far as the duplicates, I'll have to write a javascript loop in bluetoothscanner.html to remove duplicates in the list. I'm not too concerned about it.

Super happy the Echelon is showing on the list for you. That was an easy fix.

@d-nx
Copy link

d-nx commented Dec 3, 2022

Also, it's not allowing me to select 'none' so I can disconnect from the bike.

I can't seem to duplicate this - is there a certain browser you're using? I've tried on Windows Chrome, Edge, and IPhone Safari and Chrome.

As far as the duplicates, I'll have to write a javascript loop in bluetoothscanner.html to remove duplicates in the list. I'm not too concerned about it.

Super happy the Echelon is showing on the list for you. That was an easy fix.

I'm using Chrome. The behaviour is as follows:

I connect to the bike by selecting "Any" then "Save Dropdowns", after that the bike beeps confirming connection and the name appears on the dropdown menu of SS2K.

Now, I would like to select "None" so the bike disconnects from SS2K (So I can use with a different app), but after hitting "Save Dropdowns" it's still connected. Maybe this has something to do with the new reconnect feature? not sure how to make ss2k disconnect from the bike at this point.

@doudar
Copy link
Owner Author

doudar commented Dec 3, 2022

Okay, so it will save "none" but the bike doesn't disconnect, correct?

Does it disconnect (and stay disconnected) if you reboot the SS2K after selecting none?

@d-nx
Copy link

d-nx commented Dec 3, 2022

It doesn't save 'none' the echelon remains selected in the dropdown. Ant the bike remains connected to ss2k.

Selecting "None" then "Saving Dropdown" = Echelon remains in the dropdown list, and bike remains connected.
Selecting "None" then "Saving Dropdown" then Rebooting= Echelon remains in the dropdown list, but bike is not connected automatically.

@doudar
Copy link
Owner Author

doudar commented Dec 6, 2022

It doesn't save 'none' the echelon remains selected in the dropdown. Ant the bike remains connected to ss2k.

Selecting "None" then "Saving Dropdown" = Echelon remains in the dropdown list, and bike remains connected. Selecting "None" then "Saving Dropdown" then Rebooting= Echelon remains in the dropdown list, but bike is not connected automatically.

Thanks! I’ll see if I can work on that. I might just have it reboot if none is selected.

@doudar
Copy link
Owner Author

doudar commented Dec 7, 2022

@d-nx I've changed it so that whenever a BLE device is selected that's different from the currently connected one it will reboot to apply the settings. It's the easiest way to apply the changes that need to be done and it happens pretty fast as long as the WiFi doesn't take a long time to reconnect.

Newest binary attached.

firmware.zip

@doudar
Copy link
Owner Author

doudar commented Dec 7, 2022

@eMadman see above - any comments?

@eMadman
Copy link
Collaborator

eMadman commented Dec 7, 2022

@doudar device reboots when selecting "None" from the dropdown then quickly finds an available connection. Seems to be working as intended

Copy link
Collaborator

@eMadman eMadman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed testing on bench and bike

@doudar doudar merged commit 1b77d6c into develop Dec 7, 2022
@doudar doudar deleted the auto_reconnect branch December 7, 2022 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants