This post was last edited by dvacos on 2024-9-28 18:35
The above article has been able to connect and discover new services. This article implements data transmission and reception based on the above article. Continue to refer to and read BLE_p2pServer and BLE_HeartRate
1. Data reception
Burn and connect to BLE_p2pServer. After sending data, check the LOG and find that the following log will be printed when sending one byte of data. Follow this clue to find the custom service.
I found the Bluetooth time callback interface, but I don't know why this interface is named TEST_Notification, which is easy to confuse.
Add LOG from lines 109 to 115 to print data.
The following LOG successfully receives the one-byte data I sent
Combining the above two pictures, it is found that 2 bytes of data cannot be received.
After some attempts and research, I found that Bluetooth data reception actually requires a given length in advance? ?
So I set MTU to 247, but found that p_Notification->DataTransfered.Length is not the actual length of the received data (this is very strange and I don’t understand it), so this only needs to be given in combination with the actual application.
The above completes the data reception experiment! !
Second data reply
Refer to the BLE_HeartRate example and use Notify to report data to the phone.
Find the data sending interface
The parameters that need to be filled in are:
1 Opcode (operation code (personally think it is not necessarily correct))
2 Data of type TEST_Data_t, including the transmission data length and data pointer
3 handle, very important. If you fill in the wrong handle, you will not receive data.
So add the following code to test and verify the data sent
It turns out that the variables received and printed are not the ones I filled in, and when declaring the structure, I added the static modifier, but after testing, the data sent is still not the data I filled in.
After
After modification, Notify data was finally received!!
The above data transmission and reception experiments are completed, and the subsequent debugging will be carried out with Web BLE! !