HI I am having trouble converting the NUS example into something that simply stores the BLE nus response to the peripheral into a variable rather than printing it to the UART. Can you please show me an example of how this can be done?
Here is my current code in main.c, it does get triggered when i write from the NRF COnnect app on my Android but as far as I can tell there is no data passed to the buffer.
static void nus_data_handler(ble_nus_evt_t * p_evt)
{
uint16_t length;
static char data_array[6];
static char temp_data_array[40];
static int array;
static uint8_t index = 0;
static char ap_ssid[40];
static char ap_pwd[40];
if (p_evt->type == BLE_NUS_EVT_RX_DATA)
{
for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
{
temp_data_array[i] = p_evt->params.rx_data.p_data[i];
}
substring(data_array, temp_data_array, 0, 6);
uint32_t err_code;
NRF_LOG_INFO("Received data from BLE NUS. Writing data on UART.");
NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
if (temp_data_array == "AP_SSI")
{
array = 1;
}
else if (temp_data_array == "AP_PWD")
{
array = 2;
}
switch(array)
{
case 1:
index = 7; //precursor is actually AP_SSID, 7 characters we need to omit
while(p_evt->params.rx_data.p_data[index] != 0x3F)
{
app_uart_put(p_evt->params.rx_data.p_data[index]);
index++;
}
length = index;
memcpy(ssid, p_evt->params.rx_data.p_data, length);
app_uart_put(0x0A);
break;
case 2:
index = 6;
while(p_evt->params.rx_data.p_data[index] != 0x3F)
{
app_uart_put(p_evt->params.rx_data.p_data[index]);
index++;
}
length = index;
memcpy(password, p_evt->params.rx_data.p_data, length);
app_uart_put(0x0A);
break;
default:
break;
}
}
}