Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
RoSy_3754371
Level 1
Level 1
First like given

Hi

I am having trouble understanding how to connect a ESS client to ESS server using the service UUID.

I edited the SimpleBLECentral code to scan for Bluetooth devices and connect to a server with a advertisement packet length of 30. This works fine but the client connects to any device with a packet length 30. I want to edit this by connecting to a ESS peripheral device (with the UUID 181A).

The SimpleBLECentral project compared the scanned servcie UUID with an expected UUID and if the are the same, it pairs and does whatever it needs to thereafter.

For my project I cannot find the required reference for the expected ESS UUID.  Is my approach incorrect? How do I get around this? Below is the particular snip of code i am working on. I have commented out the other if statements (SimpleBLECentral and the length statements) and highlighted where my issue is. My guess is there is no direct reference o the UUID, but I get lost when it comes to deciphering the structure pointers, and I am not confident i understand how they reference the correct member.

Additionally, I am having trouble actually printing out the UUID when I do connect to a ESS it in the message printed once. This is a minor issue but if you can see where my issue is as regards this, id be grateful if you can point me in the right direction.

Thanks in advance for any help.

       case CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT:          

           

            // Print Out Information about the Device that was found

            printf("Device ");

           

            cy_stc_ble_gapc_adv_report_param_t  *scanProgressParam = (cy_stc_ble_gapc_adv_report_param_t  *)eventParameter;

           

            printf("BD Addr: ");          

            for(unsigned int i=0;i<CY_BLE_BD_ADDR_SIZE;i++)

                printf("%02X",scanProgressParam->peerBdAddr);          

            printf("\tLength: %d ",scanProgressParam->dataLen);

            printf("\tRssi: %d",scanProgressParam->rssi);

            //printf("Data Received:\t\t%.*s\r\n\r\n",currentAdvInfo.sensorData_len, currentAdvInfo.sensorData);

           

            findAdvInfo(scanProgressParam->data,scanProgressParam->dataLen);

           

            if(currentAdvInfo.name != 0)

                printf("%.*s",currentAdvInfo.name_len,currentAdvInfo.name);             

            printf("\r\n");            

           

            //if the advertised data length matches the scanned data length for EnviroSensor(25), attempt to connect

            //if(scanProgressParam->dataLen==30)

//            if(currentAdvInfo.servUUID_len > 0

//                && memcmp(currentAdvInfo.serviceUUID,cy_ble_customCServ [CY_BLE_CUSTOMC_LED_SERVICE_INDEX].uuid,

//                currentAdvInfo.servUUID_len) == 0)

            if(currentAdvInfo.servUUID_len>0

               &&memcmp(currentAdvInfo.serviceUUID,cy_ble_ess , currentAdvInfo.servUUID_len)==0)

            {

                Cy_GPIO_Write(GREEN_0_PORT, GREEN_0_NUM, 1);

                printf("\r\nFound ESS Service");

                cy_stc_ble_bd_addr_t connectAddr;

                memcpy(&connectAddr.bdAddr[0], &scanProgressParam->peerBdAddr[0] , CY_BLE_BD_ADDR_SIZE);

                connectAddr.type = scanProgressParam->peerAddrType;

               

                Cy_BLE_GAPC_ConnectDevice(&connectAddr,0);

                Cy_BLE_GAPC_StopScan();              

                //if connection is successful

                if(CY_BLE_EVT_GATT_CONNECT_IND)

                {

                    printf("\r\nConnection Success\r\n");                           //print information about connected device

                    printf("\r\nConnected to:\t\t");         //device name

                    printf("%.*s\r\n",currentAdvInfo.name_len,currentAdvInfo.name);

                    printf("Name Length:\t\t%d \r\n",currentAdvInfo.name_len);      //length of device name

                    printf("Service UUID:\t");                               // uuid

                    printf("%.*s\r\n",currentAdvInfo.servUUID_len,currentAdvInfo.serviceUUID);

                    printf("Data Received:\t\t%.*s\r\n\r\n",currentAdvInfo.sensorData_len, currentAdvInfo.sensorData);

                    Cy_GPIO_Write(LED9_0_PORT,LED9_0_NUM,0);                        //Light LED9   

                }

            }

        break;

0 Likes
1 Solution

Obviously, you have get what you want in currentAdvInfo. The serviceUUID points to '0x1A' and ServUUID_len is 0x02. They are correct.

The problem is below printing sentence can not print the UUID correctly -

printf("%.*s\r\n",currentAdvInfo.servUUID_len,currentAdvInfo.serviceUUID);

It is used to print a string, instead of hexadecimal number.

View solution in original post

6 Replies