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

BLETelemetry for esp32 devices implementation #2305

Closed
wants to merge 12 commits into from

Conversation

flux242
Copy link

@flux242 flux242 commented Jul 17, 2023

As long as nobody wanted to finish pull request #2018 I had to do it myself. Basically I implemented all the review comments from PR #2018 on top of the master branch and tested the results.

@CapnBry
Copy link
Member

CapnBry commented Jul 17, 2023

haha I'll look at this after 3.3 releases, but I'm giving it 5 stars for the sweet command line with multiple awks and a perl too 🤩. I was just thinking Saturday about how thank goodness I never see perl code any more and here we are!

@flux242 flux242 changed the title ADDED: btle telemetry for esp32 devices implementation BLETelemetry for esp32 devices implementation Jul 18, 2023
@arthurson
Copy link

tx16s with internal elrs, using telemetry viewer from googleplay doesn't work , while RomanLut with bluetooth le can finally connected.

@flux242
Copy link
Author

flux242 commented Jul 20, 2023

Some remarks:

  1. If you cannot connect again to the ExpressLRS Telemetry BLE device again, then try to forget it first
  2. If no connection is established within some period of time after transmitter is switched on then TX device will stop advertising. In this case simply deactivate and activate BLE Telemetry in Lua.

I don't like this random addressing myself but I havent found a way to set a specific BSSID address manually. It would be better to get the public address which is used for BT Joystick and increase/decrease the last byte by one

COSMETIC: removed unused reference
@EMH3
Copy link

EMH3 commented Aug 8, 2023

Hello everyone! I flash this pr and it seems to work fine and finally my "abnormal" jjumper aion tx don't freeze & show phantom from a "past life"! Telemetry goes to the phone perfectly and they don't seem to be any bugs yet, although the lua script freezing a little when selecting 500 Hz, but the module itself is fine. Maybe today it will be possible to fly & test in hardcore;) Many thanks to the developers!

@EMH3
Copy link

EMH3 commented Aug 8, 2023

Today tested it, so far everything is fine, thanks

@Pelado-Mat
Copy link

Works fine with my RM Zorro, at least on the bench. It even get a more reliable connection than my BT module with Telemetry Mirror.
Will be trying this branch on a LR flight during the week end.


static uint32_t LastTMLLinkStatsPacketMillis = 0;
static uint32_t LastTLMRCPacketMillis = 0;
static bool initOnce = false;

Choose a reason for hiding this comment

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

Suggested change
static bool initOnce = false;

delete unused var


//Set MTU to max packet length + 3 bytes to be able to send packets longer then default 20 bytes.
//Should be set on both ends - smaller from two is used.
BLEDevice::setMTU(CRSF_MAX_PACKET_LEN + 3);

Choose a reason for hiding this comment

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

Suggested change
BLEDevice::setMTU(CRSF_MAX_PACKET_LEN + 3);
NimBLEDevice::setMTU(CRSF_MAX_PACKET_LEN + 3);

use correct class

Comment on lines 169 to 180
//we do not want devices which are bound to BLE Joystick to connect to Telemetry service.
//start BLE Device with random address
//avoid frequent address changes
if ( initOnce == false )
{
initOnce = true;

ble_addr_t blead;
ble_hs_id_gen_rnd(1, &blead);
ble_hs_id_set_rnd(blead.val);
}
NimBLEDevice::setOwnAddrType(BLE_OWN_ADDR_RANDOM);
Copy link

@RomanLut RomanLut Aug 10, 2023

Choose a reason for hiding this comment

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

Suggested change
//we do not want devices which are bound to BLE Joystick to connect to Telemetry service.
//start BLE Device with random address
//avoid frequent address changes
if ( initOnce == false )
{
initOnce = true;
ble_addr_t blead;
ble_hs_id_gen_rnd(1, &blead);
ble_hs_id_set_rnd(blead.val);
}
NimBLEDevice::setOwnAddrType(BLE_OWN_ADDR_RANDOM);
//we do not want devices which are bound to BLE Joystick to connect to Telemetry service.
//BLE Joystick is using PUBLIC address
//start BLE Device with RANDOM address
//set RANDOM address as PUBLIC addres with last byte increased by 1
assignRandomAddress();

Use RANDOM address generated from PUBLIC address, so it does not change every time.

Comment on lines 186 to 187
/** Set low transmit power, default is 6db */
BLEDevice::setPower(ESP_PWR_LVL_P6);

Choose a reason for hiding this comment

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

Suggested change
/** Set low transmit power, default is 6db */
BLEDevice::setPower(ESP_PWR_LVL_P6);

Correct function should be called in correct place, see below

src/lib/BLE/devBLETelemetry.cpp Show resolved Hide resolved
src/lib/BLE/devBLETelemetry.cpp Show resolved Hide resolved
Comment on lines 144 to 148
NimBLEDevice::stopAdvertising();
NimBLEDevice::deinit(true);
pServer = nullptr;
rcCRSF = nullptr;
vSemaphoreDelete(_mutex);

Choose a reason for hiding this comment

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

Suggested change
NimBLEDevice::stopAdvertising();
NimBLEDevice::deinit(true);
pServer = nullptr;
rcCRSF = nullptr;
vSemaphoreDelete(_mutex);
pServer->setCallbacks(nullptr);
pServer = nullptr;
rcCRSF = nullptr;
NimBLEDevice::stopAdvertising();
NimBLEDevice::deinit(true);
vSemaphoreDelete(_mutex);

src/lib/BLE/devBLETelemetry.cpp Show resolved Hide resolved
src/lib/BLE/devBLETelemetry.cpp Show resolved Hide resolved
pAdvertising->addServiceUUID(rcService->getUUID());

pAdvertising->addServiceUUID(dInfo->getUUID());
pAdvertising->start();

Choose a reason for hiding this comment

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

Suggested change
pAdvertising->start();
pAdvertising->start(0, &onAdvertisingStopped);

Regardles specified timeout value, BLE library stops advertising after ~10 minutes. Add callback and restart advertising when stopped.

@RomanLut
Copy link

Please accept proposed changes. They solve the following problems:

  • low BLE transmission power
  • advertisiement stops after ~10 minutes if no clients are connected
  • implemented: service address is generated from public address, so it does not change every time
  • implemented: allows connecting multiple devices

@flux242
Copy link
Author

flux242 commented Aug 12, 2023

I've just pushed updated code based on @RomanLut comments. There're some parts that I changed though:

  • assigning 'constant' address code didn't work, so I kept the old implementation
  • power level set to 4mW instead of 8mW. 4mW should be enough imo and I also do not want my transmitter battery drain faster for nothing

Multiple clients connection tested and it works

@Rodrigo-NH
Copy link

Flashed to NamimnoRC 2.4 OLED RX and BetaFpv Nano TX. It works, can see telemetry in Telemetry View. Pitch is inverted in artificial horizon though (using ardupilot), must be something else.

@flux242
Copy link
Author

flux242 commented Oct 11, 2023

If used in gemini mode, the hardware will keep restarting.

yet another point to not use gemini

@howels
Copy link

howels commented Oct 11, 2023

If used in gemini mode, the hardware will keep restarting.

yet another point to not use gemini

Not really a fair comment. This BT telem PR takes cycles away from the core purpose of the eLRS code - to process packets - in order to route telemetry conveniently via BT. This PR was already known to cause issues with faster packet rates, which was not the fault of the rest of the eLRS codebase. Gemini is processing more packets than traditionally uni-radio TX processing so not surprising that spare CPU cycles are lower with Gemini that other modes.

@flux242
Copy link
Author

flux242 commented Oct 13, 2023

This PR was already known to cause issues with faster packet rates,

your statement is based on tests you performed or on some rumors? If latter is the case then please perform the test and then come back again

gemini uses 2 times the bandwidth for no apparent reason which means - less bandwidth for others

@howels
Copy link

howels commented Oct 13, 2023

This PR was already known to cause issues with faster packet rates,

your statement is based on tests you performed or on some rumors? If latter is the case then please perform the test and then come back again

gemini uses 2 times the bandwidth for no apparent reason which means - less bandwidth for others

My friend reviewed the system, Gemini works very well.

@flux242
Copy link
Author

flux242 commented Oct 13, 2023

My friend reviewed the system

right, feel free to tell us what your mum thinks about it too

@jiri-jirus
Copy link

My friend reviewed the system

right, feel free to tell us what your mum thinks about it too

I think your comments violate Contributor's Covenant.

@konstkarapan
Copy link

I've been using this PR for quite some time and I have to say, I love it. I noticed, however, that sometimes my phone randomly disconnects and I am not able to reconnect again for a couple of minutes. My tx is rm zorro with int elrs. This happened 2-3 times but since I was flying with goggles I couldn't really investigate it. I will try to, but I felt I should let you guys know.
Tell me if you need more info about my hardware👍

… a compiler switch. Reason - it won't fit into 20 bytes and setting BLE MTU isn't working for some reason
@flux242
Copy link
Author

flux242 commented Jan 14, 2024

so, Ive investigated a bit deeper and I could reproduce the "disconnect" behavior. After some connect/disconnect repeats it would not connect anymore and then the "ExpressLRS Telemetry" device would appear but with a different MAC address which shouldn't happen because it is supposed to be fixed. I'm not sure why this happens, maybe a bug in the BLE stack. So, if this happens the solution currently is to disable/enable BLE Telemetry in the lua script.

@flux242
Copy link
Author

flux242 commented Jan 15, 2024

The latest change might solve that "disconnect" problem. At least I couldn't reproduce it by repeatedly connecting/disconnecting the radio.

@kvalexey
Copy link

Hello.
Is it planned to upgrade project to elrs configurator 1.6.1?
ELRS configurator 1.6.0 bild success, but in 1.6.1 error occured.
Some new devices(pocket,bandit) are only in 1.6.1

@flux242
Copy link
Author

flux242 commented Jan 30, 2024

Hello. Is it planned to upgrade project to elrs configurator 1.6.1?

should work now

@kvalexey
Copy link

Hello. Is it planned to upgrade project to elrs configurator 1.6.1?

should work now

Sank you. It work now

@CopterFail
Copy link

CopterFail commented Feb 2, 2024

Hello. Is it planned to upgrade project to elrs configurator 1.6.1?

should work now

Works well 👍 thank you
Does anyone know sample esp32 code to receive the ble telemetry?
Edit: the esp32 arduino BLE sample (platformio) does the job, just update the id's

@flux242
Copy link
Author

flux242 commented Feb 24, 2024

I have fixed a bug that has prevented proper telemetry update. If you're still using this patch please recompile the FW with the latest commit.

@kvalexey
Copy link

Hello. I create bin file with this PR(in main page selected 3.3.2 version). When i try to flash it throw WIFI i see error: Could Not Activate this firmware
If i select at main page 3.3.1 and generate bin file for PR the result file flash throw wifi correctly
Some of my TX occured only in 3.3.2 version.
TX with problem: RM 2.4 Ranger, RM Bandit 900 micro

@kasatka60
Copy link

What if you try to flash it via USB?

@kvalexey
Copy link

What if you try to flash it via USB?

Yes. Throw usb flashing was sucessful

@CopterFail
Copy link

CopterFail commented Mar 23, 2024

My ESP32 cannot receive "CRSF_FRAMETYPE_BARO_ALTITUDE = 0x09" telegrams , but the baro value is displayed in the telemetry of the transmitter. All the other CRSF frame type work well.
The maximum distance before loosing the BLE connection is 1m. Any hints to increase this?

Edit: Altitude is in the Vario Frame

@CopterFail
Copy link

The BLETelemetry contains 12 rc-channels, but 16 were used.

@CopterFail
Copy link

My Antenna Tracking Project ist based ON this Pull requests. I wunder if , or when this pr become part of the Project? I think it will not stay forever as pr?

@konstkarapan
Copy link

I know it causes some issues when being used with higher packet rates. Why don't we just disable this feature for these higher rates and call it a day? I don't think racers of freestylers will mind. Or are there any other problems that need to be solved? I've been using this pr for several months and except from the disconnect problem that has been solved it works flawlessly for me. Is there anything we can do to speed up the integration? It's definitely a very useful tool.

@Roman-Golod
Copy link

Roman-Golod commented Apr 29, 2024

and except from the disconnect problem that has been solved

I've started using it recently with the T20, and facing disconnects after ~10 min, but I can't reproduce it on the table, only during flight. Packet rate is 150Hz. Maybe it's of high power of TX? BLE turns off completely, and can be found again only after switching it off/on in the script.

@konstkarapan
Copy link

and except from the disconnect problem that has been solved

I've started using it recently with the T20, and facing disconnects after ~10 min, but I can't reproduce it on the table, only during flight. Packet rate is 150Hz. Maybe it's of high power of TX? BLE turns off completely, and can be found again only after switching it off/on in the script.

In my case it turned out to be client related. I was using romam lut's telemetry viewer app and updating it to the latest version solved the issue, at least for me. Since then I didn't have any disconnects even at 30min+ flights

@GT-Volk
Copy link

GT-Volk commented May 19, 2024

@flux242 Please update the pull request to version 3.4, thanks!

@aszczu
Copy link

aszczu commented May 21, 2024

Loaded on Radiomaster Ranger Micro 2.4Ghz- Neither my phone or PC can't finish pairing process. ExpressLRS Telemetry bluetooth device is properly detected, but fail to connect. Restarting the module or bluetooth, and bluetooth function change nothing.

@konstkarapan
Copy link

Loaded on Radiomaster Ranger Micro 2.4Ghz- Neither my phone or PC can't finish pairing process. ExpressLRS Telemetry bluetooth device is properly detected, but fail to connect. Restarting the module or bluetooth, and bluetooth function change nothing.

What program do you use at the client side?

@aszczu
Copy link

aszczu commented May 22, 2024

Loaded on Radiomaster Ranger Micro 2.4Ghz- Neither my phone or PC can't finish pairing process. ExpressLRS Telemetry bluetooth device is properly detected, but fail to connect. Restarting the module or bluetooth, and bluetooth function change nothing.

What program do you use at the client side?

I wanted to use Android telemetry app by RomanLut, but I didn't went that far- I fail at connecting to bluetooh davice, I don't think that application have anything to do with it.

@konstkarapan
Copy link

Loaded on Radiomaster Ranger Micro 2.4Ghz- Neither my phone or PC can't finish pairing process. ExpressLRS Telemetry bluetooth device is properly detected, but fail to connect. Restarting the module or bluetooth, and bluetooth function change nothing.

What program do you use at the client side?

I wanted to use Android telemetry app by RomanLut, but I didn't went that far- I fail at connecting to bluetooh davice, I don't think that application have anything to do with it.

No need to pair, just connect through the app

@aszczu
Copy link

aszczu commented May 22, 2024

Loaded on Radiomaster Ranger Micro 2.4Ghz- Neither my phone or PC can't finish pairing process. ExpressLRS Telemetry bluetooth device is properly detected, but fail to connect. Restarting the module or bluetooth, and bluetooth function change nothing.

What program do you use at the client side?

I wanted to use Android telemetry app by RomanLut, but I didn't went that far- I fail at connecting to bluetooh davice, I don't think that application have anything to do with it.

No need to pair, just connect through the app

Ooo, okey. Connection through app worked, everything working fine then on Ranger Micro, great !

@flux242
Copy link
Author

flux242 commented May 25, 2024

use 2731

@flux242 flux242 closed this May 25, 2024
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.

None yet