chegewara wrote:param is type of union esp_spp_cb_param_t:
https://github.com/espressif/esp-idf/bl ... api.h#L168
For this particular event it will be this structure:
https://github.com/espressif/esp-idf/bl ... #L150-L158
I think this ( my_param.write.handle = ???; // 129 ?) should be somewhere in here:
Code: Select all
case ESP_SPP_SRV_OPEN_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_SRV_OPEN_EVT"); // client connected
FlowMeterData.SPP_conn = true;
<--- HERE
break;
case ESP_SPP_DATA_IND_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_DATA_IND_EVT len=%d handle=%d", param->data_ind.len, param->data_ind.handle);
if (param->data_ind.len < 1023)
{
<--- OR HERE
Sorry, I updated my previous post to late.
Here is code:
Code: Select all
//my structure
typedef struct MyData_s
{
uint8_t SPP_buffer[BUF_SIZE];
uint8_t UART_buffer[BUF_SIZE];
uint32_t SPP_len;
uint32_t UART_len;
uint8_t SPP_got_packet;
uint8_t UART_got_packet;
bool SPP_conn; // TRUE: spp connected
}MyData_t;
MyData_t MyData;
// SPP callback
static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
{
...
case ESP_SPP_CLOSE_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_CLOSE_EVT"); // when client disconnects
MyData.SPP_conn = false;
break;
case ESP_SPP_SRV_OPEN_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_SRV_OPEN_EVT"); // client connected
FlowMeterData.SPP_conn = true;
break;
case ESP_SPP_DATA_IND_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_DATA_IND_EVT len=%d handle=%d", param->data_ind.len, param->data_ind.handle);
if (param->data_ind.len < 1023)
{
// this part tranferring data fom SPP to UART (at this stage only fills the proper buffer, later it will be handled)
memcpy(MyData.SPP_Buf,param->data_ind.data, (size_t)param->data_ind.len);
MyData.SPP_len = param->data_ind.len;
MyData.SPP_got_packet = true;
// And this part works ONLY if I send something via SPP (I need independence sending)
if(MyData.UART_got_packet == true)
{
esp_spp_write(param->write.handle, MyData.UART_len, MyData.UART_buffer);
MyData.UART_got_packet = false;
}
}
...
}
// My function that should write data from UART to SPP outside spp callbacks
void SPP_to_UART_write(esp_spp_cb_param_t param)
{
esp_spp_write(param.write.handle, MyData.UART_len, MyData.UART_buffer);
}
//Main
void app_main()
{
...
// maybe like this?
esp_spp_cb_param_t my_param;
my_param.write.handle = ???; // 129 ?
SPP_to_UART_write(my_param)
...
}
(and at pastebin):
https://pastebin.com/sAhKXtM1
In your solution data from UART will be tranferred only when I'm connecting/disconnecting from smartphone, am I right?
I would like to connect (and stay connected), if something will arrive in esp UART, it should send to phone via SPP. And if I'm sending something from phone, it should transmitting over UART (this part is done!).
Problem is that I cant see UART data in realtime:
"uart_packet_1" arrived
"uart_packet_2" after 1 second
Packet #1 stored in buffer and if there wasnt any incoming SPP events I cant read it.
I will read uart_packet #2 or #3 or whatever later, when I will send something over SPP.
So I want all packet will transfering automatically over SPP.