Skip to content

Commit

Permalink
pb with yield on esp8266
Browse files Browse the repository at this point in the history
  • Loading branch information
dvarrel committed Feb 28, 2023
1 parent 33a01c9 commit be9c2dc
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/arduino-lint-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ jobs:
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
#library-manager: update
library-manager: update
compliance: strict
25 changes: 16 additions & 9 deletions examples/test_ping/test_ping.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void setup()
delay(100);

WiFi.begin("ssid","password");

// attente connexion
Serial.print("\nConnection");
while (WiFi.status() != WL_CONNECTED)
Expand All @@ -32,23 +32,30 @@ void loop()
// Ping IP
const IPAddress remote_ip(9,9,9,9);
Serial.print(remote_ip);
if (Ping.ping(remote_ip)){
Serial.printf(" response time : %d/%.2f/%d", Ping.minTime(), Ping.averageTime(), Ping.maxTime());
Serial.println("ms");
if (Ping.ping(remote_ip) > 0){
Serial.printf(" response time : %d/%.2f/%d ms\n", Ping.minTime(), Ping.averageTime(), Ping.maxTime());
} else {
Serial.println(" Error !");
}
delay(5000);
delay(1000);

// Ping Host
const char* remote_host = "quad9.net";
Serial.print(remote_host);
if (Ping.ping(remote_host)){
Serial.printf(" response time : %d/%.2f/%d", Ping.minTime(), Ping.averageTime(), Ping.maxTime());
Serial.println("ms");
if (Ping.ping(remote_host) > 0){
Serial.printf(" response time : %d/%.2f/%d ms\n", Ping.minTime(), Ping.averageTime(), Ping.maxTime());
} else {
Serial.println(" Ping Error !");
}
delay(1000);

// Ping local IP
Serial.print(WiFi.gatewayIP());
if (Ping.ping(WiFi.gatewayIP()) > 0){
Serial.printf(" response time : %d/%.2f/%d ms\n", Ping.minTime(), Ping.averageTime(), Ping.maxTime());
} else {
Serial.println(" Ping Error !");
}
delay(5000);
delay(1000);

}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ESPping
version=1.0.1
version=1.0.2
author=dvarrel, Daniele Colanardi, Marian Craciunescu
maintainer=dvarrel
sentence=Let the ESP32/ESP8266 ping a remote machine.
Expand Down
48 changes: 35 additions & 13 deletions src/ESPping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,17 @@ bool PingClass::ping(IPAddress dest, unsigned int count) {

// Let's go!
if(ping_start(&_options)) {
#ifdef ESP8266
//wait until finished
while((_success + _errors) < _expected_count){
delay(1);
esp_yield();
};
#else
// Suspend till the process end
esp_yield();
#endif
}

return (_success > 0);
}

Expand Down Expand Up @@ -88,6 +95,7 @@ void PingClass::_ping_recv_cb(void *opt, void *resp) {
//ping_option* ping_opt = reinterpret_cast<struct ping_option*>(opt);

// Error or success?
#ifdef ESP8266
if (ping_resp->ping_err == -1)
_errors++;
else {
Expand All @@ -99,32 +107,46 @@ void PingClass::_ping_recv_cb(void *opt, void *resp) {
_max_time = ping_resp->resp_time;

}
#else
_errors = ping_resp->ping_err;
_success = _expected_count - _errors;
_avg_time = ping_resp->resp_time;
_min_time = 0;
#endif

// Some debug info
DEBUG_PING(
"DEBUG: ping reply\n"
"\ttotal_count = %d \n"
"\tresp_time = %d \n"
"\tseqno = %d \n"
"\ttimeout_count = %d \n"
"\tbytes = %d \n"
"\ttotal_bytes = %d \n"
"\ttotal_time = %d \n"
"DEBUG: ping reply"
"\ttotal_count = %d"
"\tresp_time = %d"
"\tseqno = %d"
"\ttimeout_count = %d"
"\tbytes = %d"
"\ttotal_bytes = %d"
"\ttotal_time = %d"
"\tping_err = %d \n",
ping_resp->total_count, ping_resp->resp_time, ping_resp->seqno,
ping_resp->timeout_count, ping_resp->bytes, ping_resp->total_bytes,
ping_resp->total_time, ping_resp->ping_err
(int)ping_resp->total_count, (int)ping_resp->resp_time, (int)ping_resp->seqno,
(int)ping_resp->timeout_count, (int)ping_resp->bytes, (int)ping_resp->total_bytes,
(int)ping_resp->total_time, (int)ping_resp->ping_err
);

// Is it time to end?
// Don't using seqno because it does not increase on error
if (_success + _errors == _expected_count) {
#ifdef ESP8266
if (_success + _errors == _expected_count ) {
_avg_time = _success > 0 ? _avg_time / _success : 0;
#else
if (ping_resp->total_count== _expected_count) {

#endif

DEBUG_PING("success %d errors %d\n", _success, _errors);
DEBUG_PING("Resp times min %d, avg %.2f, max %d ms\n", _min_time, _avg_time, _max_time);

#ifdef ESP32
// Done, return to main functiom
esp_schedule();
#endif
}
}

Expand Down
1 change: 1 addition & 0 deletions src/ESPping.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern "C" {
}
#endif

//#define ENABLE_DEBUG_PING 0
#ifdef ENABLE_DEBUG_PING
#define DEBUG_PING(...) Serial.printf(__VA_ARGS__)
#else
Expand Down

0 comments on commit be9c2dc

Please sign in to comment.