|Top Previous Next|
To send out data through the BLE interface, use the bt.setdata method to store data into the TX buffer, and bt.send to commit this data for sending. Prior to bt.send invocation, the newly stored data will be uncommitted. Calling bt.send commits the data, and only committed data is sent out. You can check the amount of committed data in the buffer through the bt.txlen read-only property. The amount of uncommitted data can be checked via bt.newtxlen. Bt.txfree returns free buffer space, but doesn't take into the account uncommitted data, so the real free space is bt.txfree – bt.newtxlen.
For example, here is how to send out a "Hello, World!" message on a press of the MD button (this code snipped assumes that you have an active BLE connection, i.e. bt.connected= 1- YES):
The code above would work, but only if at the moment of this code's execution the necessary amount of free space was already available in the TX buffer (otherwise the data would get truncated). So, obviously, you need to make sure that the TX buffer has the necessary amount of free space before sending. A simple polling solution would look like this:
As the WA2000 Wi-Fi/BLE add-on module sends out the data you placed into the TX buffer, it will be gradually removing this data from the buffer. Please note that TX buffer becoming empty does not indicate that all data has been received by the other end of the BLE link. This only means that BLE hardware of the WA2000 has already removed the data from the buffer and at least started sending it. Regrettably, there is no mechanism to let your app know when the data you send actually reaches the other end of the BLE link.
You can delete all data in the TX buffer using the bt.txclear method.