![]() |
sending byte in code? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: sending byte in code? (/thread-38566.html) |
sending byte in code? - korenron - Oct-30-2022 Hello, I'm working on some BLE code that need to send 01 \ 00 in order to turn on a remote LED. this is the command I'm using await client.write_gatt_char(Led_Char, b'\01') # send new valueand right now I'm working not smart : New_Led_Status = input(''' Enter new led status: 3 - Led1 - off 2 - Led1 on 1 - Led on , 0 - led off , ''' ) if New_Led_Status == "1": await client.write_gatt_char(Led_Char, b'\01',) elif New_Led_Status == "0": await client.write_gatt_char(Led_Char, b'\00') elif New_Led_Status == "2": await client.write_gatt_char(Led_Char, b'\02')I want to enter the value inside 1 command and not write the same command many times(I'm going to handle more options) what do I need to change? and another issue when I run the code on Windows - it's working, when I run the code on Linux - it's not sending , I get nothing on the remote device on linux I have Python 3.7.3 on windows I have Python 3.10 can this be reason ? - if so what do I need to change? *** using the same code , and I don't get any errors what could be the problem? Thanks , RE: sending byte in code? - deanhystad - Oct-30-2022 There is an int.to_bytes() method. You could convert your int string to an int, then convert that to bytes. New_Led_Status = 2 New_Led_Status = int(New_Led_Status).to_bytes(length=1, byteorder='big') print(New_Led_Status)
RE: sending byte in code? - korenron - Oct-30-2022 Great - it's working Thanks , |