-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'TypeError: can't convert NoneType to int' using aioble on Pico W #866
Comments
Personally I have always been frustrated with being able to tell what is in scope and what is not in scope in python/micropython. accel_service and accel_char are both first defined in a try - except clause and then they are accessed later outside of that clause. Now in C and in Java, those variables would be out of scope once outside of the try clause. Try something simple like placing them at the top of the file along with the
then check that they are not None before accessing them. Just because you are getting the error that what you are accessing is of NoneType suggests that they are out of scope. I recall being instructed that variables defined in a try clause should not go out of scope but that has not always been my experience. In any case, if you have not found a solution this is an easy thing to try. |
I have also gotten this error (client side) because the device has disconnected and aioble does not get that information to the client application or does not get that information to the client application in a timely manner. In the mean time the client application does something that uses components of the aioble library assuming the device is still connected and that causes the type error. In the end this was so common when working with real (market) devices I had the application set its own variables directly in the aioble disconnect event handler and used that (instead of the DeviceConnection apis) to ascertain if the device was still connected. That solved a LOT of problems! For example here:
The first two lines set the connection state in the application variable. |
Hi all,
I am trying to get two Raspberry Pi Pico W's to communicate. The Pico that transmits the data is hooked up to an accelerometer (MPU6050). As it takes the x, y, and z values from the accelerometer, it then attempts to send the data to the receiving Pico. The example code, temp_client.py and temp_sensor.py, was used as a baseline for my code. As for setup, I am using the IDE, Thonny, which is currently running MicroPython v1.22.2.
When I run the program, the two devices connect successfully, and the transmitter appears to successfully retrieve and send the data to the receiver. The problem I'm having is at the receiver end -- when I attempt to read the data using
data = accel_char.read()
, I get an error that says "TypeError: can't convert NoneType to int". I am unsure why this error is appearing, since it is written the exact way the examples have it (and I tested the example numerous times, along with using a MAX31855 breakout board to receive temperature data.) Here is the code for my receiver which I am having issues for.Receiver Output:
MPY: soft reboot
Connecting to Device(ADDR_PUBLIC, 28:cd:c1:0b:30:b9, CONNECTED)
Accel service: Service: 7 9 UUID(0x181a)
Accel characteristic: Characteristic: 11 9 10 UUID(0x2a6e)
<class 'bytes'>
Waiting until data is not None
Received data type: <class 'bytes'>
b''
Traceback (most recent call last):
File "", line 195, in
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 "", line 173, in main
File "aioble/client.py", line 251, in read
TypeError: can't convert NoneType to int
The receiver initially does not receive any data (as marked by b''), but I figure this is due to a timing issue. To my understanding, this error should still not be happening despite this since the datatype of the received data is 'bytes.'
Any help would be greatly appreciated! I've been stuck on this problem for a couple weeks now and have not found a solution despite scrounging through numerous discussion posts and comparing my code to the original example code multiple times. I originally thought it was because the service and characteristic was not being registered properly, but I added a short delay to ensure that it is and the problem is still occurring. I've also added my transmitter code below just in case.
Thank you!
The text was updated successfully, but these errors were encountered: