About BLE.gap_connect(esp32-based ubluetooth)

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
net0040
Posts: 26
Joined: Fri Nov 08, 2019 4:33 am

Re: About BLE.gap_connect(esp32-based ubluetooth)

Post by net0040 » Wed Nov 20, 2019 12:28 pm

jimmo wrote:
Wed Nov 20, 2019 4:14 am
net0040 wrote:
Wed Nov 20, 2019 2:59 am
conn_handle always return 0, I have also seen the posts of other players in the forum, should be a non-0 integer.
It depends on which port and the BLE implementation. On ESP32, the conn_handle will typically be around 0, on STM32 it starts at 64.
net0040 wrote:
Wed Nov 20, 2019 2:59 am
2, Will the PR you sent be integrated into the firmware. I'm brush v.1120 firmware tonight and try again, thank you.
I hope so, but not sure how quickly. You can always build using my branch instead though if you want to try out the fix. https://github.com/jimmo/micropython/tr ... er-example
ERROR:

Code: Select all

>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
  File "<stdin>", line 9, in <module>
ImportError: no module named 'ble_advertising'
I try two Firmware:
1.

Code: Select all

MicroPython v1.10-298-g47e76b527 on 2019-04-18; ESP32 module with ESP32

Type "help()" for more information.
>>> 
2.

Code: Select all

esp32-idf4-20191119-v1.11-580-g973f68780.bin
both error.

thanks

User avatar
net0040
Posts: 26
Joined: Fri Nov 08, 2019 4:33 am

Re: About BLE.gap_connect(esp32-based ubluetooth)

Post by net0040 » Wed Nov 20, 2019 1:53 pm

sorry,I find ble_advertising.py ,and import it.

thanks.

User avatar
net0040
Posts: 26
Joined: Fri Nov 08, 2019 4:33 am

Re: About BLE.gap_connect(esp32-based ubluetooth)

Post by net0040 » Wed Nov 20, 2019 3:00 pm

code:

Code: Select all

 def _irq(self, event, data):
        if event == _IRQ_SCAN_RESULT:
            addr_type, addr, connectable, rssi, adv_data = data
            print(addr_type,bytes(addr),decode_services(adv_data))

Code: Select all

>>> %Run -c $EDITOR_CONTENT
0 b'\xf4^\xab\x91k\x97' []
0 b'\xf4^\xab\x91k\x97' []
0 b'\xf4^\xab\x91k\x97' []
0 b'\xf4^\xab\x91k\x97' []
0 b'\xf4^\xab\x91k\x97' []
0 b'\xf4^\xab\x91k\x97' []
0 b'\xf4^\xab\x91k\x97' []
0 b',A\xa1\x971\xcd' [UUID16(0xfebe)]
0 b'\xf4^\xab\x91k\x97' []
0 b'\xf4^\xab\x91k\x97' []
0 b'\xf4^\xab\x91k\x97' []
0 b'\xf4^\xab\x91k\x97' []
0 b',A\xa1\x971\xcd' [UUID16(0xfebe)]
0 b'\xf4^\xab\x91k\x97' []
0 b'\xf4^\xab\x91k\x97' []
0 b'\xf4^\xab\x91k\x97' []
0 b'\xf4^\xab\x91k\x97' []
No sensor found.
>>> 
b'\xf4^\xab\x91k\x97' is my heart rate belt,after decode_services(adv_data),It looks empty.so,No sensor found.

Code: Select all

esp32-idf4-20191119-v1.11-580-g973f68780.bin
thanks.

User avatar
net0040
Posts: 26
Joined: Fri Nov 08, 2019 4:33 am

Re: About BLE.gap_connect(esp32-based ubluetooth)

Post by net0040 » Wed Nov 20, 2019 3:53 pm

I used two examples of you, one is ble thermometer(another esp32), the other is reading thermometer data as central role.
During the test, two problems were encountered:
1、

Code: Select all

    def _irq(self, event, data):
        if event == _IRQ_SCAN_RESULT:
            addr_type, addr, connectable, rssi, adv_data = data
            print(addr_type, bytes(addr),decode_services(adv_data),_ENV_SENSE_UUID, _ENV_SENSE_UUID in decode_services(adv_data) ,connectable)
            if connectable and _ENV_SENSE_UUID in decode_services(adv_data):
            #if connectable:
                # Found a potential device, remember it and stop scanning.
                self._addr_type = addr_type
                self._addr = bytes(addr) # Note: The addr buffer is owned by modbluetooth, need to copy it.
                self._name = decode_name(adv_data) or '?'
                self._ble.gap_scan(None)
result:

Code: Select all

>>> %Run -c $EDITOR_CONTENT
0 b'<q\xbfF\x05Z' [UUID16(0x181a)] UUID16(0x181a) False True
0 b'<q\xbfF\x05Z' [UUID16(0x181a)] UUID16(0x181a) False True
0 b'<q\xbfF\x05Z' [UUID16(0x181a)] UUID16(0x181a) False True
0 b'<q\xbfF\x05Z' [UUID16(0x181a)] UUID16(0x181a) False True
No sensor found.
_ENV_SENSE_UUID= [UUID16(0x181a)]
decode_services(adv_data) UUID16(0x181a)
but:

Code: Select all

_ENV_SENSE_UUID in decode_services(adv_data) 
is false
2、When I commented out some code, the sensor was searched. After I run the code of ble thermometer (another esp32), I have conducted joint debugging with my mobile phone, The ble thermometer is works.

result:

Code: Select all

>>> %Run -c $EDITOR_CONTENT
0 b'<q\xbfF\x05Z' [UUID16(0x181a)] UUID16(0x181a) False True
Found sensor: 0 b'<q\xbfF\x05Z' mpy-temp
0 0 b'<q\xbfF\x05Z'
0 1 5 UUID16(0x0000)
0 6 10 UUID16(0x0000)
0 11 65535 UUID16(0x001a)
Do I need some bug to be fixed?
thanks

User avatar
iotman
Posts: 45
Joined: Sat Feb 02, 2019 4:06 pm
Location: Nanoose Bay, Canada
Contact:

Re: About BLE.gap_connect(esp32-based ubluetooth)

Post by iotman » Fri Nov 22, 2019 5:37 pm

Hi, just wanted to quickly ask what this means on the download page:

Firmware built with ESP-IDF v4.x, with support for bluetooth but no LAN or PPP:

GENERIC : esp32-idf4-20191122-v1.11-586-g1530fda9c.bin

Does this mean BLE will be functional, or at least partially functional for testing? What does the "no LAN or PPP" part mean? Is that referring to some kind of missing wifi capability?

Tks, AB

mczubel
Posts: 3
Joined: Thu Oct 17, 2019 12:24 pm

Re: About BLE.gap_connect(esp32-based ubluetooth)

Post by mczubel » Fri Nov 22, 2019 8:29 pm

Hi
In ble_uart_peripheral.py file, line 26, I have the AttributeError: 'BLE' object has no attribute 'gatts_set_buffer'
How fix it??
1000 thanks

User avatar
jimmo
Posts: 878
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: About BLE.gap_connect(esp32-based ubluetooth)

Post by jimmo » Fri Nov 22, 2019 10:15 pm

iotman wrote:
Fri Nov 22, 2019 5:37 pm
Does this mean BLE will be functional, or at least partially functional for testing? What does the "no LAN or PPP" part mean? Is that referring to some kind of missing wifi capability?
Both versions support WiFi. The issue is that we had to use a newer version of the IDF (the ESP32 SDK) to enable Bluetooth, but this broke the MicroPython driver for LAN (i.e. _wired_ ethernet) and PPP (useful for 3G modems).

So we are providing firmware built with both the old and new IDF so that people who need LAN or PPP can still use it.

Also, last time I checked, the new version of the IDF is still not released yet (we're using beta1) so that might be a consideration for some people.

I hope that someone from the community will update the PPP and LAN drivers to use the new SDK. I lack the hardware to test this on.

User avatar
jimmo
Posts: 878
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: About BLE.gap_connect(esp32-based ubluetooth)

Post by jimmo » Fri Nov 22, 2019 10:16 pm

mczubel wrote:
Fri Nov 22, 2019 8:29 pm
In ble_uart_peripheral.py file, line 26, I have the AttributeError: 'BLE' object has no attribute 'gatts_set_buffer'
How fix it??
What firmware version are you using? (Hit Ctrl-D at the REPL and grab the version that's printed there, or just the filename that you used to flash it would be fine)

mczubel
Posts: 3
Joined: Thu Oct 17, 2019 12:24 pm

Re: About BLE.gap_connect(esp32-based ubluetooth)

Post by mczubel » Sat Nov 23, 2019 1:01 am

jimmo wrote:
Fri Nov 22, 2019 10:16 pm
mczubel wrote:
Fri Nov 22, 2019 8:29 pm
In ble_uart_peripheral.py file, line 26, I have the AttributeError: 'BLE' object has no attribute 'gatts_set_buffer'
How fix it??
What firmware version are you using? (Hit Ctrl-D at the REPL and grab the version that's printed there, or just the filename that you used to flash it would be fine)
Sorry, I replace 422-g98c2eabaf 20191011 with 586-g1530fda9c 20191122 and now work perfect.
1000 thanks and sorry again

mczubel
Posts: 3
Joined: Thu Oct 17, 2019 12:24 pm

Re: About BLE.gap_connect(esp32-based ubluetooth)

Post by mczubel » Sat Nov 23, 2019 12:20 pm

I'm newly in esp32 ble, with this firmware: can I set esp32 ble like a beacon?
adv packet with conn posibility

Post Reply