Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

add esp32 support #174

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

Closed
dominsch wants to merge 7 commits into arduino-libraries:master from dominsch:master
Closed

Conversation

Copy link
Contributor

@dominsch dominsch commented Apr 18, 2021

Added support for the esp32 chip using the virtual HCI. This has been tested on real hardware with "Arduino core for the ESP32" version 2.0.0.

wiesenklee, ilia-ametov, sabas1080, SamuelHelbling, Benni77, bisak, and baconcheese113 reacted with thumbs up emoji
Copy link

CLAassistant commented Apr 18, 2021
edited
Loading

CLA assistant check
All committers have signed the CLA.

@per1234 per1234 added the type: enhancement Proposed improvement label Apr 18, 2021
Copy link
Contributor Author

ESP32-C3 compiles as well now but not tested on hardware

Copy link

akumar36 commented Dec 6, 2021

Hi @dominsch, by when can we expect this branch merged into the master branch?

Copy link
Contributor Author

dominsch commented Dec 6, 2021

I'm not involved in this project and it is entirely up to the maintainers if they want to add esp32 support. Maybe if enough people express interest they will consider merging.

Copy link

haptork commented Dec 26, 2021

@dominsch I tried code from your fork but it gives compile error. May be it is my lack of understanding on how to run it. The error is because of the following include statements:

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/stream_buffer.h"
#include "esp_bt.h"
#include "nvs_flash.h"
#include "esp32-hal-bt.h"

in the HCIVirtualTransport.h file.

Copy link

@haptork i fixed this issue by creating a folder called freertos, and including the files from https://www.freertos.org/a00104.html that are needed. although now I am getting this error
error: 'struct esp_bt_controller_config_t' has no member named 'mode' bt_cfg.mode = ESP_BT_MODE_BLE; ^~~~
I located the error, it's in HCIVirtualTransport.cpp, line 85.

Copy link

Immediately after posting that, i noticed that

#include "esp_bt.h"
#include "nvs_flash.h"
#include "esp32-hal-bt.h"

were also not included. Time to google some more.

Copy link
Contributor Author

FreeRTOS headers should be included with arduino-esp32, just like the bluetooth files. Do the regular bluetooth examples compile for you?

Copy link
Contributor Author

Just checked it on a different computer with clean arduino install and it compiled. Make sure you have arduino for esp32 version 2.0.0 or later. This is the link you want to be using in your board manager: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json. They used to use https://dl.espressif.com/dl/package_esp32_index.json but that has become stale and doesn't go beyond 1.0.6

Copy link

haptork commented Jan 27, 2022

@dominsch Thank you. Yes it works well with version 2.0.2. I am using platform.io which is still stuck in ver 1.0.6 and working with version 2 needs some hack.

Copy link
Contributor Author

It shouldn't be hard to get it to work with the old versions. Most of it is just name changes in the api. The only problem I had was that the function HCIVirtualTransportClass::read() only reads one byte at a time so I had to use the RTOS stream buffer that is exclusive to versions 2.0+. You can avoid this by putting all the functionality directly into HCI.cpp but that breaks compatibility with the other platforms.

@per1234 per1234 added the topic: code Related to content of the project itself label May 13, 2022
Copy link

bisak commented Jun 12, 2022

This would be so useful, especially now that Platformio supports 2.0...

Copy link

Di3mex commented Jun 14, 2022

I would really like to see support for ESP32

Copy link

Nxtv2 commented Aug 7, 2022

@dominsch I tried BLE on esp32 and everything works great except changing MAC addresses. HCI.leSetRandomAddress() does nothing, i tried to debug what happened with HCI but it is way out of my ability, could you maybe look at it?

@dominsch dominsch deleted the branch arduino-libraries:master August 8, 2022 11:58
@dominsch dominsch deleted the master branch August 8, 2022 11:58
Copy link
Contributor Author

dominsch commented Aug 8, 2022

Nice to hear that someone is using it. Can you provide a code snipped I can test? I looked in the documentation and leSetRandomAddress() is not listed. I don't think it's meant to be called by the user.

Copy link

Nxtv2 commented Aug 12, 2022

I had tested this snippet and it didn't work, i am testing on a single core esp32 board so i had to compile the esp-idf for arduino IDE myself.

#include <ArduinoBLE.h>
#include <utility/HCI.h>
uint8_t macaddress[] = {0xd2, 0x7b, 0x70, 0x1c, 0x0f, 0xd2};
void setup() {
	Serial.begin(115200);
	BLE.begin();
	BLE.setLocalName("ESP");
	BLE.advertise();
}
void loop() {
	BLE.stopAdvertise();
	macaddress[1]++;
	HCI.leSetRandomAddress(macaddress);
	BLE.advertise();
}

Copy link
Contributor Author

You can call esp_base_mac_addr_set() before BLE.begin() to set a custom MAC address. The BLE mac address will be base address + 2. If you need to change it on the fly you will have to reinit the entire bluetooth stack which crashes at the moment and will take some time for me to fix. It looks like arduinoBLE doesn't currently doesn't allow the user to change the MAC address so you might want to open an issue and request the feature.

Copy link

bisak commented Aug 16, 2022

Why close the PR though?
I've been also using this and has been working exceptionally well for me.

Copy link
Contributor Author

The PR has been open for more than a year and there hasn't been any interest in merging it which is understandable since there are no official arduino boards that would benefit from this. I will try to make it stable enough so that it doesn't crash when calling BLE.end() and then open another PR. I think I might also just make a fork that removes some abstractions and doesn't depend on arduino at all so that it can be used standalone with the esp-IDF. I think its a shame this library isn't more popular despite using the lowest amount of resources among all the BLE stacks.

bisak and MonkaKokosowa reacted with heart emoji

Copy link
Contributor Author

@Nxtv2 This works now without crashing or leaking memory:

#include <ArduinoBLE.h>
uint8_t macaddress[] = {0x00, 0x00, 0x70, 0x1c, 0x0f, 0x00};
void setup() {
}
void loop() {
 esp_base_mac_addr_set(macaddress);
 BLE.begin();
 BLE.setLocalName("Mystery Device");
 BLE.advertise();
 delay(1000);
 BLE.end();
 macaddress[1]++;
}

@per1234 per1234 added the conclusion: duplicate Has already been submitted label Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
conclusion: duplicate Has already been submitted topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /