1er test avec http in arduinoCC

This commit is contained in:
Clement 2023-03-13 16:46:15 +01:00
parent 9b4afa2b74
commit 8773ef7068
2 changed files with 103 additions and 5 deletions

View File

@ -36,6 +36,7 @@ monitor_flags =
; librairies
lib_deps =
bportaluri/WiFiEsp@^2.2.2
; example:
; erropix/ESP32 AnalogWrite@^0.2

View File

@ -1,12 +1,109 @@
#include <Arduino.h>
#include "Program.h"
// #include <Arduino.h>
// #include "Program.h"
Program* program;
// Program* program;
// void setup() {
// program = new Program();
// }
// void loop() {
// program->loop();
// }
#include <Arduino.h>
#include <WiFiEsp.h>
const char ssid[] = "Clement4G"; // your network SSID (name)
const char pass[] = "Clement123"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
char server[] = "arduino.cc";
// Initialize the Ethernet client object
WiFiEspClient client;
void setup() {
program = new Program();
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial1.begin(115200);
// initialize ESP module
WiFi.init(&Serial1);
// 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 WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
Serial.println("You're connected to the network");
Serial.println();
Serial.println("Starting 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 /asciilogo.txt HTTP/1.1");
client.println("Host: arduino.cc");
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() {
program->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());
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// if the server's disconnected, stop the client
if (!client.connected()) {
Serial.println();
Serial.println("Disconnecting from server...");
client.stop();
// do nothing forevermore
while (true);
}
//delay(10000);
}