micropython with ble



  • I came across the following code for ble on dfrobot firebeetle esp32:
    https://www.dfrobot.com/forum/viewtopic.php?t=2985

    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
    

    I tried it on the firebeetle and it works. When I try it on the M5 it uploads but I believe there is a difference in the network module that is keeping it from running. Is it possible for someone with micropython experience to take a look and see how this code can be ported to the m5. I'll take any suggestions I can get. thanks



  • @jpilarski Can't really help you with the problem at hand, but if you edit the message and replace <code> and </code> with three backticks ( ``` ) it will be much easier to read.



  • Another way of asking my question is how can I use bluetooth on M5go or M5stack running micropython. It seems to me like a new firmware is needed for bluetooth to be enabled. The LOBO esp32 build now looks to have bluetooth capabilities. How does one go about adding the m5stack libraries to a newer LOBO esp32 firmware or is it possible for the M5 micropython/M5go micropython firmware to be updated to include bluetooth.



  • @jpilarskimicropython with ble 中说:

    Another way of asking my question is how can I use bluetooth on M5go or M5stack running micropython. It seems to me like a new firmware is needed for bluetooth to be enabled. The LOBO esp32 build now looks to have bluetooth capabilities. How does one go about adding the m5stack libraries to a newer LOBO esp32 firmware or is it possible for the M5 micropython/M5go micropython firmware to be updated to include bluetooth.

    No full BT support is available yet in LoBo-MicroPython. BT RFCOMM is implemented (same functionality as the UART module, the documentation should be available later this week), and I'm planning to finish the BLE support next month.



  • That's amazing thanks for the response and for all the hard work. I am trying to learn micropython and the one thing I am trying to understand is for the m5go there are two files the bin and the img. If the img is the filesystem can I use esptools to upload your newer firmware bin files with the existing img file to get newer features while still having access to m5go web ide. Also is it possible to include telnet in M5STACK for webrepl. I saw you suggested in a previous discussion that is a way to use wifi and connect to repl. When I try to use telnet it isn't included in network library on M5STACK. I think what I need to learn is how I can add features to micropython firmware yet still have the M5STACK api. Can you suggest how to do this or where to learn more about this. Sorry for such a long post it's just really interesting and I want to try to understand this better.



  • @jpilarskimicropython with ble 中说:

    ... Can you suggest how to do this or where to learn more about this...

    You can use my MicroPython port on M5Stack without any changes.
    Most of the information needed can be found on the Wiki pages.
    You can find some helper functions to use it on M5Stack here.
    I'll try to add some information about using this MicroPython port on M5Stack on the Wiki pages when I'll find some time.



  • Thanks for your help much appreciated.


登录后回复
 

与 M5Stack Community 的连接断开,我们正在尝试重连,请耐心等待