說明
ping 網絡上的遠程設備。
用法
grps.ping(ip);
grps.begin(ip, ttl);
grps.begin(host);
grps.begin(host, ttl);
參數
ip:要 ping 的 IP 地址(4 個字節的數組)
主機:要 ping 的主機(字符串)
ttl:生存時間(可選,默認為 128)。請求可以轉發到的最大路由器數。
返回
GPRS_PING_DEST_UNREACHABLE 當目標(IP 或主機不可達)時 GPRS_PING_TIMEOUT 當 ping 超時時 GPRS_PING_UNKNOWN_HOST 當主機無法解析時 GPRS_PING_ERROR 當發生錯誤時
示例
/*
This uses an MKR GSM 1400 to continuously ping a host specified by IP Address or name.
Circuit:
* MKR GSM 1400 board
* Antenna
* SIM card with a data plan
created 06 Dec 2017
by Arturo Guadalupi
*/
#include <MKRGSM.h>
#include "arduino_secrets.h"
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// PIN Number
const char PINNUMBER[] = SECRET_PINNUMBER;
// APN data
const char GPRS_APN[] = SECRET_GPRS_APN;
const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN;
const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD;
// initialize the library instance
GSMSSLClient client;
GPRS gprs;
GSM gsmAccess;
// Specify IP address or hostname
String hostName = "www.google.com";
int pingResult;
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
}
Serial.println("Starting Arduino GPRS ping.");
// connection state
bool connected = false;
// After starting the modem with GSM.begin()
// attach the shield to the GPRS network with the APN, login and password
while (!connected) {
if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &&
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
connected = true;
} else {
Serial.println("Not connected");
delay(1000);
}
}
}
void loop() {
Serial.print("Pinging ");
Serial.print(hostName);
Serial.print(": ");
pingResult = gprs.ping(hostName);
if (pingResult >= 0) {
Serial.print("SUCCESS! RTT = ");
Serial.print(pingResult);
Serial.println(" ms");
} else {
Serial.print("FAILED! Error code: ");
Serial.println(pingResult);
}
delay(5000);
}
相關用法
- Arduino MKRGSM - gprs.attachGPRS()用法及代碼示例
- Arduino MKRGSM - gsm.shutdown()用法及代碼示例
- Arduino MKRGSM - gsm.begin()用法及代碼示例
- Arduino MKRGSM - sms.read()用法及代碼示例
- Arduino MKRGSM - sms.print()用法及代碼示例
- Arduino MKRGSM - client.connected()用法及代碼示例
- Arduino MKRGSM - voice.answerCall()用法及代碼示例
- Arduino MKRGSM - voice.hangCall()用法及代碼示例
- Arduino MKRGSM - sms.write()用法及代碼示例
- Arduino MKRGSM - modem.getIMEI()用法及代碼示例
- Arduino MKRGSM - sms.available()用法及代碼示例
- Arduino MKRGSM - client.available()用法及代碼示例
- Arduino MKRGSM - client.stop()用法及代碼示例
- Arduino MKRGSM - voice.voiceCall()用法及代碼示例
- Arduino MKRGSM - GSM構造函數用法及代碼示例
- Arduino MKRGSM - sms.endSMS()用法及代碼示例
- Arduino MKRGSM - sms.peek()用法及代碼示例
- Arduino MKRGSM - sms.beginSMS()用法及代碼示例
- Arduino MKRGSM - voice.retrieveCallingNumber()用法及代碼示例
- Arduino MKRGSM - client.connect()用法及代碼示例
- Arduino MKRGSM - client.read()用法及代碼示例
- Arduino MKRGSM - sms.flush()用法及代碼示例
- Arduino MKRGSM - sms.remoteNumber()用法及代碼示例
- Arduino MKRGSM - voice.getVoiceCallStatus()用法及代碼示例
- Arduino MKRNB - getCurrentCarrier()用法及代碼示例
注:本文由純淨天空篩選整理自arduino.cc大神的英文原創作品 MKRGSM - grps.ping()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。