本文整理汇总了C++中EthernetClient::read方法的典型用法代码示例。如果您正苦于以下问题:C++ EthernetClient::read方法的具体用法?C++ EthernetClient::read怎么用?C++ EthernetClient::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EthernetClient
的用法示例。
在下文中一共展示了EthernetClient::read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loop
void loop() {
client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
if (client.find("GET /")) {
//INICIAR CRONOMETRAGEM
if (client.find("setCron=")) {
int charReaded = client.read();
if(charReaded == 49){
iniciarCronometragem();
}
}
//RETORNA O TEMPO DESDE O INICIO
if (client.find("getCron=")) {
int charReaded = client.read();
if(charReaded == 49){
getCronometragem();
}
}
}
}
Serial.println();
break;
}
client.println(" HTTP/1.1 200 OK ");
}
// give the web browser time to receive the data
delay(1);
client.stop();
}
示例2: GAE
String GAE(String link) {
httpRequest(link);
delay(10000);
String readString = ""; //Reset string
while (client.available() > 0) {
char s = client.read();
//Serial.print(s); //Complete response w/ headers. For dev mode.
if (s== '\n') {
char c = client.read();
//Serial.print(c); //Parsed response. For dev mode.
if (c == '\r') {
while (client.connected()) {
char z = client.read();
readString += z;
}
}
}
}
client.stop();
return(readString);
}
示例3: read
void MyClientManager::read(EthernetClient client)
{
int data_size = client.available();
int x = 0;
if (headeroffset != 3 && data_size + headeroffset >= HEADER_SIZE)
{
while (headeroffset != HEADER_SIZE && x < data_size)
{
header[headeroffset] = client.read();
++headeroffset;
++x;
}
if (headeroffset == 3 && header[2] + 1 > BUFFER_SIZE)
reset();
}
else if (headeroffset == 3 && bufferoffset != header[2] && data_size + bufferoffset >= header[2])
{
while (bufferoffset != header[2] && x < data_size)
{
buffer[bufferoffset] = client.read();
++bufferoffset;
++x;
}
}
else if (headeroffset == 3 && bufferoffset == header[2] && !checksumisset && data_size > 0)
{
checksum = client.read();
checksumisset = true;
}
}
示例4: readStream
void Parser::readStream(EthernetClient client,char* myreadstring) {
char c = 0; //carctère de lecture
char tempo[255];
bool currentLineIsBlank = true;
int n = 1;
int flag = 0;
for (int k = 0; k < 50; k++) tempo[k] = 0;
c = client.read(); //lecture du premier caractère;
if (c != (-1)) {
if ( c == 'G') {
flag = 1;
tempo[0] = c;
while (c != '\n') {
c = client.read(); //lecture du caractère
delay(5);
tempo[n] = c;
delay(5);
n++;
}
}
else {
tempo[0] = '¤';
tempo[1] = '?';
while (client.available() > 0) {
c = client.read();
if (c == '\n' && currentLineIsBlank) {
while (c != '\r') { //doute
c = client.read(); //lecture du caractère
delay(5);
if (c == (-1))
break;
tempo[n + 1] = c;
delay(5);
n++;
}
}
else if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
}
if (!flag)n++;
for (int j = 0; j < n; j++)
myreadstring[j] = tempo[j] ;
}
示例5: printClient
void printClient(EthernetClient client){
int i=0;
char c = client.read();
while(c != '\n' && c != '\r'){
buffer[i] = c;
i++;
c = client.read();
}
for(int j=0; j<i; j++){
Serial.write(buffer[j]);
}
}
示例6: task
void ModbusIP::task() {
EthernetClient client = _server.available();
if (client) {
if (client.connected()) {
int i = 0;
while (client.available()){
_MBAP[i] = client.read();
i++;
if (i==7) break; //MBAP length has 7 bytes size
}
_len = _MBAP[4] << 8 | _MBAP[5];
_len--; // Do not count with last byte from MBAP
if (_MBAP[2] !=0 || _MBAP[3] !=0) return; //Not a MODBUSIP packet
if (_len > MODBUSIP_MAXFRAME) return; //Length is over MODBUSIP_MAXFRAME
_frame = (byte*) malloc(_len);
i = 0;
while (client.available()){
_frame[i] = client.read();
i++;
if (i==_len) break;
}
this->receivePDU(_frame);
if (_reply != MB_REPLY_OFF) {
//MBAP
_MBAP[4] = (_len+1) >> 8; //_len+1 for last byte from MBAP
_MBAP[5] = (_len+1) & 0x00FF;
byte sendbuffer[7 + _len];
for (i = 0 ; i < 7 ; i++) {
sendbuffer[i] = _MBAP[i];
}
//PDU Frame
for (i = 0 ; i < _len ; i++) {
sendbuffer[i+7] = _frame[i];
}
client.write(sendbuffer, _len + 7);
}
#ifndef TCP_KEEP_ALIVE
client.stop();
#endif
free(_frame);
_len = 0;
}
示例7: loop
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
// we get a request
if (client) {
Serial.println(F("Client connected"));
// an http request ends with a blank line
boolean done = false;
while (client.connected() && !done) {
while (client.available () > 0 && !done) {
done = processIncomingByte (client.read ());
}
} // end of while client connected
// get ROV status values as json string
String rovStatus = getRovStatus();
// send a standard http response header
client.println(F("HTTP/1.1 200 OK"));
client.println(F("Content-Type: text/json"));
client.println(F("Connection: close")); // close after completion of the response
client.println(); // end of HTTP header
client.println(rovStatus);
// give the web browser time to receive the data
delay(10);
// close the connection:
client.stop();
Serial.println(F("Client disconnected"));
} // end of got a new client
} // end of loop
示例8: efail
void efail()
{
byte thisByte = 0;
int loopCount = 0;
eth_client.println(F("QUIT"));
while(!eth_client.available()) {
#ifdef WATCHDOG
wdt_reset();
#endif
delay(1);
loopCount++;
// if nothing received for 10 seconds, timeout
if(loopCount > 10000) {
eth_client.stop();
Serial.println(F("\r\nTimeout"));
return;
}
}
while(eth_client.available())
{
thisByte = eth_client.read();
Serial.write(thisByte);
}
eth_client.stop();
Serial.println(F("disconnected"));
}
示例9: loop
void loop() {
unsigned long time = millis();
if (next < time) {
Ethernet.maintain();
next += send_delay;
if (next <= time)
next = time + 1;
Serial.println("request time !");
if (client.connected()) {
Serial.println("already connected");
} else {
Serial.print("connecting results : ");
Serial.println(client.connect("tarzan.info.emn.fr", 80));
}
int sent = client.println("GET /ping.php HTTP/1.1");
sent = client.println(F("Host: tarzan.info.emn.fr"));
client.println();
}
if (client.connected() && client.available() > 0) {
Serial.println("client received data : ");
unsigned char buffer[buff_size + 1];
while (client.available() > 0) {
int read = client.read(buffer, buff_size);
buffer[read] = '\0';
Serial.println(read);
}
}
if (radio.receiveDone()) {
}
}
示例10: loop
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client)
{
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
Serial.write(c);
//*******************233333333333333333333333333333333333333333333*******
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank)
{
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: textml");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("<br />");
}
client.println("<ml>");
break;
}
if (c == '\n')
{
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r')
{
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
示例11: parseRequest
bool PyrobarHTTPRequestHandler::parseRequest(EthernetClient client) {
if (client.available()) {
if(client.readStringUntil(' ') == "GET") {
if(client.read() == '/') {
String dataType = client.readStringUntil('/');
if (DEBUG_REQUEST_HANDLER) {
Serial.print("Data Type: ");
Serial.println(dataType);
}
if(dataType == pyrobarDataTypeBuffer) {
return handleBuffer(client);
} else if(dataType == pyrobarDataTypeFire) {
return handleFireSequence(client);
} else if(dataType == pyrobarDataTypeScalar) {
return handleScalar(client);
} else if(dataType == pyrobarDataTypeLights) {
return handleLightsOnOff(client);
} else {
return false;
}
}
} else {
return false;
}
}
}
示例12: getData
void getData(char *dst)
{
Serial.println("Trying to grab data from server:");
// from the server, read them and print them:
int i = 0;
while (!client.available());
while (client.available()) {
char c = client.read();
Serial.print(c);
if (i < 10)
{
dst[i] = c;
//dst[i+1] = 0;
}
i++;
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while(true);
}
}
示例13: loop
void loop() {
// if there's incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if there's no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
// if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
httpRequest();
}
// store the state of the connection for next time through
// the loop:
lastConnected = client.connected();
}
示例14: if
static void
extract_status_code(struct HTTPObject *h, EthernetClient client){
unsigned int k,multiplier,j;
j=0;
char c;
const byte STATUS_CODE_START_INDEX = 9;
const byte STATUS_CODE_END_INDEX = 11;
while(j<=STATUS_CODE_END_INDEX && client.connected()){
if(client.available()){
// We want to extract the 200 from "HTTP/1.1 200 OK". The
// status code starts at index 9 in the string and ends at 11
c = client.read();
if(j<STATUS_CODE_START_INDEX){
j++;
}
else if(j>=STATUS_CODE_START_INDEX && j<=STATUS_CODE_END_INDEX){
// code = 10^2 * str[9] + 10^1 * str[10] + 10^0 * str[11]
// Do ghetto exponentiation here.
multiplier = 1;
for(k = 1; k <= 2 - (j - STATUS_CODE_START_INDEX); k++){
multiplier *= 10;
}
// c - '0' => char to int
h->statusCode += (c - '0') * multiplier;
j++;
}
}
}
}
示例15: receiveEthernet
void MorpheusSlave::receiveEthernet(EthernetClient& incoming) {
if ( incoming.available() ) {
char b;
while ( incoming.available() > 0 ) {
_lastRX = millis();
b = incoming.read();
#if DBG
Serial.print("B: ");
Serial.println(b);
#endif
if ( b == '\n' ) {
endComm();
break;
}
else if ( command == NULL ) {
command = b;
data = "";
}
else {
data += b;
}
}
}
if ( _lastRX != -1 && millis() - _lastRX > RX_TIMEOUT ) {
endComm();
}
}