Skip to content

Commit a004c16

Browse files
committed
espressif ping: reduce wait time on failure^
1 parent 17c4e9c commit a004c16

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

ports/espressif/common-hal/wifi/Radio.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -554,21 +554,18 @@ mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address,
554554
// ESP-IDF creates a task to do the ping session. It shuts down when done, but only after a one second delay.
555555
// Calling common_hal_wifi_radio_ping() too fast will cause resource exhaustion.
556556
esp_ping_handle_t ping;
557-
esp_err_t ret;
558-
for (size_t tries = 1; tries <= 5; tries++) {
559-
ret = esp_ping_new_session(&ping_config, &ping_callbacks, &ping);
560-
if (ret == ESP_OK) {
561-
break;
562-
}
557+
if (esp_ping_new_session(&ping_config, &ping_callbacks, &ping) != ESP_OK) {
563558
// Wait for old task to go away and then try again.
564559
// Empirical testing shows we have to wait at least two seconds, despite the task
565560
// having a one-second timeout.
566561
common_hal_time_delay_ms(2000);
562+
// Return if interrupted now, to show the interruption as KeyboardInterrupt instead of the
563+
// IDF error.
567564
if (mp_hal_is_interrupted()) {
568-
return -1;
565+
return (uint32_t)(-1);
569566
}
567+
CHECK_ESP_RESULT(esp_ping_new_session(&ping_config, &ping_callbacks, &ping));
570568
}
571-
CHECK_ESP_RESULT(ret);
572569

573570
esp_ping_start(ping);
574571

shared-bindings/wifi/Radio.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,12 @@ MP_PROPERTY_GETTER(wifi_radio_ap_info_obj,
698698
//| self, ip: ipaddress.IPv4Address, *, timeout: Optional[float] = 0.5
699699
//| ) -> Optional[float]:
700700
//| """Ping an IP to test connectivity. Returns echo time in seconds.
701-
//| Returns None when it times out."""
701+
//| Returns None when it times out.
702+
//|
703+
//| **Limitations:** On Espressif, calling `ping()` multiple times rapidly
704+
//| exhausts available resources after several calls. Rather than failing at that point, `ping()`
705+
//| will wait two seconds for enough resources to be freed up before proceeding.
706+
//| """
702707
//| ...
703708
//|
704709
static mp_obj_t wifi_radio_ping(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {

0 commit comments

Comments
 (0)