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

basic sample to send data from peripheral to smartphone with nrf connect sdk

Hi,

I need to test the data rate capacity between a nrf52840 and a smartphone. Smartphone being the central device and nrf52840 being the peripheral device. I have an eval nrf25840 dk  board.

My point is to write from peripheral to central device. If I am not wrong, in all the samples I have found in nrf connect sdk are showing exchanges from central to peripheral. I have tried to use the throughput sample, using only the "slave" part and modifying it to write, but clearly I miss some init steps or the right writting process. I can connect to the nrf52840 with nrfconnect from my phone, I have added a call on button 3 from my 52840dk board to write the image (tried using bt_throughput_write /  bt_gatt_write_without_response), but it chrashes on an assert (conn struct and handles are null...)

Any help or link to good practices woud be greatly apreciated...

Thanks

Renaud

Parents Reply Children
  • Thank you Einar for your response. I have finally managed to use the uart example.  I would like to modify it to be able to send bigger chunks of data. I took the img_file from throughput example and in a loop I push it into the fifo queue. it works, but I need to slow it down to be sure the queue is emptied before being oversized. So I have tried to not bother with the fifo and move the "bt_nus_send" call into my main thread and push data from there. Doing this does not work... the call ends in "Failed to send data over BLE connection" with this log:

    "bt_conn: Unable to allocate TX context"

    in the same time if I send "aaa" from putty it works fine, i do have it coming on my mobile phone on nrf connect...

    does the "bt_nus_send" has to be launched from a separate thread? Do I miss some init? 

    here is the code I have added / modified:

    int write_image()
    {
    	int err;
            sentSize = 0;
    #define BUFFSIZE 20
            static char buf[BUFFSIZE];
            int loadedSize = 0;
    	for (uint16_t pos = 0; pos != IMG_SIZE;) {
           
                    int buffered = 0;
                    if((IMG_SIZE - pos) > BUFFSIZE)
                    {
                      buffered = BUFFSIZE;
                      memcpy(buf, img[pos / IMG_X][pos % IMG_X], BUFFSIZE);
                    }
                    else
                    {
                      buffered = (IMG_SIZE - pos);
                      memcpy(buf, img[pos / IMG_X][pos % IMG_X], (IMG_SIZE - pos));
                    }
    		pos += buffered;
    
                  printk("writing data: %d\n", buffered);
     
                  if (bt_nus_send(NULL, buf, buffered)) {
    			LOG_WRN("Failed to send data over BLE connection");
    		}
                    k_sleep(K_MSEC(500));
    
                    sentSize += buffered;     
    	}
    	return 0;
    }
    
    
    void button_changed(uint32_t button_state, uint32_t has_changed)
    {
    	uint32_t buttons = button_state & has_changed;
    
    	if (auth_conn) {
    		if (buttons & KEY_PASSKEY_ACCEPT) {
    			num_comp_reply(true);
    		}
    
    		if (buttons & KEY_PASSKEY_REJECT) {
    			num_comp_reply(false);
    		}
    	}
    
            	if (buttons & DK_BTN3_MSK) {
    			write_image();
    		}
    
    }
    

    thanks for your help!

    renaud

  • My mistake, it seems I did not empty the tx characterisitic on phone side....

    Sorry for previous message....

Related