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
  • If you set all BLE stack (Soft Device) basics (like setting parameters, enabling it, provisioning GAP and GATT layer parameters and starting advertising or scanning - depending on what GAP role you've chosen) then you will be getting asynchronous events to handler function which you've provided to SD in softdevice_ble_evt_handler_set function call. then depending on phase of the BLE connection and roles/objects you've defined you will be acting upon receiving of certain events like BLE_GAP_EVT_CONNECTED (connection just established, still some basic establishment of higher layers is needed), BLE_GATTS_EVT_WRITE (this is basically what you are looking for if you implement GATT Server on nRF5x = Client writes to some GATT object like Characteristic's Value handle or Descriptor, you should check where it wrote and then interpret written data accordingly), BLE_GAP_EVT_DISCONNECTED (connection was terminated) etc.

    This of course gets little bit more complicated if you use other BLE layers like Security manage (pairing/bonding, connection link encryption) etc. But if you choose your GAP architecture (which device is Central/Master and which Peripheral/Slave) and GATT architecture (which side will be Server and which Client) then the rest can be found after little bit of archeology in SDK examples and Infocenter sequence charts (you need to find the right API matching your SD version, e.g. here are MSCs for latest production version for nRF52832 aka S132 V4.0.x.

  • Note that actual events linked to data transfer over Nordic BLE UART (NUS) protocol in examples\ble_peripheral\ble_app_uart SDK example are little bit hidden from you because they are not handled in main.c but in ble_nus_on_ble_evt() function which is implemented in components\ble\ble_services\ble_nus\ble_nus.c file. The idea of Nordic BLE UART project is that in your "main" program it behaves like classic serial UART line where you call PUT(char) and GET(char) meta-functions and all the magic to translate it to BLE logic happens underneath and you don't need to care. But of course you can see it and debug it as it comes in source code if you want.

Reply
  • Note that actual events linked to data transfer over Nordic BLE UART (NUS) protocol in examples\ble_peripheral\ble_app_uart SDK example are little bit hidden from you because they are not handled in main.c but in ble_nus_on_ble_evt() function which is implemented in components\ble\ble_services\ble_nus\ble_nus.c file. The idea of Nordic BLE UART project is that in your "main" program it behaves like classic serial UART line where you call PUT(char) and GET(char) meta-functions and all the magic to translate it to BLE logic happens underneath and you don't need to care. But of course you can see it and debug it as it comes in source code if you want.

Children
No Data
Related