write bluetooth FiPy
-
Hello,
I don't understand why, but when I do char.write(), nothing happens... It print well 'ok' then I can wait nothing happens... Thanks if you have an idea !from network import Bluetooth import time import ubinascii bt = Bluetooth() bt.start_scan(-1) while True: adv = bt.get_adv() if adv: print(ubinascii.hexlify(adv.mac)) if bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL) == 'Blabla': try: conn = bt.connect(adv.mac) services = conn.services() for service in services: time.sleep(0.050) if service.uuid() == XXX print('Reading chars from service = %x' % service.uuid()) chars = service.characteristics() for char in chars: if (char.uuid()==XXX): if(char.properties() & Bluetooth.PROP_WRITE): print('ok') char.write(b'0xa01f') conn.disconnect() break except: pass else: time.sleep(0.050)
-
@jcaron I read several articles to invert the bytes and read the right values. If I have val= b'\xdd\xee' tanks to struct.pack('<h', *struct.unpack('>h', val)) I get the inverse val= b'\xee\xdd'.
However, for val= b'\xxaa\xbb\xcc\xdd' I can't find a way to get val=b'\xdd\xcc\xbb\xaa'.
Do you have any idea how to help me? Thank you in advance!
-
@jcaron Thank you for your help, it works the way I wanted it to! Thanks for your advice.
-
@Tgasser You have the code-quoting quotes the wrong way around, it's ```
I don't think you are sending what you think or want: you are sending the characters 0, x, a, 0, 1, f, not 0xa0 and 0x1f.
Instead of
b'0xa01f'
, you can writeb'\xa0\x1f'
orbytes([0xa0,0x1f]
.Note that the order may be reversed based on the required endianness.