In 'peripheral_uart', where does the BLE Tx data go?

I am confused about where the data sen to the output of the 'peripheral_uart' (Tx) goes when one uses the Serial Terminal to type in text.  Eventually, I want to be able to send advertising data that my device receives to my iPhone and I thought that what was being sent could be seen in the Logger on my iPhone (in nRF Toolbox, UART Rx/Tx).  When I type something into the serial terminal I see that it makes it to my iPhone (it is in green text) followed by a "received" message.  But this, now I think, is just what is coming in (what the Rx would see).  Where is the Bluetooth Tx output?  In the end I want to send my advertising matches to the iPhone but for now I would be very pleased if I could do something simple like just repeating all data the Bluetooth receives three times for each character on the Tx that comes in the Rx (proving I have control of what is sent out based on what is coming in yet modified).  This software test seems like it ought to ne simple enough to write.  I was hoping the Logger tool on the iPhone would only show the output but that doesn't seem to be the case (it appears to show the input).

I apologize for my ignorance ahead of time but I seem to be misunderstanding something that should be simple.

  • I see. Yes, the serial port emulation demonstrated by this sample might not exactly match your use case. However, I still believe the sample could be a good starting point for your requirements as it should be relatively easy to modify. You can modify the application so that it doesn't just blindly relay data received on the UART interface (or remove the UART com. altogether).

  • Yes, it was a great place to start.  I'm almost done.  I have just a few things left.  The current problem is that I want to send data out on the UART when advertising matches my filter.  Currently it only sends out UART data when it receives data as a trigger.

  • As mentioned in the other ticket, you can use the bt_nus_send()  function to send your data.

  • I am now triggering of the reception of the matched scan.  That is working well.  I send my data out but it does not go where I want it to go.  It goes to the Terminal on my computer.  I do not want it there!  I want it to go to the Norid_UART_Service on my iPhone.  I don't understand how it could be possibly going the terminal.

  • I just realized that the code I have been modifying (lesson 4 exercise 3) is supposed to be sending it to the terminal (based on the comment on the code).  I am interrupting that data and chaining it to my text.  Now I need to figure out how to interrupt the reception of data from the terminal and allow my data to be sent out instead.

    static void bt_receive_cb(struct bt_conn *conn, const uint8_t *const data, uint16_t len)
    {
    	int err;
    	char addr[BT_ADDR_LE_STR_LEN] = { 0 };
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, ARRAY_SIZE(addr));
    
    	LOG_INF("Received data from: %s", addr);
    
    	for (uint16_t pos = 0; pos != len;) {
    		struct uart_data_t *tx = k_malloc(sizeof(*tx));
    
    		if (!tx) {
    			LOG_WRN("Not able to allocate UART send data buffer");
    			return;
    		}
    
    		/* Keep the last byte of TX buffer for potential LF char. */
    		size_t tx_data_size = sizeof(tx->data) - 1;
    
    		if ((len - pos) > tx_data_size) {
    			tx->len = tx_data_size;
    		} else {
    			tx->len = (len - pos);
    		}
    
    		memcpy(tx->data, &data[pos], tx->len);
    
    		pos += tx->len;
    
    		/* Append the LF character when the CR character triggered
    		 * transmission from the peer.
    		 */
    		if ((pos == len) && (data[len - 1] == '\r')) {
    			tx->data[tx->len] = '\n';
    			tx->len++;
    		}
    		/* STEP 8.3 - Forward the data received over Bluetooth LE to the UART peripheral */
    		err = uart_tx(uart, tx->data, tx->len, SYS_FOREVER_MS);
    		if (err) {
    			k_fifo_put(&fifo_uart_tx_data, tx);
    		}
    	}
    }

Related