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

Wifi + Bluetooth Coexistance #15

Open
atctwo opened this issue May 21, 2020 · 5 comments
Open

Wifi + Bluetooth Coexistance #15

atctwo opened this issue May 21, 2020 · 5 comments
Labels
bug Something isn't working long term todo major updates that will be done at some point, but will break everything os pertaining to the watch 2 system
Milestone

Comments

@atctwo
Copy link
Owner

atctwo commented May 21, 2020

Commit 9612d23 added Bluetooth support, but weird issues arise when you try to enable Wifi and Bluetooth at the same time. I used a separate test sketch and verified that you can run Wifi and BT at the same time on the ESP32, so i think that if you are running the watch 2 system and Wifi and Bluetooth, then the internal RAM is filled up.

I can think of a few workarounds for this, but I don't really know what the best option is. For now, I'm going to disable bluetooth until I think of a good idea. Here are the ideas I've had:

  • only support one communication method. Either Wifi or Bluetooth, but not both. If this happens, I'll probably keep wifi, and leave bluetooth disabled (but I won't remove the code)
  • ensure that only wifi or bluetooth are on at any given time. that is, when wifi is on, bluetooth isn't, and vice versa. This is difficult because I can't figure out how to deallocate the memory used by bluetooth once it has been initalised, and would be a perfect option.
  • Migrate the project to an ESP-IDF project. This would mean that I could set up the SDK using custom options, and I could set options to tell the BT and Wifi stacks to use external memory (this would be amazing). I've been working on this, but there are loads of really weird errors, so it might not be feasible.

This issue might take a while to solve. I'm going to do any Bluetooth stuff in the wifi_bt_coex branch, so new states and stuff can be worked on in the master branch (or another specialised branch).

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Also, i'm an idiot, and the commit that adds bluetooth support removes wifi profile support so when merging that branch remember this you idiot

@atctwo atctwo added bug Something isn't working long term todo major updates that will be done at some point, but will break everything os pertaining to the watch 2 system labels May 21, 2020
@atctwo atctwo added this to the long term milestone May 21, 2020
@atctwo
Copy link
Owner Author

atctwo commented May 27, 2020

Merged wifi_bt_coex, #16. Also, migrated to ESP-IDF (#17), so I might be able to set PSRAM options using make menuconfig now.

@atctwo
Copy link
Owner Author

atctwo commented May 28, 2020

commit 9b38f31 enabled bluetooth, but it still doesn't work. if bluetooth is enabled when wifi is enabled, it doesn't crash anymore, but it still breaks wifi.

@atctwo
Copy link
Owner Author

atctwo commented May 28, 2020

  • BleKeyboard creates a task which handles the server which isn't destroyed when Bluetooth is turned off. this could be related to why wifi breaks when bt is enabled (even if it's disabled after)
  • when blekeyboard tries to start the server, BLEDevice.cpp errors:
I (11609) BTDM_INIT: BT controller compile version [e989f20]

I (11616) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
[E][BLEDevice.cpp:363] init(): esp_bt_controller_enable: rc=258 Unknown ESP_ERR error

the return code in hex is 0x102, which is ESP_ERR_INVALID_ARG.

  • if i set the Bluetooth Controller Mode to "BLE Only", and disable BT Classic, then this error doesn't happen, and i can connect to BT using my android phone (wifi still doesn't work though). the fix came from here
  • if i modify the library to destroy the BLE server task when BT is disabled, then wifi works perfectly if bt is enabled then disabled. wifi doesn't work if bt is enabled first (then not disabled), and if wifi is enabled then bt is enabled, bt doesn't work, sometimes the system crashes :)

@atctwo
Copy link
Owner Author

atctwo commented Sep 2, 2020

(note: i'm now using espidf 4.0.1)
i made a test sketch (using the esp32 arduino core) that uses both BLE and Wifi to control my phone's music player using a web interface, and it worked fine. BLE and Wifi coexistence is possible. I tried to copy relevant settings from the ESP32 Arduino sdkconfig to the watch2 sdkconfig (like BLE and Wifi settings). I made a flowchart of how wifi or BLE works when enabled or disabled depending on what the states were before, and determined this:

  • if BLE is enabled, then Wifi is enabled, wifi won't work (error 0x101, no memory)
  • if BLE is enabled then disabled, BLE won't work (this might be todo with the BleKeyboard library no supporting disabling BLE), error 0x103, invalid state
  • if wifi is enabled then BLE is enabled, or if wifi is enabled then disabled then BLE is enabled, the esp crashes

i would be ok with ble and wifi being mutually exclusive (they can't be on at the same time), but enabling wifi successfully will mean that you can't enable ble without the esp crashing, and enabling ble successfully means that wifi won't work.

@atctwo
Copy link
Owner Author

atctwo commented Sep 3, 2020

i'm working on getting ble working after ble has been disabled. it seems like there's an issue setting up advertising the second time (after it's been disabled). BLEAdvertising.cpp, line 212, error 0x103 (invalid state), the function that returns this error is esp_ble_gap_config_adv_data, which i think is used to set up advertising parameters. if i modify the ble library so that advertising stuff is only set up once, then the function to start advertising fails.
what???????

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working long term todo major updates that will be done at some point, but will break everything os pertaining to the watch 2 system
Projects
None yet
Development

No branches or pull requests

1 participant