本文整理汇总了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));
}
}
示例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));
}
}
示例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");
}
}
示例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();
}
示例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");
}
}
示例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");
}
}
示例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()) {
}
}
示例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);
}
}
示例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();
}
}
示例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");
}
}
示例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();
}
}
示例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;
}
}
示例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
}
示例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);
}
}
示例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(); }