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) -
@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.
-
@jcaron Thank you for your help, it works the way I wanted it to! Thanks for your advice.
-
@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!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login