Skip to content

WiFiS3 add Ping #47

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
url = https://github.com/arduino/arduino-esp32.git
branch = unor4wifi-2.0.9
shallow = true
[submodule "libraries/ESPping"]
path = libraries/ESPping
url = https://github.com/dvarrel/ESPping.git
92 changes: 91 additions & 1 deletion UNOR4USBBridge/cmds_esp_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#define CMDS_ESP_GENERIC_H

#include "at_handler.h"
#include "ESPping.h"
char rsl[5]; // ping time

extern "C" {
#include "esp32-hal-tinyusb.h"
}
Expand Down Expand Up @@ -332,6 +335,93 @@ void CAtHandler::add_cmds_esp_generic() {
return chAT::CommandStatus::ERROR;
}
};

/* ....................................................................... */
command_table[_PINGIP] = [this](auto & srv, auto & parser) {
/* ....................................................................... */
switch (parser.cmd_mode) {
case chAT::CommandMode::Write: {

if (parser.args.size() != 3) {
return chAT::CommandStatus::ERROR;
}

// get IP
auto &hostip = parser.args[1];
if (hostip.empty()) {
return chAT::CommandStatus::ERROR;
}

IPAddress address;
if(!address.fromString(hostip.c_str())) {
return chAT::CommandStatus::ERROR;
}

// get count
auto &cnt = parser.args[2];
if (cnt.empty()) {
return chAT::CommandStatus::ERROR;
}
unsigned int count = atoi(cnt.c_str());

auto res = Ping.ping(address, count);
if (res) { // ping was succesfull
srv.write_response_prompt();
sprintf(rsl,"%.2f", Ping.averageTime());
srv.write_cstr((const char *) rsl);
srv.write_line_end();
return chAT::CommandStatus::OK;
}
srv.write_response_prompt();
srv.write_error();
srv.write_line_end();
return chAT::CommandStatus::ERROR;
}
default:
return chAT::CommandStatus::ERROR;
}
};

/* ....................................................................... */
command_table[_PINGNAME] = [this](auto & srv, auto & parser) {
/* ....................................................................... */
switch (parser.cmd_mode) {
case chAT::CommandMode::Write: {

if (parser.args.size() != 3) {
return chAT::CommandStatus::ERROR;
}

// get host name
auto &host = parser.args[1];
if (host.empty()) {
return chAT::CommandStatus::ERROR;
}

// get count
auto &cnt = parser.args[2];
if (cnt.empty()) {
return chAT::CommandStatus::ERROR;
}
unsigned int count = atoi(cnt.c_str());

auto res = Ping.ping((const char* ) host.c_str(), count);
if (res) { // ping was succesfull
srv.write_response_prompt();
sprintf(rsl,"%.2f", Ping.averageTime());
srv.write_cstr((const char *) rsl);
srv.write_line_end();
return chAT::CommandStatus::OK;
}
srv.write_response_prompt();
srv.write_error();
srv.write_line_end();
return chAT::CommandStatus::ERROR;
}
default:
return chAT::CommandStatus::ERROR;
}
};
}

#endif
#endif
2 changes: 2 additions & 0 deletions UNOR4USBBridge/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ enum file_op {
#define _ENDL "\r\n"
#define _WIFISCAN "+WIFISCAN"

#define _PINGNAME "+PINGNAME"

#define _RESET "+RESET"
#define _RESTART_BOOTLOADER "+RESTARTBOOTLOADER"
#define _GMR "+GMR"
Expand Down
1 change: 1 addition & 0 deletions libraries/ESPping
Submodule ESPping added at f62dc5