pycom / pycom-micropython-sigfox

A fork of MicroPython with the ESP32 port customized to run on Pycom's IoT multi-network modules.
MIT License
199 stars 167 forks source link

BLE: GATTCCharacteristics.write('value') doesn't work! #38

Open Mungio opened 7 years ago

Mungio commented 7 years ago

I use a WiPy 2.0 with firmware 1.7.6.b1.

I notice that with firmware 1.7.6.b1 now the BLE connection function works fine. Now it is possible discover all services and characteristics, but the write function on a characteristic does not work. In my code example chars[0] is a PROP_WRITE charateristic, but when I write something on it, anything happen.

from network import Bluetooth
import ubinascii
import machine
import uos
import utime

bt = Bluetooth()
bt.start_scan(-1)
while True:
    adv = bt.get_adv()
    try:
        if adv and bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL) == 'X-DOM-NC':
            print(adv.mac)
            conn = bt.connect(adv.mac)
            while not conn.isconnected():
                machine.idle()
            print("connected")
            print(conn)
            services = conn.services()
            print("services")
            print(services)
            print(services[0].uuid())
            print(services[1].uuid())
            print(services[2].uuid())
            chars = services[2].characteristics()
            print(chars)
            print(chars[0].properties())
            print(chars[1].properties())
            print(chars[0].uuid())
            print(chars[1].uuid())
            chars[0].write(b'x0f')
            utime.sleep(2)
            break
    except:
        print("Error while connecting or reading from the BLE device")
        break
while True:
    pass
conn.disconnect()

Instead, if chars[0] has a property PROP_WRITE_NR the write function works fine!

husigeza commented 6 years ago

Hello! Could you still reproduce this issue ? Thanks!