Hi Jimmo, thanks for your reply, I did some further reading and it seems that I can use the
service class ID.
I tried to follow through checking the characteristics with this code:
Code: Select all
import time
import bluetooth
import binascii
from micropython import const
_IRQ_CENTRAL_CONNECT = const(1 << 0)
_IRQ_CENTRAL_DISCONNECT = const(1 << 1)
_IRQ_GATTS_WRITE = const(1 << 2)
_IRQ_GATTS_READ_REQUEST = const(1 << 3)
_IRQ_SCAN_RESULT = const(1 << 4)
_IRQ_SCAN_COMPLETE = const(1 << 5)
_IRQ_PERIPHERAL_CONNECT = const(1 << 6)
_IRQ_PERIPHERAL_DISCONNECT = const(1 << 7)
_IRQ_GATTC_SERVICE_RESULT = const(1 << 8)
_IRQ_GATTC_CHARACTERISTIC_RESULT = const(1 << 9)
_IRQ_GATTC_DESCRIPTOR_RESULT = const(1 << 10)
_IRQ_GATTC_READ_RESULT = const(1 << 11)
_IRQ_GATTC_WRITE_STATUS = const(1 << 12)
_IRQ_GATTC_NOTIFY = const(1 << 13)
_IRQ_GATTC_INDICATE = const(1 << 14)
def bt_irq(event, data):
if event == _IRQ_CENTRAL_CONNECT:
# A central has connected to this peripheral.
conn_handle, addr_type, addr = data
elif event == _IRQ_CENTRAL_DISCONNECT:
# A central has disconnected from this peripheral.
conn_handle, addr_type, addr = data
elif event == _IRQ_GATTS_WRITE:
# A central has written to this characteristic or descriptor.
conn_handle, attr_handle = data
elif event == _IRQ_GATTS_READ_REQUEST:
# A central has issued a read. Note: this is a hard IRQ.
# Return None to deny the read.
# Note: This event is not supported on ESP32.
conn_handle, attr_handle = data
elif event == _IRQ_SCAN_RESULT:
# A single scan result.
addr_type, addr, connectable, rssi, adv_data = data
elif event == _IRQ_SCAN_COMPLETE:
# Scan duration finished or manually stopped.
pass
elif event == _IRQ_PERIPHERAL_CONNECT:
# A successful gap_connect().
conn_handle, addr_type, addr = data
elif event == _IRQ_PERIPHERAL_DISCONNECT:
# Connected peripheral has disconnected.
conn_handle, addr_type, addr = data
elif event == _IRQ_GATTC_SERVICE_RESULT:
# Called for each service found by gattc_discover_services().
conn_handle, start_handle, end_handle, uuid = data
elif event == _IRQ_GATTC_CHARACTERISTIC_RESULT:
# Called for each characteristic found by gattc_discover_services().
conn_handle, def_handle, value_handle, properties, uuid = data
elif event == _IRQ_GATTC_DESCRIPTOR_RESULT:
# Called for each descriptor found by gattc_discover_descriptors().
conn_handle, dsc_handle, uuid = data
elif event == _IRQ_GATTC_READ_RESULT:
# A gattc_read() has completed.
conn_handle, value_handle, char_data = data
elif event == _IRQ_GATTC_WRITE_STATUS:
# A gattc_write() has completed.
conn_handle, value_handle, status = data
elif event == _IRQ_GATTC_NOTIFY:
# A peripheral has sent a notify request.
conn_handle, value_handle, notify_data = data
elif event == _IRQ_GATTC_INDICATE:
# A peripheral has sent an indicate request.
conn_handle, value_handle, notify_data = data
bt = bluetooth.BLE()
bt.active(True)
bt.irq(handler=bt_irq)
bt.gap_connect(0, b'\xc4|\x8df\xdd\xf0', 2000)
time.sleep(5)
bt.gattc_discover_services(0)
bt.gattc_discover_characteristics(0, 49, 57)
time.sleep(10)
bt.gap_disconnect(0)
which seems to work pretty well (although everything is hardcodec,) but I get a esp32 reboot
:
Code: Select all
/pyboard> repl
Entering REPL. Use Control-X to exit.
>
MicroPython v1.12 on 2019-12-20; ESP32 module (spiram) with ESP32
Type "help()" for more information.
>>>
>>> import nexter
I (1251519) phy: phy_version: 4102, 2fa7a43, Jul 15 2019, 13:06:06, 0, 0
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x4015c4d0 PS : 0x00060430 A0 : 0x8016403b A1 : 0x3ffbb460
A2 : 0x3ffc6fcc A3 : 0x00000000 A4 : 0x3f429fbe A5 : 0x3ffc2d38
A6 : 0x00000003 A7 : 0x3ffc2d0c A8 : 0x00000000 A9 : 0x3ffbb420
A10 : 0x3ffc6fcc A11 : 0x00000000 A12 : 0x00000004 A13 : 0x3ffbb460
A14 : 0x00000001 A15 : 0x00000000 SAR : 0x00000010 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000004 LBEG : 0x4009d410 LEND : 0x4009d43e LCOUNT : 0x00000000
ELF file SHA256: 0000000000000000000000000000000000000000000000000000000000000000
Backtrace: 0x4015c4cd:0x3ffbb460 0x40164038:0x3ffbb490 0x4015e64d:0x3ffbb4d0 0x40160f3d:0x3ffbb500 0x4015e295:0x3ffbb530 0x4015e2a7:0x3ffbb550 0x4015d136:0x3ffbb570 0x400f9317:0x3ffbb590 0x400999b5:0x3ffbb5b0
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4988
load:0x40078000,len:11408
load:0x40080400,len:6108
entry 0x400806bc
I (601) psram: This chip is ESP32-D0WD
E (601) spiram: SPI RAM enabled but initialization failed. Bailing out.
I (601) cpu_start: Failed to init external RAM; continuing without it.
I (609) cpu_start: Pro cpu up.
I (612) cpu_start: Application information:
I (617) cpu_start: Compile time: Dec 20 2019 07:58:58
I (623) cpu_start: ELF file SHA256: 0000000000000000...
I (629) cpu_start: ESP-IDF: v4.0-beta1
I (634) cpu_start: Starting app cpu, entry point is 0x400835e0
I (627) cpu_start: App cpu up.
I (645) heap_init: Initializing. RAM available for dynamic allocation:
I (652) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (658) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (664) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (670) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM
I (676) heap_init: At 3FFCCA50 len 000135B0 (77 KiB): DRAM
I (682) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (689) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (695) heap_init: At 4009E2E4 len 00001D1C (7 KiB): IRAM
I (701) cpu_start: Pro cpu start user code
I (720) spi_flash: detected chip: generic
I (720) spi_flash: flash io: dio
I (721) cpu_start: Chip Revision: 1
W (722) cpu_start: Chip revision is higher than the one configured in menuconfig. Suggest to upgrade it.
I (732) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
E (40) spiram: SPI RAM not initialized
MicroPython v1.12 on 2019-12-20; ESP32 module (spiram) with ESP32
Type "help()" for more information.
>>>
Do you have an idea what I may be missing?