Receiving a uint32 variable from PSoC 4 BLE via AppInventor's BLE extension

Hello everyone :smiley:, I'm trying to read a sensor's data from PSoC4 BLE kit and display it on my android phone (Xiaomi Mi 9).

For this I have configured the BLE module of the PSoC's 4 BLE as a peripheral GAP and a GATT Server with a Custom Service. The characteristic has the read and notify properties, plus I have the UUID for service and characteristic. The value's type I'm trying to get is uint32.

I know it's working because I've read the value using CySmart App for debugging and it also works on the BLE Scanner app.

So far, the app connects succesfully to the PSoC but I don't seem to get the data.

I attach the app inventor project. If more info is needed please let me know

Thanks, I appreciate your help

App_copy.aia (191.3 KB)

Hello Invento

More Info would be the script that sends the value to the App.

Sure, this is the section related to the BLE communication:

void updateBPM(){
CYBLE_GATTS_HANDLE_VALUE_NTF_T tempHandle;
if(CyBle_GetState() != CYBLE_STATE_CONNECTED){
    return;
}
tempHandle.attrHandle = CYBLE_BPMSPO2_BPM_CHAR_HANDLE;
tempHandle.value.val = (uint8 *)&promedioBPM;
tempHandle.value.len = 4;
CyBle_GattsWriteAttributeValue(&tempHandle,0,&cyBle_connHandle,0);

if(BPMNotify){
    CyBle_GattsNotification(cyBle_connHandle,&tempHandle);
    
}

}
//BLE STACK
void BleCallBack(uint32 event, void* eventParam{

CYBLE_GATTS_WRITE_REQ_PARAM_T *wrReqParam;

switch(event){
    case CYBLE_EVT_STACK_ON:
        CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);    
        PWM_Start();
    break;
        
    case CYBLE_EVT_GAP_DEVICE_DISCONNECTED:
        BPMNotify = 0;
        CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST); 
        PWM_Start();
    break;
        
    //Update BPM Value
    case CYBLE_EVT_GATT_CONNECT_IND:
        updateBPM();
        PWM_Stop();
    break;
        
    //Write request
    case CYBLE_EVT_GATTS_WRITE_REQ:
        wrReqParam = (CYBLE_GATTS_WRITE_REQ_PARAM_T *) eventParam;
        
        //Petición de actualizar notificación de BPM
        if(wrReqParam->handleValPair.attrHandle == CYBLE_BPMSPO2_BPM_BPMCCCD_DESC_HANDLE){
            CyBle_GattsWriteAttributeValue(&wrReqParam->handleValPair, 0, &cyBle_connHandle, CYBLE_GATT_DB_PEER_INITIATED);
            BPMNotify = wrReqParam->handleValPair.value.val[0] & 0x01;
            CyBle_GattsWriteRsp(cyBle_connHandle);  
        }
    break;
    
    default:
    break;
    
}

then on my main function I this:

int main(){
while(1){
if(BPMNotify == 1){
updateBPM();
}
CyBle_ProcessEvents();
}
}

Basically, I followed this tutorial:

Thanks!!

Couple of things Invento

  1. Can I see an example value that the script is posting?
  2. The script doesn't tell me how often values are sent, nor the time interval
  3. Your phone needs to have Location switched on
  4. You have found a very old AI example which is error prone in the wrong hands

Hello ChrisWard

  1. Here's an example I get using LightBlue app from the play store:

  2. It is supposed to read the values everytime it gets a new value, as the notifications are enabled on the server but I need to set it up from the client too, on this specific app (LightBlue) I do this by touching the subscribe button so I have, somehow, to enable notifications from the Client application (AppInventor) before sending notifications

  3. Yes, it has the location on

  4. Sorry but I don't understand what you mean. If you refer to the PSoC's BLE tutorial, it works. I'm having problems only on the App Inventors side. Furthermore, the appinventor's app connects succesfully to my PSoC. The problem is I don't get any data.

Thanks!

AI = App Inventor :grin: So now I think you understand.

So, hacked together an example App, but I can't test it here as I do not have a device available to send 32bit integers. It is however based on a basic framework that many others have used successfully. Note that by registering for Integers, data is streamed to your App whenever it is available.

Enter your UUIDs in the variables provided at the top of the Blocks.

BLE_RECEIVE_UINT32.aia (194.2 KB)

I did it but it stays "waiting for data"

Hello ChrisWard, I tried the original code but instead of trying to receive integers, I changed the block to registerforbyte and that made the trick.

I attach the .aia extension in case it helps someone.

Is there a way to get rid of the () ?, so the numbers shows like

BPM: 74

Thanks

App_copy.aia (191.3 KB)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.