4949#define DEFAULT_RECV_BUFFER_SIZE (2 * MAX_PACKET_LEN)
5050
5151// Time to wait (millisec) for responses from sent packets: (2 seconds).
52- #define DEFAULT_SEND_TIMEOUT_MS (2 * 1000)
53-
54- // Number of milliseconds to wait for pending responses to sent packets.
55- // This is a fallback which should never be reached.
56- #define PENDING_RESPONSES_TIMEOUT_MS 100
57- #define PENDING_RESPONSES_BUSY_POLL_MS 10
52+ #define DEFAULT_SEND_TIMEOUT_MS (1000)
5853
5954// ESPNow packet format for the receive buffer.
6055// Use this for peeking at the header of the next packet in the buffer.
@@ -201,34 +196,10 @@ void common_hal_espnow_set_pmk(espnow_obj_t *self, const uint8_t *key) {
201196
202197// --- Send and Receive ESP-NOW data ---
203198
204- // Used by espnow_send() for sends() with sync==True.
205- // Wait till all pending sent packet responses have been received.
206- // ie. self->tx_responses == self->tx_packets.
207- static void _wait_for_pending_responses (espnow_obj_t * self ) {
208- mp_uint_t t , start = mp_hal_ticks_ms ();
209- while (self -> tx_responses < self -> tx_packets ) {
210- if ((t = mp_hal_ticks_ms () - start ) > PENDING_RESPONSES_TIMEOUT_MS ) {
211- mp_raise_OSError (MP_ETIMEDOUT );
212- }
213- if (t > PENDING_RESPONSES_BUSY_POLL_MS ) {
214- // After 10ms of busy waiting give other tasks a look in.
215- RUN_BACKGROUND_TASKS ;
216- }
217- }
218- }
219199
220- mp_obj_t common_hal_espnow_send (espnow_obj_t * self , const bool sync , const uint8_t * mac , const mp_buffer_info_t * message ) {
221- if (sync ) {
222- // Flush out any pending responses.
223- // If the last call was sync == False there may be outstanding responses
224- // still to be received (possible many if we just had a burst of unsync send()s).
225- // We need to wait for all pending responses if this call has sync = True.
226- _wait_for_pending_responses (self );
227- }
228-
229- // Send the packet - try, try again if internal esp-now buffers are full.
200+ mp_obj_t common_hal_espnow_send (espnow_obj_t * self , const uint8_t * mac , const mp_buffer_info_t * message ) {
201+ // Send the packet - keep trying until timeout if the internal esp-now buffers are full.
230202 esp_err_t err ;
231- size_t saved_failures = self -> tx_failures ;
232203 mp_uint_t start = mp_hal_ticks_ms ();
233204
234205 while ((ESP_ERR_ESPNOW_NO_MEM == (err = esp_now_send (mac , message -> buf , message -> len ))) &&
@@ -241,13 +212,7 @@ mp_obj_t common_hal_espnow_send(espnow_obj_t *self, const bool sync, const uint8
241212 // If mac == NULL msg will be sent to all peers EXCEPT any broadcast or multicast addresses.
242213 self -> tx_packets += ((mac == NULL ) ? ((mp_obj_list_t * )self -> peers -> list )-> len : 1 );
243214
244- if (sync ) {
245- // Wait for and tally all the expected responses from peers
246- _wait_for_pending_responses (self );
247- }
248-
249- // Return False if sync and any peers did not respond.
250- return mp_obj_new_bool (!(sync && self -> tx_failures != saved_failures ));
215+ return mp_const_none ;
251216}
252217
253218mp_obj_t common_hal_espnow_recv (espnow_obj_t * self ) {
0 commit comments