本文整理汇总了C++中WiFiClient::connect方法的典型用法代码示例。如果您正苦于以下问题:C++ WiFiClient::connect方法的具体用法?C++ WiFiClient::connect怎么用?C++ WiFiClient::connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WiFiClient
的用法示例。
在下文中一共展示了WiFiClient::connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: attemptClient
// See if port 80 is accessable. Try 8080 as well.
boolean WiFiManager::attemptClient(const char *szUrl)
{
WiFiClient client;
int i;
Serial.print("Probe port 80");
for(i = 0; i < 5; i++)
{
if (client.connect(szUrl, httpPort)) {
client.stop();
Serial.println("Port 80 success");
return true;
}
Serial.print(".");
delay(20);
}
httpPort = 8080;
Serial.println("");
Serial.print("Probe port 8080");
for(i = 0; i < 5; i++)
{
if (client.connect(szUrl, httpPort)) {
client.stop();
Serial.println("Port 8080 success");
return true;
}
Serial.print(".");
delay(20);
}
Serial.println("");
Serial.println("No joy");
return false;
}
示例2: AJ_Net_Connect
AJ_Status AJ_Net_Connect(AJ_BusAttachment* bus, const AJ_Service* service)
{
int ret;
IPAddress ip(service->ipv4);
if (!(service->addrTypes & AJ_ADDR_TCP4)) {
AJ_ErrPrintf(("AJ_Net_Connect(): only IPV4 TCP supported\n", ret));
return AJ_ERR_CONNECT;
}
AJ_InfoPrintf(("AJ_Net_Connect(bus=0x%p, addrType=%d.)\n", bus, service->addrTypes));
ret = g_client.connect(ip, service->ipv4port);
if (ret != 1) {
AJ_ErrPrintf(("AJ_Net_Connect(): connect() failed: %d: status=AJ_ERR_CONNECT\n", ret));
return AJ_ERR_CONNECT;
} else {
AJ_IOBufInit(&bus->sock.rx, rxData, sizeof(rxData), AJ_IO_BUF_RX, (void*)&g_client);
bus->sock.rx.recv = AJ_Net_Recv;
AJ_IOBufInit(&bus->sock.tx, txData, sizeof(txData), AJ_IO_BUF_TX, (void*)&g_client);
bus->sock.tx.send = AJ_Net_Send;
AJ_ErrPrintf(("AJ_Net_Connect(): connect() success: status=AJ_OK\n"));
return AJ_OK;
}
AJ_ErrPrintf(("AJ_Net_Connect(): connect() failed: %d: status=AJ_ERR_CONNECT\n", ret));
return AJ_ERR_CONNECT;
}
示例3: sendParameter
void EIoTCloudRestApi::sendParameter(const char * instaceParamId, String value)
{
WiFiClient client;
while(!client.connect(EIOT_CLOUD_ADDRESS, EIOT_CLOUD_PORT)) {
debug("connection failed");
wifiConnect();
}
String url = "";
// URL: /RestApi/SetParameter/[instance id]/[parameter id]/[value]
url += "/RestApi/SetParameter/" + String(instaceParamId) + "/" + value; // generate EasIoT cloud update parameter URL
debug("POST data to URL: ");
#ifdef DEBUG
char buff[300];
url.toCharArray(buff, 300);
debug(buff);
#endif
client.print(String("POST ") + url + " HTTP/1.1\r\n" +
"Host: " + String(EIOT_CLOUD_ADDRESS) + "\r\n" +
"Connection: close\r\n" +
"Content-Length: 0\r\n" +
"\r\n");
delay(100);
while(client.available()){
#ifdef DEBUG
String line = client.readStringUntil('\r');
line.toCharArray(buff, 300);
debug(buff);
#endif
}
}
示例4: AJ_Net_Connect
AJ_Status AJ_Net_Connect(AJ_NetSocket* netSock, uint16_t port, uint8_t addrType, const uint32_t* addr)
{
int ret;
IPAddress ip(*addr);
AJ_InfoPrintf(("AJ_Net_Connect(nexSock=0x%p, port=%d., addrType=%d., addr=0x%p)\n", netSock, port, addrType, addr));
AJ_InfoPrintf(("AJ_Net_Connect(): Connect to 0x%x:%u.\n", addr, port));;
ret = g_client.connect(ip, port);
#ifdef NOTDEF
Serial.print("Connecting to: ");
Serial.print(ip);
Serial.print(':');
Serial.println(port);
#endif
if (ret == -1) {
AJ_ErrPrintf(("AJ_Net_Connect(): connect() failed: %d: status=AJ_ERR_CONNECT\n", ret));
return AJ_ERR_CONNECT;
} else {
AJ_IOBufInit(&netSock->rx, rxData, sizeof(rxData), AJ_IO_BUF_RX, (void*)&g_client);
netSock->rx.recv = AJ_Net_Recv;
AJ_IOBufInit(&netSock->tx, txData, sizeof(txData), AJ_IO_BUF_TX, (void*)&g_client);
netSock->tx.send = AJ_Net_Send;
AJ_ErrPrintf(("AJ_Net_Connect(): connect() success: status=AJ_OK\n"));
return AJ_OK;
}
AJ_ErrPrintf(("AJ_Net_Connect(): connect() failed: %d: status=AJ_ERR_CONNECT\n", ret));
return AJ_ERR_CONNECT;
}
示例5: HttpRequest
String DHwifi::HttpRequest( String req )
{
WiFiClient client;
char host[99];
m_remoteServer.toCharArray( host, 99);
const int httpPort = 80;
if (!client.connect(host, httpPort))
{
Serial.print( host );
Serial.println(" connection failed");
return "";
}
client.print(String("GET ") + req + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(10);
String result;
// Read all the lines of the reply from server and print them to Serial
while (client.available())
{
result = client.readStringUntil('\r');
}
return result;
}
示例6: Iotfy_postdata
void Iotfy_postdata(String group_iotfy, String id_iotfy, String tag_iotfy, String value_iotfy)
{
debug("in postdata");
debug("setting id");
String X_IOTFY_ID="X-IOTFY-ID: "+IOTFY_ID;
String X_IOTFY_CLIENT="X-IOTFY-CLIENT: "+IOTFY_CLIENT;
debug(X_IOTFY_CLIENT);
debug(X_IOTFY_ID);
String data="\{\"group\":\"";
data+=group_iotfy;
data+="\", \"device\":\"";
data+=id_iotfy;
data+="\", \"data\":[{";
data+="\"tag\":\"";
data+=tag_iotfy;
data+="\"";
data+=",\"text\":\"";
data+=value_iotfy;
data+="\"}]}";
debug("Trying to connect");
if (client.connect(server, 80))
{
debug("connected and now sending post request");
client.println("POST /api/telemetry/v1/post_text_data HTTP/1.0");
//client.println("POST /api/telemetry/v1/post_text_data HTTP/1.1");
client.println("User-Agent: arduino-ESP");
client.println("Host: cloud.iotfy.co");
client.println(X_IOTFY_ID);
client.println(X_IOTFY_CLIENT);
client.println("Content-Type: application/json");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.println(data);
client.println("Connection: close");
if(DEBUG)
{
debug("connected");
debug("POST /api/telemetry/v1/post_text_data HTTP/1.0");
//debug("POST /api/telemetry/v1/post_text_data HTTP/1.1");
debug("User-Agent: arduino-ESP");
debug("Host: cloud.iotfy.co");
debug(X_IOTFY_ID);
debug(X_IOTFY_CLIENT);
debug("Content-Type: application/json");
debug("Content-Length: ");
debug((String)data.length());
debug("");
debug(data);
}
}
}
示例7: send
void Farmy::send( const char* device_id, int input_pins[], String api_key, WiFiClient client)
{
if(!client.connect(host, 80)) {
Serial.println("connection failed");
return;
}
String data = collectData(input_pins);
sendData(device_id, api_key, client, data);
}
示例8: getLastChannelItem
void ThingspeakClient::getLastChannelItem(String channelId, String readApiKey) {
JsonStreamingParser parser;
parser.setListener(this);
WiFiClient client;
// http://api.thingspeak.com/channels/CHANNEL_ID/feeds.json?results=2&api_key=API_KEY
const char host[] = "api.thingspeak.com";
String url = "/channels/" + channelId +"/feeds.json?results=1&api_key=" + readApiKey;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
int retryCounter = 0;
while(!client.available()) {
Serial.println(".");
delay(1000);
retryCounter++;
if (retryCounter > 10) {
return;
}
}
int pos = 0;
boolean isBody = false;
char c;
int size = 0;
client.setNoDelay(false);
while(client.connected()) {
while((size = client.available()) > 0) {
c = client.read();
if (c == '{' || c == '[') {
isBody = true;
}
if (isBody) {
parser.parse(c);
}
}
}
}
示例9: updateTime
void TimeClient::updateTime() {
WiFiClient client;
const int httpPort = 80;
if (!client.connect("google.com", httpPort)) {
Serial.println("connection failed");
return;
}
// This will send the request to the server
client.print(String("GET / HTTP/1.1\r\n") +
String("Host: google.com\r\n") +
String("Connection: close\r\n\r\n"));
int repeatCounter = 0;
while(!client.available() && repeatCounter < 10) {
delay(1000);
Serial.println(".");
repeatCounter++;
}
String line;
int size = 0;
client.setNoDelay(false);
while(client.connected()) {
while((size = client.available()) > 0) {
line = client.readStringUntil('\n');
line.toUpperCase();
// example:
// date: Thu, 19 Nov 2015 20:25:40 GMT
if (line.startsWith("DATE: ")) {
Serial.println(line.substring(23, 25) + ":" + line.substring(26, 28) + ":" +line.substring(29, 31));
int parsedHours = line.substring(23, 25).toInt();
int parsedMinutes = line.substring(26, 28).toInt();
int parsedSeconds = line.substring(29, 31).toInt();
Serial.println(String(parsedHours) + ":" + String(parsedMinutes) + ":" + String(parsedSeconds));
localEpoc = (parsedHours * 60 * 60 + parsedMinutes * 60 + parsedSeconds);
Serial.println(localEpoc);
localMillisAtUpdate = millis();
}
}
}
}
示例10: doUpdate
void WundergroundClient::doUpdate(String url) {
JsonStreamingParser parser;
parser.setListener(this);
WiFiClient client;
const int httpPort = 80;
if (!client.connect("api.wunderground.com", httpPort)) {
Serial.println("connection failed");
return;
}
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: api.wunderground.com\r\n" +
"Connection: close\r\n\r\n");
int retryCounter = 0;
while(!client.available()) {
delay(1000);
retryCounter++;
if (retryCounter > 10) {
return;
}
}
int pos = 0;
boolean isBody = false;
char c;
int size = 0;
client.setNoDelay(false);
while(client.connected()) {
while((size = client.available()) > 0) {
c = client.read();
if (c == '{' || c == '[') {
isBody = true;
}
if (isBody) {
parser.parse(c);
}
}
}
}
示例11: sendTeperatureTS
void sendTeperatureTS(int temp1, int temp2, int temp3, int temp4)
{
WiFiClient client;
if (client.connect(tsserver, 80)) { // use ip 184.106.153.149 or api.thingspeak.com
Serial.println("WiFi Client connected_neu ");
EEPROM.begin(512);
delay(10);
String apiKey = "";
for (int i = 81; i < 97; i++)
{
apiKey += char(EEPROM.read(i));
}
EEPROM.end();
Serial.println("Thingspeak-API_neu: " + apiKey);
String postStr = apiKey;
postStr += "&field1=";
postStr += String(temp1);
postStr += "&field2=";
postStr += String(temp2);
postStr += "&field3=";
postStr += String(temp3);
postStr += "&field4=";
postStr += String(temp4);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
delay(1000);
Serial.println("Daten an Thingspeak gesendet");
}//end if
sent++;
client.stop();
}//end send
示例12: init
void init()
{
Serial.begin(SERIAL_BAUD_RATE); // 115200 by default
Serial.systemDebugOutput(true); // Enable debug output to serial
pinMode(LED_PIN, OUTPUT);//LED
WifiStation.enable(true);
WifiStation.config(WIFI_SSID, WIFI_PWD);
WifiAccessPoint.enable(false);
delay(4000);
// Connect to the websocket server
if (client.connect("echo.websocket.org", 80)) {
Serial.println("Connected");
} else {
Serial.println("Connection failed.");
while(1) {
// Hang on failure
digitalWrite(LED_PIN, 0x1);//LED ON
delay(500);
digitalWrite(LED_PIN, 0x0);//LED OFF
}
}
// Handshake with the server
webSocketClient.path = path;
webSocketClient.host = host;
if (webSocketClient.handshake(client)) {
Serial.println("Handshake successful");
} else {
Serial.println("Handshake failed.");
while(1) {
// Hang on failure
digitalWrite(LED_PIN, 0x1);//LED ON
delay(100);
digitalWrite(LED_PIN, 0x0);//LED OFF
}
}
////loop every 10 msec
procTimer.initializeMs(10, loop).start();//10 msec
}
示例13: connectSensorAPI
bool connectSensorAPI()
{
/* ToDo: Add SSL/TLS support */
uint16_t port;
char hostname[NODE_EEPROM_API_HOSTNAME_MAX_LENGTH + 1];
if(WiFi.status() != WL_CONNECTED) {
return false;
}
getAPIHostnameOrDefault(&hostname[0], NODE_EEPROM_API_HOSTNAME_MAX_LENGTH);
hostname[NODE_EEPROM_API_HOSTNAME_MAX_LENGTH] = '\0';
port = getAPIPortOrDefault();
client.stop();
if(client.connect(hostname, port)) {
return true;
}
return false;
}
示例14: httpRequest
void httpRequest() {
// close any connection before send a new request.
// This will free the socket on the WiFi shield
client.stop();
// if there's a successful connection:
if (client.connect("www.hasthelargehadroncolliderdestroyedtheworldyet.com", 80)) {
Serial5.println("connecting...");
// send the HTTP PUT request:
client.println("GET / HTTP/1.1");
client.println("Host: www.hasthelargehadroncolliderdestroyedtheworldyet.com");
//client.println("User-Agent: ArduinoWiFi/1.1");
client.println("Connection: close");
client.println();
if( client.connected() )
{
Serial5.println("\tClient connected");
while( client.available() == 0 )
{
//Waiting for data
if( !client.connected() )
{
Serial5.println("\tClient disconnected !");
break;
}
}
}
else
{
Serial5.println("\tClient not connected");
}
}
else {
// if you couldn't make a connection:
Serial5.println("\tconnection failed");
}
}
示例15: setup
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println("Connected to wifi");
printWifiStatus();
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected to server");
// 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();
}
}