http client test
This commit is contained in:
parent
8773ef7068
commit
454172a5fd
@ -1,26 +1,27 @@
|
|||||||
// #include <Arduino.h>
|
/*
|
||||||
// #include "Program.h"
|
WiFiEsp example: WebClient
|
||||||
|
|
||||||
// Program* program;
|
This sketch connects to google website using an ESP8266 module to
|
||||||
|
perform a simple web search.
|
||||||
|
|
||||||
// void setup() {
|
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp-example-client.html
|
||||||
// program = new Program();
|
*/
|
||||||
// }
|
|
||||||
|
|
||||||
// void loop() {
|
#include "WiFiEsp.h"
|
||||||
// program->loop();
|
|
||||||
// }
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
// Emulate Serial1 on pins 6/7 if not present
|
||||||
|
#ifndef HAVE_HWSERIAL1
|
||||||
#include <WiFiEsp.h>
|
#include "SoftwareSerial.h"
|
||||||
|
SoftwareSerial Serial1(6, 7); // RX, TX
|
||||||
const char ssid[] = "Clement4G"; // your network SSID (name)
|
#endif
|
||||||
const char pass[] = "Clement123"; // your network password
|
|
||||||
|
|
||||||
|
char ssid[] = "Clement4G"; // your network SSID (name)
|
||||||
|
char pass[] = "Clement123"; // your network password
|
||||||
int status = WL_IDLE_STATUS; // the Wifi radio's status
|
int status = WL_IDLE_STATUS; // the Wifi radio's status
|
||||||
|
|
||||||
char server[] = "arduino.cc";
|
char server[] = "arduino.tips";
|
||||||
|
|
||||||
|
void printWifiStatus();
|
||||||
|
|
||||||
// Initialize the Ethernet client object
|
// Initialize the Ethernet client object
|
||||||
WiFiEspClient client;
|
WiFiEspClient client;
|
||||||
@ -48,8 +49,10 @@ void setup() {
|
|||||||
status = WiFi.begin(ssid, pass);
|
status = WiFi.begin(ssid, pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// you're connected now, so print out the data
|
||||||
Serial.println("You're connected to the network");
|
Serial.println("You're connected to the network");
|
||||||
|
|
||||||
|
printWifiStatus();
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("Starting connection to server...");
|
Serial.println("Starting connection to server...");
|
||||||
@ -58,38 +61,18 @@ void setup() {
|
|||||||
Serial.println("Connected to server");
|
Serial.println("Connected to server");
|
||||||
// Make a HTTP request
|
// Make a HTTP request
|
||||||
client.println("GET /asciilogo.txt HTTP/1.1");
|
client.println("GET /asciilogo.txt HTTP/1.1");
|
||||||
client.println("Host: arduino.cc");
|
client.println("Host: arduino.tips");
|
||||||
client.println("Connection: close");
|
client.println("Connection: close");
|
||||||
client.println();
|
client.println();
|
||||||
Serial.print("POUET");
|
|
||||||
} else {
|
|
||||||
Serial.print(client.status());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void printWifiData() {
|
|
||||||
// print your WiFi shield's IP address
|
|
||||||
IPAddress ip = WiFi.localIP();
|
|
||||||
Serial.print("IP Address: ");
|
|
||||||
Serial.println(ip);
|
|
||||||
|
|
||||||
// print your MAC address
|
|
||||||
byte mac[6];
|
|
||||||
WiFi.macAddress(mac);
|
|
||||||
char buf[20];
|
|
||||||
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
|
|
||||||
Serial.print("MAC address: ");
|
|
||||||
Serial.println(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// print the network connection information every 10 seconds
|
|
||||||
//Serial.println();
|
|
||||||
printWifiData();
|
|
||||||
|
|
||||||
// if there are incoming bytes available
|
// if there are incoming bytes available
|
||||||
// from the server, read them and print them
|
// from the server, read them and print them
|
||||||
Serial.println(client.status());
|
if (!client.available()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
while (client.available()) {
|
while (client.available()) {
|
||||||
char c = client.read();
|
char c = client.read();
|
||||||
Serial.write(c);
|
Serial.write(c);
|
||||||
@ -104,6 +87,22 @@ void loop() {
|
|||||||
// do nothing forevermore
|
// do nothing forevermore
|
||||||
while (true);
|
while (true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//delay(10000);
|
|
||||||
}
|
void printWifiStatus() {
|
||||||
|
// print the SSID of the network you're attached to
|
||||||
|
Serial.print("SSID: ");
|
||||||
|
Serial.println(WiFi.SSID());
|
||||||
|
|
||||||
|
// print your WiFi shield's IP address
|
||||||
|
IPAddress ip = WiFi.localIP();
|
||||||
|
Serial.print("IP Address: ");
|
||||||
|
Serial.println(ip);
|
||||||
|
|
||||||
|
// print the received signal strength
|
||||||
|
long rssi = WiFi.RSSI();
|
||||||
|
Serial.print("Signal strength (RSSI):");
|
||||||
|
Serial.print(rssi);
|
||||||
|
Serial.println(" dBm");
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user