This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Receiving data from Mobile APP

Hi

Firstly i am coming from 8 bit world(PIC and Arduino) and not so good at c programming. ( just writing all code in main and sometimes using function) (not even use pointer much but knowing principle)

But now, i start to work with 32 bit microprocessor and my first training is nrf51822 beacon module. I am trying to figure out this module, i wrote some spi, timer, gpiote application with copying code parts etc. They are working fine for me. (project is pov display with 32 RGB)

But i really screw up Bluetooth part. My problem is, i can't figure out how to make a basic char transfer over mobile app to beacon. I just want to send 'a' and this will blink a led for me on beacon.

In this problem, things i do;

  • Firstly i am using ble_app_uart example and ble_app_blinky example.

  • I wrote a code part that sends char to mobile app from beacon. (the opposite of what i want) i use ble_nus_string_send function for it. I desperately search for ble_nus_string_recieve but.. Nothing

  • I try to use app_uart_get and app_uart_put functions.. to be honest i don't even understand what they did.

To simplfy, i can not receive and handle a character which come from mobile app over bluetooth to NRF51822 Beacon. I try to analysis ble_app_blinky example and can not find the function which is doing recieving procedure from mobile app. Which functions do that job really ?

To be honest i can't analysis examples well. Because they all written in with structs, pointers, callbacks etc. One function always call another or being inside another function as well. I really want to learn writing code like that but i don't know how to deal with this difficulty. So i am open for all guidance.

Thanks.

Parents
  • Hi again.

    I am here to confess my answer. (Cersei Talkin')

    To remember, my main goal is transmitting a char from mobile app to nrf51822 Beacon module.

    So last 3-4 days, i decide to sharpen my C programming skills, I worked on pointers, structs, callback functions etc.

    And i returned to the ble_app_uart examples and caught this.

        static void services_init(void) {
           uint32_t       err_code;
           ble_nus_init_t nus_init;
        
           memset(&nus_init, 0, sizeof(nus_init));
    
           nus_init.data_handler = nus_data_handler;
        
           err_code = ble_nus_init(&m_nus, &nus_init);
           APP_ERROR_CHECK(err_code); 
    }
    

    and this.

    static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length) {
    for (uint32_t i = 0; i < length; i++)
    {
    		getData(p_data, bleRecData, i);
        //while(app_uart_put(p_data[i]) != NRF_SUCCESS);
    }
    //while(app_uart_put('\n') != NRF_SUCCESS); }
    

    This functions handle receiving process.

    As you can see i changed something little bit.

    What i have learn is, app_uart_put function is transmitting data which is received from mobile app, TO THE UART (TERMINAL).

    So that means (not sure), when you send characters from mobile app, this default functions take the data and send it to the terminal. I think i need some debugger for that terminal to open but not sure.

    Anyway, i don't need a terminal for my job, so I move on and create a new char string which is

     uint8_t bleRecData[256];
    

    with this i have a global data area. I can read and write in it easily now.

    As you can see above, there is a function which is not in ble_app_uart example. i wrote this getData function.

    void getData(uint8_t* recData,uint8_t* saveData, uint8_t index){
    		saveData[index] = recData[index];
    }
    

    It is so simple, maybe sounds stupid meh :) no need for that but i did this. it takes data from nus_data_handler and putting it to the my bleRecData[]

    So guys, this is how you can get data to anywhere you want.

    Summary : nus_data_handler default version is just getting character from mobile app and send it to UART module. If you want to use data directly just delete app_uart_put section and try to get p_data[] to anywhere else.

    As I say, I am a new learner, so some part maybe sounds ridiculous. I am still open for guidance and advices.

    See ya.

Reply
  • Hi again.

    I am here to confess my answer. (Cersei Talkin')

    To remember, my main goal is transmitting a char from mobile app to nrf51822 Beacon module.

    So last 3-4 days, i decide to sharpen my C programming skills, I worked on pointers, structs, callback functions etc.

    And i returned to the ble_app_uart examples and caught this.

        static void services_init(void) {
           uint32_t       err_code;
           ble_nus_init_t nus_init;
        
           memset(&nus_init, 0, sizeof(nus_init));
    
           nus_init.data_handler = nus_data_handler;
        
           err_code = ble_nus_init(&m_nus, &nus_init);
           APP_ERROR_CHECK(err_code); 
    }
    

    and this.

    static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length) {
    for (uint32_t i = 0; i < length; i++)
    {
    		getData(p_data, bleRecData, i);
        //while(app_uart_put(p_data[i]) != NRF_SUCCESS);
    }
    //while(app_uart_put('\n') != NRF_SUCCESS); }
    

    This functions handle receiving process.

    As you can see i changed something little bit.

    What i have learn is, app_uart_put function is transmitting data which is received from mobile app, TO THE UART (TERMINAL).

    So that means (not sure), when you send characters from mobile app, this default functions take the data and send it to the terminal. I think i need some debugger for that terminal to open but not sure.

    Anyway, i don't need a terminal for my job, so I move on and create a new char string which is

     uint8_t bleRecData[256];
    

    with this i have a global data area. I can read and write in it easily now.

    As you can see above, there is a function which is not in ble_app_uart example. i wrote this getData function.

    void getData(uint8_t* recData,uint8_t* saveData, uint8_t index){
    		saveData[index] = recData[index];
    }
    

    It is so simple, maybe sounds stupid meh :) no need for that but i did this. it takes data from nus_data_handler and putting it to the my bleRecData[]

    So guys, this is how you can get data to anywhere you want.

    Summary : nus_data_handler default version is just getting character from mobile app and send it to UART module. If you want to use data directly just delete app_uart_put section and try to get p_data[] to anywhere else.

    As I say, I am a new learner, so some part maybe sounds ridiculous. I am still open for guidance and advices.

    See ya.

Children
Related