Intermittent Bluetooth hang-up issue
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I wrote a MATLAB program that communicates with an ESP32 via Bluetooth to transfer files (between .5kB and 4kB) from the ESP32 to the host computer. It works most of the time, but every 20 to 80 files on average, it hangs up, and I can't get Bluetooth working again, unless I completely close and re-opent MATLAB.
I create the connetion like this...
bt = bluetooth("ESP32", 1)
Then I write an 'R', which tells my ESP32 to begin sending the next file
write(bt,'R')
Then I read back the data in MATLAB. I know the file size beforehand, and I'm 99% certain that the ESP32 is sending back the correct number of bytes.
bluetooth_response = read(bt, fileSize);
I loop through the write and read several and it works most of the time, but every 50 files or so, it's not able to read in the expected amount of data, and I get this warning.
Warning: The specified amount of data was not returned within the Timeout period for 'read'.
Once this happens, all subsequent reads return 0 bytes. And the funciton NumBytesAvailable returns 0. However, I can verify on the ESP32 side that it is still get the 'R' commands from MATLAB and it is reporting that it is sending the appropriate number of bytes.
numBytes = bt.NumBytesAvailable; (always returns 0 after read warning occurs)
After this happens, the only way I found to get Bluetooth working again is to completely close and re-open MATLAB. I thought maybe the ESP32 was sending data back too quickly and overwhelming the buffer, so I slowed it down (to about 1000 bytes/sec ) and that didn't help. It seemed to help a little bit if I turned off my Bluetooth mouse during the transfer, but that was inconclusive, because the frequency of incidence is too random to say for certain that it helped.
Any ideas what could be causing this problem?
1 Kommentar
NilsW
am 26 Jan. 2023
Bearbeitet: NilsW
am 27 Jan. 2023
I am experiencing a very similar problem; I am reading approx 100 times per second from a ESP32 via Terminator-Callback insinde a Matlab-app.
At a random time the bt-object runs out of available bytes, and the callback is not triggered anymore. This can happen after 10 or 500 seconds of stable connection and I can reproduce it on several devices.
I have the feeling that it is more likely to happen when the mlapp runs in the background and other programmes use some ressources, but it also happens with no other programmes running.
For me it "helps" to clear the 'bt'-object and create it again (no need to restart matlab), but still it is very annoying.
Any help or advice would be apprechiated!
UPDATE: My app runs smooth now, using the outdatet "Bluetooth" function instead of the new "bluetooth" interface...
Antworten (1)
Raj
am 6 Sep. 2023
Hi,
Referring to the comments, you can try using “Bluetooth” function instead of “bluetooth” function.
Adding on it, below are some reference of the MathWorks Documentation for both the functions-
“Bluetooth” function was removed post in R2022b update and “bluetooth” was released in R2020b.
You may also try and go through the following steps if the issue persist
- Check for errors: Make sure to include error handling in your code to catch any potential errors that might occur during the Bluetooth communication.
- Update Bluetooth drivers: Ensure that you have the latest Bluetooth drivers installed on your host computer. Outdated or incompatible drivers can sometimes cause communication issues.
- Reset the Bluetooth adapter: You can also try resetting the Bluetooth adapter on your host computer. This can be done by disabling and re-enabling Bluetooth in your computer's settings or by using a physical switch if available.
- Test with a different Bluetooth device: If possible, try testing your MATLAB program with a different Bluetooth device. This can help determine if the problem is specific to the ESP32 or if it's a more general Bluetooth communication issue.
I hope your issue is resolved!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Setup and Configuration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!