#12132
There are many Micropython talents have transplanted the BLE, but the merge is unaccomplished.
It is too long to wait and I find a Micropython Esp32 board to maintain and synchronize these new features.
Codes has already been uploaded to the server. Once you update to burn, the latest code will be obtained (The test result suggests that all previous functions are uninfluenced except unstable BLE).

We would not talk about further details of BLE. And what we going to talk is low power Bluetooth, which can complete the data transmission with relatively low speed.

Necessities in need
Hardware
1.FireBeetle-ESP32 Board
2. A telephone supports BLE(Here I used iphone 5s)
Software
1. uPyCraft-0.22
2. the LightBlue (download from Apple store)

Code for ESP32
Code is as follows
Code: Select all
import gc
import sys
import network as n
import gc
import time
 
b = n.Bluetooth()
 
found = {}
complete = True
 
def bcb(b,e,d,u):
  global complete
  global found
  if e == b.CONNECT:
    print("CONNECT")
    b.ble_settings(adv_man_name = "firebeetle-esp32", adv_dev_name="firebeetle-esp32")
    b.ble_adv_enable(True)
  elif e == b.DISCONNECT:
          print("DISCONNECT")
  else:
    print ('Unknown event', e,d)
 
def cb (cb, event, value, userdata):
  print('charcb ', cb, userdata, ' ', end='')
  if event == b.READ:
    print('Read')
    return 'ABCDEFG'
  elif event == b.WRITE:
    print ('Write', value)
 
def gatts():
  s1 = b.Service(0xaabb)
  s2 = b.Service(0xDEAD)
 
  c1 = s1.Char(0xccdd)
  c2 = s2.Char(0xccdd)
 
  c1.callback(cb, 'c1 data')
  c2.callback(cb, 'c2 data')
 
  s1.start()
  s2.start()
 
  b.ble_settings(adv_man_name = "firebeetle-esp32", adv_dev_name="firebeetle-esp32")
  b.ble_adv_enable(True)
 
b.callback(bcb)
gatts()
while(True):
  pass
1.Download to the board with uPyCraft and run
Image
2.Open Lightblue and you would found that the scanned device
Image
3.Click the device, if the connection is successful, you could found two services the AABB and the DEAD
Image
4.Click any Char (here we use CCDD),then Read can read data from ESP32 Board (A-G are the characters corresponds to ASCII code:0x41-0x47 character is A-G)
Image
5.Write can input data to the ESP32 Board (input abs ( corresponding ASCII code is 0x61 0x62 0x63))
Image
6.And the ESP32 received the data.
Image
How cool it is to realize such a simple ble_peripheral (also called gattserver) ! And there will be more interesting posts tomorrow!Image
Image