Page 1 of 1

Micropython bluetooth is not working !!!

Posted: Tue Oct 12, 2021 7:16 am
by jahidul_islam_rahat
I'm using micropython esp32-20210902-v1.17.bin for esp32 & i tried using bluetooth following this code https://techtotinker.blogspot.com/2021/ ... tooth.html . but my phone can't communicate with my esp32's bluetooth. already tried another phone but got the same error. anyone can help me?

Re: Micropython bluetooth is not working !!!

Posted: Wed Oct 13, 2021 12:49 am
by wangshujun@tom.com
The GitHub repository examples using microPython1.17 can be run

Third party examples may only apply to older versions

Re: Micropython bluetooth is not working !!!

Posted: Thu Oct 14, 2021 8:16 pm
by dork3nergy
I was also unable to get this to work. My understanding is that BLE communications will work but the BLE Pairing has not been implemented yet. As far as I can tell, BLE on ESP32 is kind of useless without the ability to pair devices. Does anyone else have any insights on this or when Bluetooth will be usable?

Re: Micropython bluetooth is not working !!!

Posted: Mon Oct 25, 2021 2:42 pm
by manpowre
weird, I got my Arduino ro2040 connect to pair with my iphone with this code, still developing it. My plan is to send data over BT to the microcontroller to do stuff with motors and neopixels:))

Code: Select all

import bluetooth
bt = bluetooth.BLE()
bt.active(True)

UUID_HR = const(0x2A37)

_IRQ_ALL = const(0xffff)
HR_SERVICE = bluetooth.UUID(0x180D)
HR_CHAR = (bluetooth.UUID(UUID_HR), bluetooth.FLAG_READ|bluetooth.FLAG_NOTIFY,)
CID = None

((HR,),) = bt.gatts_register_services(((HR_SERVICE, (HR_CHAR,),),))

def bt_irq(event, data):
  # >> bt irq 1 (64, 1, b'Y\xeb\n@uZ')
  global CID
  DATA=None
  if len(data)==2: #connection only, no data
      CID,EID = data
  else:
      CID,EID, DATA = data
  
  print(data, len(data))
  #print('connected > evt:{} id:{} eid:{} data:{}'.format(event,CID,EID,DATA))


bt.irq(bt_irq)

def adv_encode(adv_type, value):
  return bytes((len(value) + 1, adv_type,)) + value

def adv_encode_name(name):
  return adv_encode(0x09, name.encode())

def adv():
  bt.gap_advertise(100, adv_encode(0x01, b'\x06') + adv_encode(0x03, b'\x0d\x18') +
                   adv_encode(0x19, b'\xc1\x03') + adv_encode_name('newname'))

def send(val=0):
  # b'\x00\x42'
  ba = bytearray(2)
  ba[1]=val
  bt.gatts_notify(64, HR, ba)

adv()