说明
读取从客户端连接到的服务器接收到的下一个字节(在最后一次调用 read() 之后)。
read() 继承自 Stream 实用程序类。
用法
client.read()
参数
空
返回
int - 下一个字节(或字符),如果没有可用,则为 -1。
示例
// libraries
#include <MKRGSM.h>
// PIN Number
#define PINNUMBER ""
// APN data
#define GPRS_APN "GPRS_APN" // replace your GPRS APN
#define GPRS_LOGIN "login" // replace with your GPRS login
#define GPRS_PASSWORD "password" // replace with your GPRS password
// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess;
// URL, path & port (for example: arduino.cc)
char server[] = "arduino.cc";
char path[] = "/";
int port = 80; // port 80 is the default for HTTP
void setup()
{
// initialize serial communications
Serial.begin(9600);
Serial.println("Starting Arduino web client.");
// connection state
boolean notConnected = true;
// After starting the modem with GSM.begin()
// attach the shield to the GPRS network with the APN, login and password
while(notConnected)
{
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, port))
{
Serial.println("connected");
// Make a HTTP request:
client.print("GET ");
client.print(path);
client.println(" HTTP/1.0");
client.println();
}
else
{
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available())
{
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.available() && !client.connected())
{
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
for(;;)
;
}
}
相关用法
- Arduino MKRGSM - client.connected()用法及代码示例
- Arduino MKRGSM - client.available()用法及代码示例
- Arduino MKRGSM - client.stop()用法及代码示例
- Arduino MKRGSM - client.connect()用法及代码示例
- Arduino MKRGSM - gprs.attachGPRS()用法及代码示例
- Arduino MKRGSM - sms.read()用法及代码示例
- Arduino MKRGSM - sms.print()用法及代码示例
- Arduino MKRGSM - voice.answerCall()用法及代码示例
- Arduino MKRGSM - voice.hangCall()用法及代码示例
- Arduino MKRGSM - sms.write()用法及代码示例
- Arduino MKRGSM - gsm.shutdown()用法及代码示例
- Arduino MKRGSM - modem.getIMEI()用法及代码示例
- Arduino MKRGSM - sms.available()用法及代码示例
- Arduino MKRGSM - voice.voiceCall()用法及代码示例
- Arduino MKRGSM - GSM构造函数用法及代码示例
- Arduino MKRGSM - gsm.begin()用法及代码示例
- Arduino MKRGSM - sms.endSMS()用法及代码示例
- Arduino MKRGSM - grps.ping()用法及代码示例
- Arduino MKRGSM - sms.peek()用法及代码示例
- Arduino MKRGSM - sms.beginSMS()用法及代码示例
- Arduino MKRGSM - voice.retrieveCallingNumber()用法及代码示例
- Arduino MKRGSM - sms.flush()用法及代码示例
- Arduino MKRGSM - sms.remoteNumber()用法及代码示例
- Arduino MKRGSM - voice.getVoiceCallStatus()用法及代码示例
- Arduino MKRNB - getCurrentCarrier()用法及代码示例
注:本文由纯净天空筛选整理自arduino.cc大神的英文原创作品 MKRGSM - client.read()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。