-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Add BluetoothSerial library #1144
Conversation
A simple UART to Classical Bluetooth bridge for ESP32
@me-no-dev To future versions, it will be necessary to compile the core with the options As workaround, I included my compiled version of btlib in the commit for testing |
@copercini I pulled your BluetoothSerial library into my existing installation (ESP32 staging), including the libbt.a
I get
I recplaced |
@beegee-tokyo Thanks for report, I already replaced this by default |
Playing around with this, I run into a problem. If I send several strings (size between 80 to 100 bytes) immediately after each other, I get a |
@copercini : I have my sketch size of 719018 bytes
When I add these three lines:
The size becomes almost twice bigger than before and exceeds maximum allowed limit:
Seems to be too high "price" for just one SPP function, isn't it :-) |
It is not the SPP function that increases the sketch size, it is the complete Bluetooth stack behind it. Even for BLE you might need to change your partition size |
@beegee-tokyo: Thank's a lot! Upon edit of partitions.csv and boards.txt the build goes fine and Is it possible to fix esp32 crash upon SPP reconnect somehow?
|
@lyusupov It's an IDF bug, that Espressif guys will fix next week espressif/esp-idf#1537 |
@copercini Thank you for the library and information! |
good job! Please fix the sketch! |
@me-no-dev Done =) |
merged :) |
* Add BluetoothSerial library A simple UART to Classical Bluetooth bridge for ESP32 * Create README.md * Fix typos * Replace deprecated header and small fixes * Add coexistence with BLE * Add missing semicolon
Hi @copercini . I'm sending and receiving a string representing a JSON object through the SerialBT and i noticed that when I receive any data the write speed becomes slower. In the exact moment that I receive some data the ESP keeps fast, but after almost 2 seconds it becomes slower. If i receive something again the write gets back it's fast speed and the process repeat itself. When I disconnect and Android phone from the bluetooth the sketch stops (sometimes) . Is there any way to disconnect and reconnect without stopping the loop() ? Im using Arduino IDE and Esp32 DevKit v1. |
Olá @1uuc4asb, There is an internal flow control where the first 512 bytes will be read from android and queued till you call About the disconnect and reconnect issue, seems this one: #2009 it will be fix probably in the next IDF compilation |
@copercini I put the core debug level to "verbose" (using the SerialtoSerialBT sketch) and i noticed that:
is triggered almost everytime that i send something(thing that only was happening sometimes before). Why when i receive, the sending slow? |
CONGEST event means that radio is too busy to send messages with this rate and is queuing messages or just drop it (im not sure). |
@chegewara The situation is: But if a receive something. Sending data. This happen after a few seconds. |
Try to add small delay in send loop (3-5ms). Last few days ive been trying to trigger congest event with ble on esp-idf with no luck. I am able to send notifications 5-6 times per ms and no congest. My speed rate with ble is about 500-600 kbit per second now. |
That's impressive, though.
Is there any documentation about the low-level workings of the ESP32
Bluetooth and BLE radio? I'm think there is some tricks (hacks) to the
RFCOMM stack that we may do.
|
I would suggest to ask this question on forum or esp-idf repo. |
@copercini Thats weird, because like i said earlier i am able to achieve 500-600kbits between esp32 and android smartphone nRF connect in ble app, which should be slower that classic bt. Of course it is app with master esp-idf, not arduino. |
@copercini idk if you noticed, but i'm receiving the string in one 'x' speed. Watch closely https://drive.google.com/file/d/1QY0NHfPhY9ilQ5AZLfnezPnzOmbexTMk/view?usp=drivesdk (You can slow the video's speed to help if u want...) |
@chegewara here is the problem and workaround: https://www.esp32.com/viewtopic.php?t=5613 |
Looks like this link answer all questions from this discussion. |
@1uuc4asb I compiled a libbt with the workaround proposed in the above link libbt.zip Try unzip it on |
I opened a new IDF issue about it: espressif/esp-idf#2725 |
I reunited with @1uuc4asb in some fablab here in our city.
|
|
|
This line suggests that error is not related to bluetooth serial: What is the code after i2c init? |
Ok. Now i'm using nothing but the Bluetooth.
|
You have to use tool to decode this:
|
There is not much i can do or say now. You can find someone with better knowledge than mine or try to create new task in setup and move all your code to that task, because i still believe there is some issue with stack size |
You can optimize the loop task to use less stack (creating less local variables, less recursion functions, etc), or increase the stack size here from 8192 to a bigger value (may to 12288) |
@copercini |
This happens only when i use the libbt that u compiled...
|
@1uuc4asb |
I've modified the library to allow master / slave role selection so ESP32 can connect to and use SPP BT devices, like bluetooth GPS receiver, what is my use case. |
Can't say for everyone, but I would consider it as a very useful feature. Will be waiting for your upload into your own 'fork' of this repo. |
I've created a repository, this is the link https://github.com/gmag11/BTClassicSPP. Feel free to ask questions there. |
I've applied your code to one of my open source projects where I mostly use SPP in conjunction with ESP32 'slave'. Thank you so much for developing and sharing!
|
Yes, connection will restart if it is dropped. Thank you for testing |
I've just noticed that in my environment (ESP32 AC 1.0.1 on both sides) when 'master' reconnects to the 'slave' , the latter makes unwanted self-WDT restart before actual reconnection:
I wonder of how could I get rid of that restart... Germán, have you noticed anything similar when you did debugging before the release ? |
I've only tested against a bluetooth GPS receiver. I have not found any problem with watchdog on my side. Try to identify what your code was doing or waiting just before the reboot. Try to load slave example from IDF repository or this one from Arduino-ESP32 for testing |
Ok. Thanks for the information! My ESP32 'slave' gives WDT reset once it gets connected with ESP32 'master'. After the reset, re-established peer-to-peer connection works fine. Looks like there is an infinite loop somewhere in ESP32 'slave' code but which is triggered only when 'master' is also an ESP32-based device. |
@lyusupov I've been thinking about what's different from first connection to reconnection. Code is the same. Are you using device name or address to start the connection? |
@copercini Would you like to add this to your code so that it is native to esp32 Arduino core? |
@gmag11 sure! for me all the improvements are welcome, please open a pull request to be easier to @me-no-dev manage the code |
Name. My 'slave' is this code: https://github.com/lyusupov/SoftRF/blob/master/software/firmware/source/SoftRF/BluetoothHelper.cpp
Will do. Next week I will try to reproduce this issue using basic BT SPP examples code, same way as you suggested. |
A simple UART to Classical Bluetooth bridge for ESP32