I am trying to connect my Vivoactive 5 to a Raspberry Pi Pico 2 W. My app is based on CIQpi https://forums.garmin.com/developer/connect-iq/b/news-announcements/posts/would-you-like-some-raspberry-pi-with-your-connect-iq.
I cant connect to the Raspberry Pi Pico. I can call Ble.pairDevice(scanResult) and get a device back, but onConnectedStateChanged never gets called.
This is my Pi code:
import sys
sys.path.append("")
from micropython import const
import uasyncio as asyncio
import aioble
import bluetooth
SERVICE_UUID = bluetooth.UUID("0F3DF50F-09C0-40A5-8208-9836C6040B00")
CHAR_UUID = bluetooth.UUID("0F3DF50F-09C0-40A5-8208-9836C6040B23")
ADV_APPEARANCE = const(128)
ADV_INTERVAL_MS = 100000
service = aioble.Service(SERVICE_UUID)
characteristic = aioble.Characteristic(
service, CHAR_UUID, read=True, notify=True, write=True, capture=True
)
aioble.register_services(service)
async def peripheral_task():
while True:
async with await aioble.advertise(
ADV_INTERVAL_MS,
name="mpy-temp",
services=[SERVICE_UUID],
appearance=ADV_APPEARANCE,
) as connection:
print("Connection from", connection.device)
while connection.is_connected():
try:
_, data = await characteristic.written(timeout_ms=10000)
print("Received", data)
except asyncio.TimeoutError:
print("Timeout waiting for write")
await asyncio.sleep(1)
asyncio.run(peripheral_task())