WLED icon indicating copy to clipboard operation
WLED copied to clipboard

ESP 2 Bluetooth?

Open Doyle4 opened this issue 3 years ago • 37 comments

Is your feature request related to a problem? Please describe. To control WLED via Bluetooth using ESP32 :) A clear and concise description of what you want to happen. Enable bluetooth, connect to WLED and use

Describe alternatives you've considered NA, Love WLED too much

Thank you for your ideas for making WLED better!

Doyle4 avatar Nov 27 '20 10:11 Doyle4

Hi! I'm very glad that you like WLED so much :) This could be done, but it doesn't seem easy: https://esp32.com/viewtopic.php?t=6707 What would be your use case / what makes BLE better than the WLED-AP WiFi access point?
In any case it would only be useful with some client-side/app code to communicate over Bluetooth as it of course doesn't work in browser (no HTTP)

Aircoookie avatar Dec 01 '20 10:12 Aircoookie

Thanks for getting back @Aircoookie :)

My friend owns a Gaming Bar and has a lot of consoles etc all ready using wireless and we have found the devices can conflict, tried various channels, so we thought it would good idea to be able to control them via bluetooth instead, I hope someday someone does release a WLED app that works like the web browser.

Doyle4 avatar Dec 01 '20 20:12 Doyle4

Hi! I'm very glad that you like WLED so much :) This could be done, but it doesn't seem easy: https://esp32.com/viewtopic.php?t=6707 What would be your use case / what makes BLE better than the WLED-AP WiFi access point? In any case it would only be useful with some client-side/app code to communicate over Bluetooth as it of course doesn't work in browser (no HTTP)

Hi,

I'm currently working on this kind of solution for my own project. There is a BluetoothSerial library and a Serial Bluetooth android app for this topic. You can send commands over Bluetooth to ESP32. OR Maybe it could work as a BLE tracker and could change to a personal light effect. If it "feels" some bluetooth device (phone, beacon) around itself could change to greetings color. But probably this is an overload function for this project. This kind of automation should be done by another device and control WLED board to change the color/effect

redakker avatar Dec 06 '20 08:12 redakker

I would also like to see bluetooth protocol incorporated into WLED project! My reasoning: I have installed ~500 LEDs at my family's lake house where they do not have WiFi/ISP. As they are a bit older, they find it troublesome connecting to the AP and and loosing LTE data just to use the lights. As a work-around, I've set up custom IR codes with a remote that has DIY programmable buttons to switch to some of their favorite settings. But would be nice if the APP could communicate via Bluetooth to interface with the controller/backend.

JBlackJr avatar Jun 07 '21 13:06 JBlackJr

I have a very different reason for this. I fly a paramotor and have a 5m strip of LEDs on it. Right now I'm using an SP-105E bluetooth controller for the lights, but want to move to WLED. I use the MagicLED app on IOS. The app sucks, but it is reliable and rock-solid.

Bluetooth is handy because I still want to use data on phone over LTE, and while it may work while I'm flying to have wifi connected to the WLED ESP32, it disrupts the normal flow of things.

Having the app able to control all the same stuff via Bluetooth instead of WiFi would definitely help in my situation.

When flying I don't want to have to mess with disconnecting and reconnecting networks, power-cycling the ESP32 to get it to reconnect, etc. Bluetooth requires less setup and configuration for a device that will be powered on for 2 hours with a battery and then shut off again, not something that is active all the time.

ooglek avatar Jun 28 '21 16:06 ooglek

I have another scenario for wanting this feature: I have an over desk cabinet that I've added a couple led strips, but I don't have any outlets nearby, so I'm powering it with a power bank and it works great for this purpose (I'm also building my own larger battery in order to provide more amperes and have less frequent recharge cycles).

The problem is that wifi consumes too much energy even with all LEDs turned off (a 10A battery is 50% discharged overnight), so I can't leave it connected all the time and have the automations that I've wanted to (like turn it on automatically when at dawn when I'm working or with the alarm clock in the morning). Adding a relay to the circuit may improve things, but from my research wifi still demands too much energy for a battery operated device.

I've looked into zigbee and BLE controllers/DIY solutions, but WLED is much more feature complete and I'm willing to help with implementation and test of this feature if needed.

andregodoy0 avatar Aug 08 '21 15:08 andregodoy0

I'd like to see this as well. I'm trying to use WLED with an ESP32 in my vehicle and found with the chassis fuse in, it's acting as sort of faraday cage and I can't connect to the wifi or it never shows up. As soon as I take the chassis fuse out, all the problems go away. I've tried other bluetooth controllers in my vehicle and they work fine.

djvj1 avatar Sep 22 '21 17:09 djvj1

Bluetooth will not be implemented (anytime soon) due to huge amount of resources it demands.

blazoncek avatar Sep 22 '21 20:09 blazoncek

@blazoncek Would you be willing to roughly outline the work that needs to be done? Maybe I can get the ball rolling with just a piece that moves the functionality closer to completion.

ooglek avatar Sep 23 '21 04:09 ooglek

It is the sheer code size and RAM requirements that are prohibiting. You are still free to try if you wish. 😉

blazoncek avatar Sep 23 '21 05:09 blazoncek

Hi! I'm very glad that you like WLED so much :) This could be done, but it doesn't seem easy: https://esp32.com/viewtopic.php?t=6707 What would be your use case / what makes BLE better than the WLED-AP WiFi access point? In any case it would only be useful with some client-side/app code to communicate over Bluetooth as it of course doesn't work in browser (no HTTP)

Hi,

I'm currently working on this kind of solution for my own project. There is a BluetoothSerial library and a Serial Bluetooth android app for this topic. You can send commands over Bluetooth to ESP32. OR Maybe it could work as a BLE tracker and could change to a personal light effect. If it "feels" some bluetooth device (phone, beacon) around itself could change to greetings color. But probably this is an overload function for this project. This kind of automation should be done by another device and control WLED board to change the color/effect

did you get any further on this? we have a BLE app for our Pixelblaze based board (originally on NRF52) and it's esp32 port - but want to move to WLED asap. This is pretty much a deal breaker, as the wifi stuff is just not practical for endusers.

Funkelfetisch avatar Feb 08 '22 17:02 Funkelfetisch

No. And IMO WiFi is easier than BT. But that is just me.

Apart from my opinion, there was no-one willing to add BT yet. Until someone with interest shows up it may not happen soon. There are caveats as stated above.

blazoncek avatar Feb 08 '22 18:02 blazoncek

+1 to build a few BT connected DIY-Hue-Go or DIY-BT-Obulbs :)

snickers2k avatar Mar 07 '22 21:03 snickers2k

I would also like to have a Bluetooth solution. Or maybe some work around that doesn't require wifi. I have a gator that I want to decorate with lights for holidays. Thanks for WLED it is hands down the best!!!!!!! (better than fast led. I use both).

ghost avatar May 10 '22 23:05 ghost

I understood that Wifi and Bluetooth cannot be active together on the same ESP32, because they both need to use the same radio/antenna. Is this still correct? So, in contrast to the IR receiver solution, you would not have the web UI availeable once that BT (or BLE) is activated?

That actually means you have two options:

  1. Re-Implement all web UI functionality in a new bluetooth API, so that WFi will not be necessary any more (also for configuring WLED, OTA update etc)

  2. Implement only a subset of commands for BT, and have some kind of "kill switch" that allows to disable BT and start Wifi to use the web UI

softhack007 avatar May 21 '22 19:05 softhack007

I have no issues with BLE and Wifi on at the same time. Haven't completed the implementation, but discovery, connect and sending strings back and forth works just fine. I do have an 8MB ESP32 though - 4 MB won't work!

Funkelfetisch avatar May 21 '22 19:05 Funkelfetisch

I have no issues with BLE and Wifi on at the same time. Haven't completed the implementation, but discovery, connect and sending strings back and forth works just fine. I do have an 8MB ESP32 though - 4 MB won't work!

Interesting 👍 ... could you make a usermod for BLE, that works similar to the IR receiver control? Or do you need to have "deeper" control of WLED?

softhack007 avatar May 21 '22 19:05 softhack007

Just another idea - in case BLE + Wifi become problematic, or memory requirements are prohibiting - how about using one of these cheap bluetooth boards with serial interface and AT commanding? Like the HM-10 or HC-05 that we find in all those "arduino robot car" kits? Or maybe utilize a nRF24L01 based module over SPI?

softhack007 avatar May 21 '22 19:05 softhack007

Hi all - I'm trying to run with this & my use case is similar to others: I want to do short BLE communications (not a full WLED UI) between multiple WLED ESP32s, in a place where there's no WiFi AP available.

In a previous non-ESP32 project I used an external nRF24L01 module but now I'd rather try to leverage the built-in BLE. I've got working BLE mesh code that can run on an ESP32 via NimBLE, but it doesn't work when added to WLED. I've been trying to get the WLED code into "coexistence" mode (where WiFi and BLE can both run on the same antenna by sharing time.)

If anyone has had any luck or wants to collaborate on this, I'm happy to write the code, package it up and contribute it to WLED once it's working. I don't mind hacking WLED core, I'm just hitting issues with the underlying esp stack crashing when I turn on BLE. There's evidence on the 'net that people have gotten wifi+ble coexistence working, but they're typically doing it in esp-idf versus the arduino package WLED uses. Maybe we can figure out how to port that over?

@Funkelfetisch in particular if you have working code I'd love to collab! @softhack007 your # 2 solution is what I'll be exploring first... a way to switch between wifi and BT mode

SteveEisner avatar Jul 17 '22 17:07 SteveEisner

I too would like this feature for using WLED in my car. I want to use a bunch of thin strips in my dash that can be used with the music reactivity part of WLED but using a regular microphone would pickup road noise. If I could use bluetooth multi pairing I could play my music to the car speakers and the WLED controller with clean synced audio. I know it might be a huge pain to code this, but if you could that would be amazing. The functionality offered by WLED ESP32 stand alone, or QuinLED-Dig boards is superior to anything else on the market. Its main limitation being tied to WiFi holds it back from going absolutely anywhere, opening tons of new possibilities.

PoTheRedTeletubby avatar Nov 21 '22 19:11 PoTheRedTeletubby

Just use I2S line in from @srg74 if noise is a problem. BT will not happen any time soon.

blazoncek avatar Nov 21 '22 20:11 blazoncek

It seems that two feature requests get mixed up here.

  1. control WLED over BT (no internet availeable) -> as @blazoncek says, this will not happen, as it requires replacing all the web based UIs with a bluetooth command interface. "Everything" includes configuring LEDs and other setup stuff, not just control brightness... -> in case of no internet, you can still connect to the WLED AP. This works everywhere especially if no internet is availeable, like on a boat or plane.

If I could use bluetooth multi pairing I could play my music to the car speakers and the WLED controller with clean synced audio

  1. this is a different feature request for audioreactive, to have audio input via bluetooth. Unfortunately will also not happen, due to complexity of the coding needed. However there are alternatives -> with some coding, it should be possible to utilize a second ESP32 as bluetooth to I2S receiver, and wire it to I2S on the WLED esp32. Basic idea is described here: https://github.com/atuline/WLED/wiki/Digital-Microphone-Hookup#use-a-second-esp32-as-bluetooth-audio-to-i2s-device. -> you can use a bluetooth audio receiver with line-out, and connect that to WLED via line-in to I2S shield. This is already possible today.

I have to admit I don't understand your last comment about quindor's boards. Every ESP32 can run WLED, and there are many options for ready-made shields of different sizes not just from quindor. Personally i never used any QuinQodWhat dig-dog boardz 😉 or similar and still happy with WLED lighting my rooms.

So there are some options already availeable, with a bit of out-of-the-box thinking.

softhack007 avatar Nov 21 '22 20:11 softhack007

I haven't looked at the code, so apologies if I'm incorrect, but isn't the current web application that loads already making tiny AJAX web interface calls when you tap on something on the screen to make the actual lights change?

If yes, and I'm guessing it is a yes, could you not build something that sends commands via bluetooth, turn those into whatever those AJAX calls are internally, and make the same calls within WLED?

Current:

  1. User loads WLED Web Interface UI
  2. User taps on a Favorite effect
  3. the UI makes an AJAX call from the browser to the web UI that takes an action to change the lights to that effect

Bluetooth:

  1. A user loads an app which is the UI
  2. They get a list of all of the effects (TBD)
  3. When they tap on an effect, this makes a bluetooth call to the BT receiver, which then does the same thing as if the user tapped the effect in the web UI

No need to replace the web interface stuff -- the controls are already written, this is just a different path to accessing them, an abstraction.

ooglek avatar Nov 21 '22 22:11 ooglek

I now see how this is indeed two different types of feature requests. As for audio reactive scenario 2 as it was dubbed.

I will admit that I am new to this stuff and not particularly familiar with the wiring setup but if you can wire a mic directly into an ESP32 with WLED support then why couldn't you also use a separate Bluetooth 5.0 board with some audio out pins piping the audio into the ESP32 similarly? Using multiple ESP32s just for a singular function add-on is also a bit of an L because you could use that board for another LED setup.

PoTheRedTeletubby avatar Nov 21 '22 23:11 PoTheRedTeletubby

@ooglek Since posting my comment on Jun 19th, that's actually the path I ended up following. I was able to get it working, although not exactly what you said, same spirit. My code does send information between WLED instances but it's not exactly hooked into the UDP or AJAX sync endpoints. Instead I used my own smaller protocol to just sync what I needed to sync. It might be possible to connect it to those, though!

-- Note this is very different than the recent question about getting bluetooth audio! & doesn't solve that. --

I wrote the BLE code first, and got something simple-ish working, but BLE just isn't a super-reliable way to transmit this info since it relies so much on timing windows. There are 3 BLE channels constantly rotating on both sender and receiver, so you have to have a relatively large window where you're scanning and hoping that you'll find an overlap. I messed with this for a bit, trying different windows to see if I could increase the reliability, but moved on to a different approach.

I ended up using ESPNow for broadcast packets instead, and that's been rock solid. I got 75 individual devices to sync perfectly at ranges up to several hundred feet apart. Then I stopped testing further because I only have 75 ESP boards :) but I don't see any degradation so I bet it could handle many more devices.

There would be some challenges in wiring this up to the actual UDP sync or AJAX endpoints. Those have payloads that might be larger than ESPNow can handle. Also there's an implicit assumption that one is the "truth" and others are targeted for sync, but that's not the ideal way to run a mesh. Anyway, I'm going to try to package this all up at some point....

SteveEisner avatar Nov 21 '22 23:11 SteveEisner

Just forget about BT. Look elsewhere. Please.

@SteveEisner we are still waiting for your PR. 😉

blazoncek avatar Nov 22 '22 06:11 blazoncek

@blazoncek I don't quite understand what is so offensive to you about having an open discussion on a tech forum but thanks for being extremely unwelcoming. Others had some interesting points to contribute. There might not be an "ideal" solution to the issue but that doesn't mean it's not worth discussing. This sounds like those business software engineers that always say everything is impossible. Nothing is getting done that way and clearly others have found some work arounds for the other scenario already by not listening to the "forget about BT" line. Obviously my answers aren't here and I could see that without your completely unnecessary comment.

PoTheRedTeletubby avatar Nov 22 '22 11:11 PoTheRedTeletubby

@PoTheRedTeletubby & @rontav I am sorry if my post sounded too blunt. The fact is that unless someone with experience (that could be you) volunteers to adapt everything for BT it is just not going to happen as there are other areas of WLED that need attention with higher priority.

blazoncek avatar Nov 22 '22 12:11 blazoncek

there are a couple reasons I wanted bt functionality... I want to put lights on my trailer and having wifi setup isn't always practical... I usually don't connect to wifi very often... even at home, i'm not always connected to wifi but still wanna control my lights...

so... I started working on it... I made a user mod that will turn off wifi when set in ble mode (ethernet should still work but I don't have a device yet to test that with)... and has another switch to turn off ble mode... in this, ble mode just exposes all the json api (I have state working so far, but the others should be very easy to add) here is my fork: https://github.com/johne/WLED/tree/ble

now, please be kind... i'm not usually an embedded developer. I know there are memory leaks (I feel most of them don't matter since I reboot when changing between ble and wifi) and I know there are a ton of formatting problems (anyone have a .prettierrc file for use with c/c++ that they don't mind sharing so I can turn auto-formatting back on)... I also didn't completely understand debugging statements when I first started, so there is a nasty mix of Serial.println and ESP_LOGD but I do plan to clean those up... even though all that, i'm definitely wanting feedback if you have it...

my next plan is to take the ios app (I know, apple fan boy, I guess) and make it so the networking layer can switch between ble-json and wifi-json... I haven't started that process yet, but if you are from the future, you can go here: https://github.com/johne/WLED-App/tree/ble to see my progress...

you might say: "well, what about the 600 byte ble limit of Arduino BLE?" yeah... I'm a hack and just chunked the data into 512 byte chunks... It ain't pretty or fast, but it does seem to work... the cool thing about ble is that I can "push" changes to the phone to keep it up to date with the current state... I might turn that off if I don't see an easy use for it in the app...

johne avatar Dec 10 '22 18:12 johne

Hi, yes we can can wait. Just tell us when you'r ready. We're here to help 👍 Just that we also need to think about long-term maintenance of your usermod, even at times when you might not be interested any more. That's why some coding style (including logging) and lots of comments in the code are really necessary.

About the memory leaks ... please try to fix them if you can. RAM is always low on embedded processors, so any leaked memory is a pity.

make it so the networking layer can switch between ble-json and wifi-json

Not sure if the phone APP is really using JSON. My undertanding is that the App is basicilly a wrapper around Safari (or another core browser), so a lot of communication will happen with simple HTML POST an GET requests i think.

Cheers, Frank.

softhack007 avatar Dec 10 '22 18:12 softhack007