Skip to content

"TypeError: can't convert NoneType to int" on Raspberry Pi Pico W with aioble #817

@jxpd

Description

@jxpd

I am writing a program for the Raspberry Pi Pico W that sends commands to control the blinkers of a Lumos Kickstart Bluetooth helmet via BLE to later hook it up with the blinkers of my Ninebot e-Scooter.

Device: Raspberry Pi Pico W (sysname='rp2', nodename='rp2', release='1.22.2', version='v1.22.2 on 2024-02-22 (GNU 13.2.0 MinSizeRel)', machine='Raspberry Pi Pico W with RP2040')
MicroPython version: 1.22.2
aioble version: 0.4.1 (installed via the package manager in Thonny)

I have managed to send the first command (Blink right) successfully, but every time I intend to send another command with the method await temp_characteristic.write(), I get an error like this with "TypeError: can't convert NoneType to int":

Sent 'blink right' command to LumosHelmet.
Sent 'turn off' command to LumosHelmet.
Traceback (most recent call last):
  File "<stdin>", line 97, in <module>
  File "asyncio/core.py", line 1, in run
  File "asyncio/core.py", line 1, in run_until_complete
  File "asyncio/core.py", line 1, in run_until_complete
  File "<stdin>", line 75, in main
  File "aioble/client.py", line 288, in write
TypeError: can't convert NoneType to int

I must admit that I am still a beginner at python, and I would be thankful if anyone could tell me where the problem lies.
Here is the part of the code that causes the problem (in the while True loop):

async def main():
    device = await scan_and_connect()
    if not device:
        print("Lumos Helmet not found.")
        return
    try:
        print("Connecting to ", device)
        connection = await device.connect()
    except asyncio.TimeoutError:
        print("Timeout during connection")
        return
    
    async with connection:
        try:
            # Get the service and characteristic for the UART Tx
            temp_service = await connection.service(SERVICE_UUID)
            temp_characteristic = await temp_service.characteristic(UART_TX_UUID)
        except asyncio.TimeoutError:
            print("Timeout discovering services/characteristics")
            return
        
        while True:
            if temp_characteristic is not None:
                # Send the "blink right" command
                await temp_characteristic.write(BLINK_RIGHT_CMD)
                print("Sent 'blink right' command to LumosHelmet.")
                
                # Sleep a bit            
                await asyncio.sleep_ms(2000)
            else:
                print("Characteristic not found.")
            
            if temp_characteristic is not None:
                # Send the "turn off" command
                await temp_characteristic.write(TURN_OFF_CMD)
                print("Sent 'turn off' command to LumosHelmet.")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions