ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • webOS OSE 2.X :: 블루투스 스피커 또는 이어폰으로 음악듣기
    Development/webOS 2020. 4. 22. 14:22

    오늘은 webOS OSE 2.X 버전에서 블루투스 스피커 또는 이어폰을 연결하여 유투브의 음악을 듣는 방법을 알려드리려 합니다.

     

    준비물

    - webOS OSE 2.x 가 설치된 라즈베리파이

    - QCY T5 (저는 이것으로 설명하겠지만, 다른 것도 가능합니다.)

     

    이번 시간에는 콘솔에서 직접 Luna-Send 명령을 입력하여 블루투스 헤드셋을 페어링 시키고 음악을 듣는 과정에 대해서만 설명하고, 애플리케이션에서 사용하는 방법에 대해서는 따로 설명하지 않겠습니다. 이 부분은 애플리케이션에서 Luna Service API를 사용하는 방법에 대해서 설명한 아래 링크를 참고하세요.

    https://www.webosose.org/docs/guides/development/web-apps/using-ls2-api-in-web-apps/

     

    Using LS2 API in Web Apps

    To utilize the platform capabilities in your web app, you can use LS2 API. This page describes how to use LS2 API in your web app, with an example of the following dummy service and method: Service name: com.webos.service. Method name: <m< p=""> </m<>

    www.webosose.org

    그럼 아래 순서에 따라 진행해 보겠습니다. 

     

    1. Bluetooth 활성화

    라즈베리파이4의 블루투스를 활성화 시켜줍니다. 

    # luna-send -n 1 -f luna://com.webos.service.bluetooth2/adapter/setState '{"powered":true}'

    명령이 성공적으로 입력되었다면 다음과 같은 응답을 받습니다.

    {
        "adapterAddress": "b8:27:eb:c7:79:77",
        "returnValue": true
    }
    

     

    2. Start Discovery 명령

    블루투스가 정상적으로 동작하고 있는지 startDiscovery 명령으로 확인해 보겠습니다.

    # luna-send -n 1 -f luna://com.webos.service.bluetooth2/adapter/startDiscovery '{}'

    명령이 성공적으로 입력되었다면 다음과 같은 응답을 받습니다.

    {
        "adapterAddress": "b8:27:eb:c7:79:77",
        "returnValue": true
    }
    

     

    3. 블루투스 디바이스 탐색

    라즈베리의 블루투스 Adapter가 검색가능한 모든 Device의 리스트를 보여줍니다. 너무 많이 잡히기 때문에 연결하고자 하는 QCY T5 만 찾아보도록 하겠습니다.

    # luna-send -n 1 -f luna://com.webos.service.bluetooth2/device/getStatus'{}' | grep "QCY T5" -C 10

    명령이 성공적으로 입력되었다면 다음과 같은 응답을 받습니다.

            {
                "serviceClasses": [
                ],
                "trusted": false,
                "connectedProfiles": [
                ],
                "scanRecord": [
                ],
                "pairing": false,
                "rssi": -64,
                "name": "QCY-T5",
                "address": "1c:52:17:37:64:dc",
                "paired": false,
                "typeOfDevice": "bredr",
                "manufacturerData": {
                },
                "adapterAddress": "",
                "classOfDevice": 2098200,
                "blocked": false
            },
            {
    

    여기서 우리는 name이 "QCY T5"인 블루투스 디바이스의 Address를 확인할 수 있습니다. (Address는 블루투스 디바이스마다 다릅니다.)

     

    4. 블루투스 디바이스 탐색 종료

    원하는 정보를 확인했으므로 라즈베리파이가 디바이스를 탐색하는 것을 종료시킵니다.

    # luna-send -n 1 -f luna://com.webos.service.bluetooth2/adapter/cancelDiscovery '{}'

    명령이 성공적으로 입력되었다면 다음과 같은 응답을 받습니다.

    {
        "adapterAddress": "b8:27:eb:c7:79:77",
        "returnValue": true
    }
    

     

    5. 블루투스 페어링

    연결할 블루투스 디바이스의 주소를 알아냈다면, 이제 페어링을 시켜줍니다.

    # luna-send -i -f luna://com.webos.service.bluetooth2/adapter/pair '{ "address": "1c:52:17:37:64:dc", "subscribe":true}'

    명령이 성공적으로 입력되었다면 다음과 같은 응답을 받습니다. 

    {
        "adapterAddress": "b8:27:eb:c7:79:77",
        "subscribed": true,
        "returnValue": true
    }
    {
        "adapterAddress": "b8:27:eb:c7:79:77",
        "subscribed": false,
        "returnValue": true,
        "request": "endPairing"
    }
    

     

    6. A2DP 프로파일로 연결

    A2DP 프로파일의 Connect 명령으로 라즈베리파이에서 출력되는 소리를 블루투스 디바이스로 전달할 수 있도록 연결합니다.

    # luna-send -i -f luna://com.webos.service.bluetooth2/a2dp/connect '{"address":"1c:52:17:37:64:dc","subscribe":true}'

    명령이 성공적으로 입력되었다면 다음과 같은 응답을 받습니다. 

    {
        "address": "1c:52:17:37:64:dc",
        "subscribed": true,
        "adapterAddress": "b8:27:eb:c7:79:77",
        "returnValue": true
    }

    주의) Subscribe가 True인 상태에서 Ctrl + C 를 눌러 종료하면 Connection이 끊어집니다.

     

    이제 유투브를 실행해서 소리를 들어보세요. 

     

    7. A2DP 상태 확인

    현재 상태를 확인하려면 아래와 같이 getStatus 명령으로 블루투스 디바이스와의 연결 상태를 확인합니다.

    luna-send -i -f luna://com.webos.service.bluetooth2/a2dp/getStatus '{"address":"1c:52:17:37:64:dc", "subscribe":true}'

    명령이 성공적으로 입력되었다면 다음과 같은 응답을 받습니다. 

    {
        "playing": true,
        "adapterAddress": "b8:27:eb:c7:79:77",
        "address": "1c:52:17:37:64:dc",
        "connected": true,
        "subscribed": true,
        "returnValue": true,
        "connecting": false
    }
    {
        "playing": false,
        "adapterAddress": "b8:27:eb:c7:79:77",
        "address": "1c:52:17:37:64:dc",
        "connected": true,
        "subscribed": true,
        "returnValue": true,
        "connecting": false
    }
    {
        "playing": true,
        "adapterAddress": "b8:27:eb:c7:79:77",
        "address": "1c:52:17:37:64:dc",
        "connected": true,
        "subscribed": true,
        "returnValue": true,
        "connecting": false
    }
    

    재생 상태에 따라서 Playing 값이 변하는 것을 확인할 수 있습니다.

     

    8. A2DP 연결 종료

    더 이상 블루투스 디바이스로 음악을 듣고 싶지 않다면, A2DP 연결을 끊어 줍니다. 물론 페어링을 종료해도 되겠지만 여기서는 하나 하나 끊어 보도록 하겠습니다.

    luna-send -i -f luna://com.webos.service.bluetooth2/a2dp/disconnect '{"address":"1c:52:17:37:64:dc"}'

    명령이 성공적으로 입력되었다면 다음과 같은 응답을 받습니다. 

    {
        "adapterAddress": "b8:27:eb:c7:79:77",
        "address": "1c:52:17:37:64:dc",
        "returnValue": true
    }
    


    9. 페어링 끊기

    이젠 블루투스 디바이스가 필요없네요. 페어링을 끊고 QCY T5는 충전하러 보내겠습니다. 

    luna-send -i -f luna://com.webos.service.bluetooth2/adapter/unpair '{"address":"1c:52:17:37:64:dc"}'

    명령이 성공적으로 입력되었다면 다음과 같은 응답을 받습니다.

    {
        "adapterAddress": "b8:27:eb:c7:79:77",
        "returnValue": true
    }
    

     

    webOS OSE 2.X에서 블루투스 스피커 또는 이어폰 사용하는 방법 어렵지 않습니다. 자 이제는 여러분의 차례 !!!

    블루투스를 활용한 간단한 애플리케이션을 만들어 보시면 어떨까요?

     

    더 많은 블루투스 관련 API 가 궁금하신가요? 아래 링크를 확인하세요.

    https://www.webosose.org/docs/reference/ls2-api/com-webos-service-bluetooth2/

     

    com.webos.service.bluetooth2

    API Summary This API allows webOS to use remote Bluetooth devices.  Overview of the API Bluetooth Service Categories adapter: Provides methods for discovering and pairing with remote Bluetooth devices and for querying their status and Bluetooth adapters av

    www.webosose.org

     

    댓글

Designed by Tistory.