Skip to content

Commit d34cac4

Browse files
committed
GSM: add ping
1 parent 8bdb160 commit d34cac4

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

libraries/GSM/src/GSM.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,36 @@ void arduino::GSMClass::end() {
140140
}
141141
}
142142

143+
int arduino::GSMClass::ping(const char* hostname, int ttl) {
144+
145+
mbed::GEMALTO_CINTERION_CellularStack* stack = (mbed::GEMALTO_CINTERION_CellularStack*)_context->get_stack();
146+
if (!stack) {
147+
return 0;
148+
}
149+
return stack->ping(hostname, ttl);
150+
}
151+
152+
int arduino::GSMClass::ping(const String &hostname, int ttl)
153+
{
154+
return ping(hostname.c_str(), ttl);
155+
}
156+
157+
int arduino::GSMClass::ping(IPAddress ip, int ttl)
158+
{
159+
String host;
160+
host.reserve(15);
161+
162+
host += ip[0];
163+
host += '.';
164+
host += ip[1];
165+
host += '.';
166+
host += ip[2];
167+
host += '.';
168+
host += ip[3];
169+
170+
return ping(host, ttl);
171+
}
172+
143173
int arduino::GSMClass::disconnect() {
144174
if (!_context) {
145175
return 0;

libraries/GSM/src/GSM.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ class GSMClass : public MbedSocketClass {
115115
void trace(Stream& stream);
116116
void setTraceLevel(int trace_level, bool timestamp = false, bool at_trace = false);
117117
#endif
118-
int ping(const char* hostname, uint8_t ttl = 128);
119-
int ping(const String& hostname, uint8_t ttl = 128);
120-
int ping(IPAddress host, uint8_t ttl = 128);
118+
int ping(const char* hostname, int ttl = 5000);
119+
int ping(const String& hostname, int ttl = 5000);
120+
int ping(IPAddress host, int ttl = 5000);
121121
bool isConnected();
122122

123123
friend class GSMClient;

0 commit comments

Comments
 (0)