Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork218
Ping command#1014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Ping command#1014
Changes fromall commits
Commits
Show all changes
4 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionscores/arduino/mbed/connectivity/drivers/emac/COMPONENT_WHD/interface/WhdSTAInterface.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion...s/arduino/mbed/connectivity/drivers/wifi/COMPONENT_WHD/wifi-host-driver/inc/whd_version.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletionscores/arduino/mbed/connectivity/netsocket/include/netsocket/ICMPSocket.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletionslibraries/GSM/src/GSM.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletionslibraries/SocketWrapper/src/SocketHelpers.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletionslibraries/SocketWrapper/src/SocketHelpers.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletionslibraries/WiFi/examples/WiFiPing/WiFiPing.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /* | ||
| Web ICMP Ping | ||
| This sketch pings a device based on the IP address or the hostname | ||
| using the WiFi module. | ||
| This example is written for a network using WPA encryption. For | ||
| WEP or WPA, change the WiFi.begin() call accordingly. | ||
| created 14 February 2024 | ||
| by paulvha | ||
| modified 8 Jenuary 2025 | ||
| by fabik111 | ||
| */ | ||
| #include <WiFi.h> | ||
| #include "arduino_secrets.h" | ||
| ///////please enter your sensitive data in the Secret tab/arduino_secrets.h | ||
| char ssid[] = SECRET_SSID; // your network SSID (name) | ||
| char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) | ||
| int status = WL_IDLE_STATUS; | ||
| /* -------------------------------------------------------------------------- */ | ||
| void setup() { | ||
| /* -------------------------------------------------------------------------- */ | ||
| //Initialize serial and wait for port to open: | ||
| Serial.begin(9600); | ||
| while (!Serial) { | ||
| ; // wait for serial port to connect. Needed for native USB port only | ||
| } | ||
| // check for the WiFi module: | ||
| if (WiFi.status() == WL_NO_MODULE) { | ||
| Serial.println("Communication with WiFi module failed."); | ||
| // don't continue | ||
| while (true); | ||
| } | ||
| // attempt to connect to WiFi network: | ||
| while (status != WL_CONNECTED) { | ||
| Serial.print("Attempting to connect to SSID: "); | ||
| Serial.println(ssid); | ||
| // Connect to WPA/WPA2 network. Change this line if using open or WEP network: | ||
| status = WiFi.begin(ssid, pass); | ||
| // wait 3 seconds for connection: | ||
| delay(3000); | ||
| } | ||
| printWifiStatus(); | ||
| } | ||
| /* -------------------------------------------------------------------------- */ | ||
| void loop() { | ||
| /* -------------------------------------------------------------------------- */ | ||
| // Ping IP | ||
| const IPAddress remote_ip(140,82,121,4); | ||
| Serial.print("Trying to ping github.com on IP: "); | ||
| Serial.println(remote_ip); | ||
| // using default ping count of 1 | ||
| int res = WiFi.ping(remote_ip); | ||
| if (res > 0) { | ||
| Serial.print("Ping response time: "); | ||
| Serial.print(res); | ||
| Serial.println(" ms"); | ||
| } | ||
| else { | ||
| Serial.println("Timeout on IP!"); | ||
| } | ||
| // Ping Host | ||
| const char* remote_host = "www.google.com"; | ||
| Serial.print("Trying to ping host: "); | ||
| Serial.println(remote_host); | ||
| int res1 = WiFi.ping(remote_host); | ||
| if (res1 > 0) { | ||
| Serial.print("Ping response time: "); | ||
| Serial.print(res1); | ||
| Serial.println(" ms"); | ||
| } | ||
| else { | ||
| Serial.println("Timeout on host!"); | ||
| } | ||
| Serial.println(); | ||
| delay(5000); | ||
| } | ||
| /* -------------------------------------------------------------------------- */ | ||
| void printWifiStatus() { | ||
| /* -------------------------------------------------------------------------- */ | ||
| // print the SSID of the network you're attached to: | ||
| Serial.print("SSID: "); | ||
| Serial.println(WiFi.SSID()); | ||
| // print your board's IP address: | ||
| IPAddress ip = WiFi.localIP(); | ||
| Serial.print("IP Address: "); | ||
| Serial.println(ip); | ||
| // print the received signal strength: | ||
| long rssi = WiFi.RSSI(); | ||
| Serial.print("signal strength (RSSI):"); | ||
| Serial.print(rssi); | ||
| Serial.println(" dBm"); | ||
| } |
2 changes: 2 additions & 0 deletionslibraries/WiFi/examples/WiFiPing/arduino_secrets.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #define SECRET_SSID "" | ||
| #define SECRET_PASS "" |
106 changes: 106 additions & 0 deletionspatches/0247-ICMPSocket-add-ping.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| From 933694e0f35451d21eed77a93fa346570de20878 Mon Sep 17 00:00:00 2001 | ||
| From: pennam <m.pennasilico@arduino.cc> | ||
| Date: Tue, 4 Feb 2025 14:31:59 +0100 | ||
| Subject: [PATCH] ICMPSocket: add ping | ||
| --- | ||
| .../netsocket/include/netsocket/ICMPSocket.h | 4 ++ | ||
| connectivity/netsocket/source/ICMPSocket.cpp | 61 +++++++++++++++++++ | ||
| 2 files changed, 65 insertions(+) | ||
| diff --git a/connectivity/netsocket/include/netsocket/ICMPSocket.h b/connectivity/netsocket/include/netsocket/ICMPSocket.h | ||
| index 1837bc8e09..5e1ee8fb03 100644 | ||
| --- a/connectivity/netsocket/include/netsocket/ICMPSocket.h | ||
| +++ b/connectivity/netsocket/include/netsocket/ICMPSocket.h | ||
| @@ -37,6 +37,10 @@ public: | ||
| */ | ||
| ICMPSocket(); | ||
| +#if MBED_CONF_LWIP_RAW_SOCKET_ENABLED | ||
| + int ping(SocketAddress &socketAddress, uint32_t timeout); | ||
| +#endif | ||
| + | ||
| #if !defined(DOXYGEN_ONLY) | ||
| protected: | ||
| diff --git a/connectivity/netsocket/source/ICMPSocket.cpp b/connectivity/netsocket/source/ICMPSocket.cpp | ||
| index f6c9b98de1..d8ea954835 100644 | ||
| --- a/connectivity/netsocket/source/ICMPSocket.cpp | ||
| +++ b/connectivity/netsocket/source/ICMPSocket.cpp | ||
| @@ -16,12 +16,73 @@ | ||
| */ | ||
| #include "ICMPSocket.h" | ||
| +#if MBED_CONF_LWIP_RAW_SOCKET_ENABLED | ||
| +#include "drivers/Timer.h" | ||
| +#include "lwip/prot/icmp.h" | ||
| +#include "lwip/inet_chksum.h" | ||
| +#include "lwip/prot/ip4.h" | ||
| +#endif | ||
| ICMPSocket::ICMPSocket() | ||
| { | ||
| _socket_stats.stats_update_proto(this, NSAPI_ICMP); | ||
| } | ||
| +#if MBED_CONF_LWIP_RAW_SOCKET_ENABLED | ||
| +int ICMPSocket::ping(SocketAddress &socketAddress, uint32_t timeout) | ||
| +{ | ||
| + struct __attribute__((__packed__)) { | ||
| + struct icmp_echo_hdr header; | ||
| + uint8_t data[32]; | ||
| + } request; | ||
| + | ||
| + ICMPH_TYPE_SET(&request.header, ICMP_ECHO); | ||
| + ICMPH_CODE_SET(&request.header, 0); | ||
| + request.header.chksum = 0; | ||
| + request.header.id = 0xAFAF; | ||
| + request.header.seqno = random(); | ||
| + | ||
| + for (size_t i = 0; i < sizeof(request.data); i++) { | ||
| + request.data[i] = i; | ||
| + } | ||
| + | ||
| + request.header.chksum = inet_chksum(&request, sizeof(request)); | ||
| + | ||
| + int res = sendto(socketAddress, &request, sizeof(request)); | ||
| + if (res <= 0){ | ||
| + return -1; | ||
| + } | ||
| + | ||
| + mbed::Timer timer; | ||
| + timer.start(); | ||
| + int elapsed = -1; | ||
| + do { | ||
| + struct __attribute__((__packed__)) { | ||
| + struct ip_hdr ipHeader; | ||
| + struct icmp_echo_hdr header; | ||
| + } response; | ||
| + | ||
| + int rxSize = recvfrom(&socketAddress, &response, sizeof(response)); | ||
| + if (rxSize < 0) { | ||
| + // time out | ||
| + break; | ||
| + } | ||
| + | ||
| + if (rxSize < sizeof(response)) { | ||
| + // too short | ||
| + continue; | ||
| + } | ||
| + | ||
| + if ((response.header.id == request.header.id) && (response.header.seqno == request.header.seqno)) { | ||
| + elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(timer.elapsed_time()).count(); | ||
| + timer.stop(); | ||
| + } | ||
| + } while (elapsed == -1 && std::chrono::duration_cast<std::chrono::milliseconds>(timer.elapsed_time()).count() < timeout); | ||
| + | ||
| + return elapsed; | ||
| +} | ||
| +#endif | ||
| + | ||
| nsapi_protocol_t ICMPSocket::get_proto() | ||
| { | ||
| return NSAPI_ICMP; | ||
| -- | ||
| 2.47.2 | ||
2 changes: 1 addition & 1 deletionvariants/ARDUINO_NANO33BLE/defines.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Binary file modifiedvariants/ARDUINO_NANO33BLE/libs/libmbed.a
Binary file not shown.
3 changes: 2 additions & 1 deletionvariants/EDGE_CONTROL/conf/mbed_app.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionvariants/EDGE_CONTROL/defines.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Binary file modifiedvariants/EDGE_CONTROL/libs/libmbed.a
Binary file not shown.
2 changes: 1 addition & 1 deletionvariants/EDGE_CONTROL/mbed_config.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionvariants/GENERIC_STM32H747_M4/defines.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Binary file modifiedvariants/GENERIC_STM32H747_M4/libs/libmbed.a
Binary file not shown.
1 change: 1 addition & 0 deletionsvariants/GIGA/conf/mbed_app.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.