Skip to content

Commit

Permalink
Update TinyGSM,Added Ping function #178
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Nov 16, 2024
1 parent 29b9561 commit 3abbf5c
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
48 changes: 48 additions & 0 deletions lib/TinyGSM/src/TinyGsmClientA7608.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,54 @@ class TinyGsmA7608 : public TinyGsmModem<TinyGsmA7608>,
}
return true;
}

/*
* Return code:
* -1 ping failed
* 1 Ping success
* 2 Ping time out
* 3 Ping result
* * */
int ping(const char *url, String &resolved_ip_addr,
uint32_t &rep_data_packet_size,
uint32_t &tripTime,
uint8_t &TTL)
{
uint8_t dest_addr_type = 1;
uint8_t num_pings = 1;
uint8_t data_packet_size = 64;
uint32_t interval_time = 1000;
uint32_t wait_time = 10000;
uint8_t ttl = 0xFF;
int result_type = -1;

sendAT("+CPING=\"", url, "\"", ",", dest_addr_type, ",",
num_pings, ",", data_packet_size, ",",
interval_time, ",", wait_time, ",", ttl);

if (waitResponse() != 1) {
return -1;
}
if (waitResponse(10000UL, "+CPING: ") == 1) {
result_type = streamGetIntBefore(',');
switch (result_type) {
case 1:
resolved_ip_addr = stream.readStringUntil(',');
rep_data_packet_size = streamGetIntBefore(',');
tripTime = streamGetIntBefore(',');
TTL = streamGetIntBefore('\n');
break;
case 2:
break;
case 3:
break;
default:
break;
}
}
return result_type;
}

/*
* GPRS functions
*/
Expand Down
48 changes: 48 additions & 0 deletions lib/TinyGSM/src/TinyGsmClientA7670.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,54 @@ class TinyGsmA7670 : public TinyGsmModem<TinyGsmA7670>,
return true;
}

/*
* Return code:
* -1 ping failed
* 1 Ping success
* 2 Ping time out
* 3 Ping result
* * */
int ping(const char *url, String &resolved_ip_addr,
uint32_t &rep_data_packet_size,
uint32_t &tripTime,
uint8_t &TTL)
{
uint8_t dest_addr_type = 1;
uint8_t num_pings = 1;
uint8_t data_packet_size = 64;
uint32_t interval_time = 1000;
uint32_t wait_time = 10000;
uint8_t ttl = 0xFF;
int result_type = -1;

sendAT("+CPING=\"", url, "\"", ",", dest_addr_type, ",",
num_pings, ",", data_packet_size, ",",
interval_time, ",", wait_time, ",", ttl);

if (waitResponse() != 1) {
return -1;
}
if (waitResponse(10000UL, "+CPING: ") == 1) {
result_type = streamGetIntBefore(',');
switch (result_type) {
case 1:
resolved_ip_addr = stream.readStringUntil(',');
rep_data_packet_size = streamGetIntBefore(',');
tripTime = streamGetIntBefore(',');
TTL = streamGetIntBefore('\n');
break;
case 2:
break;
case 3:
break;
default:
break;
}
}
return result_type;
}


/*
* GPRS functions
*/
Expand Down
48 changes: 48 additions & 0 deletions lib/TinyGSM/src/TinyGsmClientSIM7672.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,54 @@ class TinyGsmSim7672 : public TinyGsmModem<TinyGsmSim7672>,
}
return true;
}

/*
* Return code:
* -1 ping failed
* 1 Ping success
* 2 Ping time out
* 3 Ping result
* * */
int ping(const char *url, String &resolved_ip_addr,
uint32_t &rep_data_packet_size,
uint32_t &tripTime,
uint8_t &TTL)
{
uint8_t dest_addr_type = 1;
uint8_t num_pings = 1;
uint8_t data_packet_size = 64;
uint32_t interval_time = 1000;
uint32_t wait_time = 10000;
uint8_t ttl = 0xFF;
int result_type = -1;

sendAT("+CPING=\"", url, "\"", ",", dest_addr_type, ",",
num_pings, ",", data_packet_size, ",",
interval_time, ",", wait_time, ",", ttl);

if (waitResponse() != 1) {
return -1;
}
if (waitResponse(10000UL, "+CPING: ") == 1) {
result_type = streamGetIntBefore(',');
switch (result_type) {
case 1:
resolved_ip_addr = stream.readStringUntil(',');
rep_data_packet_size = streamGetIntBefore(',');
tripTime = streamGetIntBefore(',');
TTL = streamGetIntBefore('\n');
break;
case 2:
break;
case 3:
break;
default:
break;
}
}
return result_type;
}

/*
* GPRS functions
*/
Expand Down

0 comments on commit 3abbf5c

Please sign in to comment.