whitecatboard / Lua-RTOS-ESP32

Lua RTOS for ESP32
Other
1.19k stars 221 forks source link

Bluetooth support? #75

Open max1220 opened 6 years ago

max1220 commented 6 years ago

As far as I can see, there is no support for bluetooth, but the ESP32 has bluetooth, and the esp-idf supports it as well, so it should be doable without to much of an effort.

jolivepetrus commented 6 years ago

Yes, I'm agree with you.

Now I'm involving in many things: add support for external GPIO / PWM chips, finish the IDE, release an expansion board for the WHITECAT N1 board with CAN/SDCARD, etc ...

This is scheluded by 4Q 2017, but not started yet.

May be someone from the community can help?

the0ne commented 6 years ago

@max1220 as you know bluetooth isn't just one function but offers many different "protocols" and use cases. If the Lua RTOS should offer more than only low-level functionality then that would mean to implement such "use cases" instead. so possibly it would be a step forward if you would specify your use case(s) first.

max1220 commented 6 years ago

I'm actually "porting" this to the SHA2017 badge(Which in it's default micropython firmware does not support bluetooth). Most useful for most users would be RFCOMM/SPP, as it's somewhat generic, and can easily be used to control an appliance via, e.g. a phone. I'd personally like to see HID and audio support, but I guess that's a litte more niche.

the0ne commented 6 years ago

audio (sink) support should be straight forward as there's a sample included in the esp-idf. ble (gatts) spp server and client are included as samples as well.

i didn't find an rfcomm spp sample in the current esp-idf despite i thought i had seen one before. the api at esp-idf/components/bt/bluedroid/stack/rfcomm/port_api.c contains a function RFCOMM_CreateConnection that you could use as a starting point

the good news is that a sample can be found at https://esp32.com/viewtopic.php?f=13&t=1722 but the bad news is that RFCOMM currently, according to https://www.esp32.com/viewtopic.php?f=18&t=1928&p=9328&hilit=rfcomm#p9328 doesn't seem to be implemented properly.

jolivepetrus commented 6 years ago

I'm agree with @the0ne. We need to know the use cases to provide support for BT in Lua RTOS.

1soproni commented 6 years ago

I would like to use PBAP and HFP features. Browse in the phonebook and initiate, answer or cancel calls.

jolivepetrus commented 6 years ago

Hi guys, @max1220, @the0ne, @1soproni , @andreas23, @jcwren,

There is a new branch (https://github.com/whitecatboard/Lua-RTOS-ESP32/tree/ble) with a very, very, very, initial version about ble support in Lua RTOS.

The initial version has support for:

bt.attach(bt.mode.BLE)

bt.advertise(160, 160, bt.adv.ADV_IND, bt.ownaddr.Public, bt.peeraddr.Public, "808182838485", bt.chann.All, bt.filter.ConnAllScanAll, advData)

bt.reset()

b1 = bt.service.eddystone.uid("808182838485", 0xed, "3F3B51B60B88EF9949E5", "CF484185AE0B") b2 = bt.service.eddystone.url("808182838485", 0xed, "https://whitecatboard.org") b1:start() b2:start()

I know that is not too much, but please, take a look if anyone have time to give ideas.

Best regards,

Jaume

kmod-midori commented 6 years ago

Is there any possibility of GATT support?

galenzhao commented 5 years ago

@jolivepetrus thanks for what you have done.

I think BLE is a very important function for some can using their phones for config or connect their devices.

The NodeMCu has implemented BLE for esp32.

https://nodemcu.readthedocs.io/en/dev-esp32/modules/bthci/

the0ne commented 5 years ago

Hi guys,

to summarize, this functionality has been committed to the mainline already. Some fixes are available for advertising raw data in https://github.com/whitecatboard/Lua-RTOS-ESP32/pull/289

Advertising the data from the RAW data taken from a ESP32 Demo source code now works:

bt.attach(bt.mode.BLE)
advData="0201060303F0AB0F094553505f5350505f534552564552"
bt.advertise.start(160, 160, bt.adv.ADV_IND, bt.ownaddr.Public, bt.peeraddr.Public, "808182838485", bt.chann.All, bt.filter.ConnAllScanAll, advData)

However, I feel having non-raw advertising could be much more convenient. Until then, the following may help:

advData=""
advData=advData.."020106"   -- flags: ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT
advData=advData.."0303F0AB" -- 16srvcpl: 0xABF0
advData=advData.."0319C203" -- appearance: ESP_BLE_APPEARANCE_HID_MOUSE
advData=advData.."0A0945737033322d424c45" -- name: Esp32-BLE

where the first hex-byte (e.g. 02) is the length, the second hex-byte is the type (e.g. 01, see esp_gap_ble_api.h for types and names) and the remaining hex-byte is the value (e.g. 06).

megazhuk commented 4 years ago

Hi friends ✌ Are there any more info about bt module? As i can see this thread is only one small piece of info about BT module. I can't find any information in wiki and other threads. May be you can make some examples or just give more information?

i want to use BLE to exchange data between 3..5 esp32 modules(with lua rtos) a control them from smartphone. May be you can show me some directions to search more info ?

Thanx guys! PS. Lua on RTOS is amazing 👍 Great project!

ziotibia81 commented 4 years ago

Hi!

I'm interested on BT support for SPP in master mode, but also in slave.

Like this:

https://github.com/espressif/arduino-esp32/blob/master/libraries/BluetoothSerial/src/BluetoothSerial.cpp