Aioble bluetooth #12428
Replies: 4 comments 2 replies
-
I don't know what's happening, but the NRF connect for mobile app by Nordic Semiconductors (free) has helped me to see what's going on, explore service, characteristics, etc |
Beta Was this translation helpful? Give feedback.
-
The lines near the top registering services / characteristics don't look right to me, that only applies to the server side, not the client
I presume the rest of the code here was based on the temp_client example the
Have you tried running temp_client.py and temp_sensor.py unmodified on your two devices to see if they work? Another thing to try, add this above async for service in connection.services():
print("service:", service) |
Beta Was this translation helpful? Give feedback.
-
@daniquedamen Yes, just to confirm that what @andrewleech is saying is correct: print(connection.service(_SENSE_UUID))
...
service = await connection.service(_SENSE_UUID) this will not work, because the first line triggers a service discovery (which is never completed because it's not awaited), and then the second one will be unable to start. Like Andrew said, you should almost be able to copy |
Beta Was this translation helpful? Give feedback.
-
Thank you. It now works indeed! But only for two reads and then it crashes into an error. Is this due to a too high frequency of reading or is there another issue? import sys
sys.path.append("")
from micropython import const
import uasyncio as asyncio
import aioble
import bluetooth
import struct
service_UUID = bluetooth.UUID("00000000-0000-0000-0000-00000000183e")
char_UUID = bluetooth.UUID("00000000-0000-0000-0000-000000000541")
def data_processing(data):
return struct.unpack("<h",data)[0]
async def find_Plushie():
async with aioble.scan(5000, interval_us=30000, window_us=30000, active=True) as scanner:
async for result in scanner:
if result.name() == "Plushie" and service_UUID in result.services():
return result.device
return None
async def main():
device = await find_Plushie()
if not device:
print("Server not found")
return
try:
print("Connecting to server:", device)
connection = await device.connect()
except asyncio.TimeoutError:
print("Timeout during connection")
return
async with connection:
try:
IMU_service = await connection.service(service_UUID)
IMU_characteristic = await IMU_service.characteristic(char_UUID)
except asyncio.TimeoutError:
print("Timeout discovering services/characteristics")
return
while True:
interaction = data_processing(await IMU_characteristic.read())
print(interaction)
await asyncio.sleep_ms(1000)
asyncio.run(main()) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to connect a microcontroller to another microcontroller. On the client site, I think everything goes well since I can obtain the characteristics of the service on my android phone. However, on the server site, I have the following code with corresponding output. As you can see, the connection can be made. However, the service/characteristics are None. I really do not know what to do anymore.
The output:
(Edited by @jimmo to fix code formatting)
Beta Was this translation helpful? Give feedback.
All reactions