From 950b7079ea2df5d3fca5ac627422e29aa10c6a6f Mon Sep 17 00:00:00 2001 From: lewisxhe Date: Wed, 11 Dec 2024 16:16:15 +0800 Subject: [PATCH] Added ping function --- src/TinyGsmClientA76xx.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/TinyGsmClientA76xx.h b/src/TinyGsmClientA76xx.h index 58539e90..755a8e35 100644 --- a/src/TinyGsmClientA76xx.h +++ b/src/TinyGsmClientA76xx.h @@ -264,6 +264,45 @@ class TinyGsmA76xx : public TinyGsmModem>, } + /* + * 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; + + thisModem().sendAT("+CPING=\"", url, "\"", ",", dest_addr_type, ",", num_pings, ",", + data_packet_size, ",", interval_time, ",", wait_time, ",", ttl); + + if (thisModem().waitResponse() != 1) { return -1; } + if (thisModem().waitResponse(10000UL, "+CPING: ") == 1) { + result_type = thisModem().streamGetIntBefore(','); + switch (result_type) { + case 1: + resolved_ip_addr = stream.readStringUntil(','); + rep_data_packet_size = thisModem().streamGetIntBefore(','); + tripTime = thisModem().streamGetIntBefore(','); + TTL = thisModem().streamGetIntBefore('\n'); + break; + case 2: break; + case 3: break; + default: break; + } + } + return result_type; + } + + /* * GPRS functions */