http client test

This commit is contained in:
Clement 2023-03-13 17:21:04 +01:00
parent 8773ef7068
commit 454172a5fd

View File

@ -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() {
// program = new Program();
// }
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp-example-client.html
*/
// void loop() {
// program->loop();
// }
#include "WiFiEsp.h"
#include <Arduino.h>
#include <WiFiEsp.h>
const char ssid[] = "Clement4G"; // your network SSID (name)
const char pass[] = "Clement123"; // your network password
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "Clement4G"; // your network SSID (name)
char pass[] = "Clement123"; // your network password
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
WiFiEspClient client;
@ -48,8 +49,10 @@ void setup() {
status = WiFi.begin(ssid, pass);
}
// you're connected now, so print out the data
Serial.println("You're connected to the network");
printWifiStatus();
Serial.println();
Serial.println("Starting connection to server...");
@ -58,38 +61,18 @@ void setup() {
Serial.println("Connected to server");
// Make a HTTP request
client.println("GET /asciilogo.txt HTTP/1.1");
client.println("Host: arduino.cc");
client.println("Host: arduino.tips");
client.println("Connection: close");
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() {
// print the network connection information every 10 seconds
//Serial.println();
printWifiData();
// if there are incoming bytes available
// from the server, read them and print them
Serial.println(client.status());
if (!client.available()) {
return;
}
while (client.available()) {
char c = client.read();
Serial.write(c);
@ -104,6 +87,22 @@ void loop() {
// do nothing forevermore
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");
}