当前位置: 首页>>代码示例>>C++>>正文


C++ EthernetClient::connect方法代码示例

本文整理汇总了C++中EthernetClient::connect方法的典型用法代码示例。如果您正苦于以下问题:C++ EthernetClient::connect方法的具体用法?C++ EthernetClient::connect怎么用?C++ EthernetClient::connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EthernetClient的用法示例。


在下文中一共展示了EthernetClient::connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: connectViaGateway

bool CosmClient::connectViaGateway(byte macAddress[], IPAddress localIP, IPAddress dnsServerIP, IPAddress gatewayIP, IPAddress subnet)
{
    Serial.begin(9600);

    Ethernet.begin(macAddress, localIP, dnsServerIP, gatewayIP, subnet);

    if (_client.connect(_host, _port)) {
        return true;
    }
    else {
        Ethernet.begin(macAddress, localIP, dnsServerIP, gatewayIP, subnet);
        return (_client.connect(_host, _port));
    }
}
开发者ID:Gerst20051,项目名称:ArduinoExamples,代码行数:14,代码来源:Cosm.cpp

示例2: connectWithIP

bool CosmClient::connectWithIP(byte macAddress[], IPAddress localIP)
{
    Serial.begin(9600);

    Ethernet.begin(macAddress, localIP);

    if (_client.connect(_host, _port)) {
        return true;
    }
    else {
        Ethernet.begin(macAddress, localIP);
        return (_client.connect(_host, _port));
    }
}
开发者ID:Gerst20051,项目名称:ArduinoExamples,代码行数:14,代码来源:Cosm.cpp

示例3: sendData

void sendData()
{
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect("kaylee.markild.no", 80))
  
  {
    Serial.println("connected");
    // Make a HTTP request:
    Serial.println("GET /crap/test.txt HTTP/1.1");
    client.println("GET /crap/test.txt HTTP/1.1");
    Serial.println("Host: kaylee.markild.no");
    client.println("Host: kaylee.markild.no");
    Serial.println("User-Agent: ArduinoUno/r3 Ethernet Shield");
    client.println("User-Agent: ArduinoUno/r3 Ethernet Shield");
    Serial.println("Accept: */*");
    client.println("Accept: */*");    
    client.println();
  }
  else
  {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}
开发者ID:torkildr,项目名称:display,代码行数:26,代码来源:ehternet_utility.cpp

示例4: sendData

// this method makes a HTTP connection to the server:
void sendData(String thisData) {
  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("connecting...");
    // send the HTTP PUT request:
    client.print("PUT /v2/feeds/");
    client.print(FEEDID);
    client.println(".csv HTTP/1.1");
    client.println("Host: api.xively.com");
    client.print("X-ApiKey: ");
    client.println(APIKEY);
    client.print("User-Agent: ");
    client.println(USERAGENT);
    client.print("Content-Length: ");
    client.println(thisData.length());

    // last pieces of the HTTP PUT request:
    client.println("Content-Type: text/csv");
    client.println("Connection: close");
    client.println();

    // here's the actual content of the PUT request:
    client.println(thisData);
  } 
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }
  // note the time that the connection was made or attempted:
  lastConnectionTime = millis();
}
开发者ID:KISSMonX,项目名称:gr_ethernet_examples,代码行数:35,代码来源:gr_XivelyClientString.cpp

示例5: sendData

/*
 * Sends an HTTP POST request containing the name and the code to the server.
 */
void sendData() {
	Serial.print("attempting to send data (name = ");
	Serial.print(nameBuf);
	Serial.print(", code = ");
	Serial.print(buffer);
	Serial.println(")");


	// if you get a connection, report back via serial:
	if (client.connect(server, port)) {
		Serial.println("connected");
		// Make a HTTP request:
		client.print("POST /barcode");
		client.print("?name=");
		client.print(nameBuf);
		client.print("&code=");
		client.print(buffer);
		client.print("&uptime=");
		client.print(millis());
		client.println(" HTTP/1.0");
		client.println();
		client.flush();
		client.stop();
		Serial.println("request sent");
	}
	else {
		// if you didn't get a connection to the server:
		Serial.println("connection failed");
	}
}
开发者ID:rjoberon,项目名称:arduino-barcode-client,代码行数:33,代码来源:scanner.cpp

示例6: setup

void setup() {
  Serial.begin(9600);   // Initialize serial communications with the PC
  while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();      // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522
//---------------ETHERNET INIT
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

// if you get a connection, report back via serial:
  if (client.connect(server, 3000)) {
    Serial.println("connected");
  } 
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }

}
开发者ID:saion-chatterjee,项目名称:iot-rfid-rc522-reader,代码行数:27,代码来源:rfid_reader_board1.cpp

示例7: 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()) {
  }
}
开发者ID:glelouet,项目名称:Connected_House,代码行数:30,代码来源:TcpClient.cpp

示例8: sendData

void CosmClient::sendData(uint32_t feedId, char datastreamId[], double dataToSend)
{
    if (_client.connect("api.cosm.com", 80)) {
        Serial.println("Connecting to Cosm...");

        _client.print("PUT /v2/feeds/");
        _client.print(feedId);
        _client.print("/datastreams/");
        _client.print(datastreamId);
        _client.print(".csv HTTP/1.1\n");
        _client.print("Host: api.cosm.com\n");

        _client.print("X-ApiKey: ");
        _client.print(_api);
        _client.print("\n");
        _client.print("Content-Length: ");

        int lengthOfData = getLength(dataToSend);
        _client.println(lengthOfData, DEC);

        _client.print("Content-Type: text/csv\n");
        _client.println("Connection: close\n");

        _client.print(dataToSend, DEC);
    }
}
开发者ID:Gerst20051,项目名称:ArduinoExamples,代码行数:26,代码来源:Cosm.cpp

示例9: createPoint

void Nimbits::createPoint(String pointName)
{
  EthernetClient client;
  if (client.connect(GOOGLE, PORT))
  {
    client.println(F("POST /service/point HTTP/1.1"));
    String content;
    //  writeAuthParams(content);
    content += "email=";
    content += _ownerEmail;
    if (_accessKey.length() > 0)
    {
      content += ("&key=");
      content += (_accessKey);
    }
    content += "&action=create&point=";
    content += (pointName);
    client.println(F("Host:nimbits1.appspot.com"));
    client.println(F("Connection:close"));
    client.println(F("Cache-Control:max-age=0"));
    client.print(F("Content-Type: application/x-www-form-urlencoded\n"));
    client.print(F("Content-Length: "));
    client.print(content.length());
    client.print(F("\n\n"));
    client.print(content);
    while (client.connected() && !client.available())
    {
      delay(1); //waits for data
    }
    client.stop();
    client.flush();
  }

}
开发者ID:pelrun,项目名称:Logger,代码行数:34,代码来源:Nimbits.cpp

示例10: setup

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.1");
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println();
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }

}
开发者ID:ern0,项目名称:posixino,代码行数:33,代码来源:WebClient.cpp

示例11: recordValue

void Nimbits::recordValue(double value, String pointId) {
  EthernetClient client;

 String json;
 json =  "{\"d\":\"";
 json += floatToString(value, 4);

json +=  "\"}";
  String content;

  content += "&json=";
  content += json;
  content += "&id=";
  content +=  pointId;



  if (client.connect(_hostname.c_str(), _port)) {

    doPost(client, VALUE_API, content);

    String response = getFullResponse(client);


    client.stop();
  }
  else {

    client.stop();
  }

}
开发者ID:cloudstrifexx,项目名称:com.nimbits,代码行数:32,代码来源:Nimbits.cpp

示例12: serverRequest

//builds the url for the api request, connects to the server, and sends the request
boolean serverRequest() {
	//Serial.print(server);
	//Serial.println(page);
	client.stop();

	Serial.println("connecting...");
	if (client.connect(server, 80)) {
		Serial.println("connected");
		client.print("GET /makermanager/index.php?r=api/toolValidate&badge=");
		client.print(rfid_long);
		client.print("&tool=1");
		client.println(" HTTP/1.1");
		client.print("Host: ");
		client.println(server);
		client.println("User-Agent: arduino-ethernet");
		client.println("Connection: close");
		client.println("");
		
		//Serial.println(cmd);
		//client.println(cmd);
		return true;
	}
	else {
		Serial.println("connection failed");
		return false;
	}
}
开发者ID:mikelduke,项目名称:DMS-RFID-Interlock,代码行数:28,代码来源:PowerInterlock.cpp

示例13: EC_Connect

void EC_Connect(void)
{
#ifdef USE_RS485
 #if _DEBUG_>0
	Serial.println(F("Connected to EnergyCam via RS485."));
 #endif
	RS485_ENABLE_TX;
	ec_state = EC_OK;
#else

#define EC_CONNECT_TIMEOUT	5000	// millis
	int reply;
	byte ec_ip[] = {192,168,100,48};
	int ec_port = 8088;
//  int8_t repl = 0;
#if _DEBUG_>0
	Serial.print(F("Connecting to EnergyCam ... "));
#endif
	// if you get a connection, report back via serial:
	timeout = millis();  // time within to get reply
	while (1) {
		if ( (millis()-timeout)>EC_CONNECT_TIMEOUT ) {  // if no answer received within the prescribed time
			//time_client.stop();
#if _DEBUG_>0
			Serial.print(F("timed out..."));
#endif
			break;
		}
		WDG_RST;
		reply = ec_client.connect(ec_ip, ec_port);
		if ( reply>0 ) break;
		else  delay(100);
	}
	if ( reply<=0 ) {
#if _DEBUG_>0
		// if you didn't get a connection to the server:
		Serial.print(F("failed: "));
		if ( reply==-1 ) Serial.println(F("timed out."));
		else if ( reply==-2 ) Serial.println(F("invalid server."));
		else if ( reply==-3 ) Serial.println(F("truncated."));
		else if ( reply==-4 ) Serial.println(F("invalid response"));
		else Serial.println(reply);
#endif
		ec_state = CONNECTION_TIMEOUT;  // to avoid error code 0
	} else {
    // connection was successful.
#if _DEBUG_>0
		Serial.println(F("done."));
#endif
		ec_state = EC_OK;
	}
	
#endif	// #ifdef USE_RS485
}
开发者ID:stevstrong,项目名称:HomeServer,代码行数:54,代码来源:energy_cam.cpp

示例14: loop

void loop() {
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }

  client.connect(server, 3000);

  char store_id[30];
  
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i]);
  } 
	Serial.println();

  unsigned int hex_num;
  hex_num =  mfrc522.uid.uidByte[0] << 24;
  hex_num += mfrc522.uid.uidByte[1] << 16;
  hex_num += mfrc522.uid.uidByte[2] <<  8;
  hex_num += mfrc522.uid.uidByte[3];

  int  NFC_id=  (int)hex_num;

  sprintf(store_id,"%d" ,NFC_id);

  Serial.print("Store id is: ");
  Serial.println(store_id);

  char req[80];
  strcpy(req, "GET /?uid=");
  strcat(req, store_id);
  strcat(req, "&lat=48.139867&long=11.560935&sensor=MUCHbf HTTP/1.0");
    
  // Make a HTTP request:
  client.println(req);
  client.println();
  Serial.println("Request sent");
  Serial.println(req);

  
  // if there are incoming bytes available 
  // from the server, read them and print them:
  while (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

}
开发者ID:saion-chatterjee,项目名称:iot-rfid-rc522-reader,代码行数:53,代码来源:rfid_reader_board1.cpp

示例15: httpRequest

// This method makes an HTTP connection to the server
void httpRequest(String link) {
	//if there is a successful connection
	if (client.connect(server, 80)) {
		client.println("Get " + link + " HTTP/1.0 ");
		client.println();

	} else {
		// You couldn't make the connection
		Serial.println("Connection Failed");
		Serial.println("Disconnecting.");
	}
		client.stop(); }
开发者ID:niskyponics,项目名称:niskyponics-arduino,代码行数:13,代码来源:txt_messaging.c


注:本文中的EthernetClient::connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。