Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // appuyer sur la touche BOOT avant l'upload (marquée 0 sur le layout)
- // testé OK sur "Lolin S2 mini v1.0.0 original wifi Iot ESP32 - s2fn4r2"
- #include <WiFi.h>
- #include <WiFiClient.h>
- #include <WebServer.h>
- #include <ESPmDNS.h>
- const char* ssid = "monwifi"; //vous le saurez pas
- const char* password = "monpw"; // ça non plus
- const char* static_ip = "192.168.0.7";
- int builtinLed = 15; // 15 sur Lolin S2 mini
- //code morse
- long int dureeTrait=500; //durée d'un trait morse
- long int dureePoint=200; //durée d'un point morse
- long int dureeStop=100; //durée entre 2 caractères
- WebServer server(80);
- const int led = 15; // 15 sur Lolin S2 mini
- void handleRoot() {
- digitalWrite(led, 1);
- server.send(200, "text/plain", "hello from esp32 s2 mini ! Emet SOS sur builtinLED");
- digitalWrite(led, 0);
- }
- void handleNotFound() {
- digitalWrite(led, 1);
- String message = "File Not Found\n\n";
- message += "URI: ";
- message += server.uri();
- message += "\nMethod: ";
- message += (server.method() == HTTP_GET) ? "GET" : "POST";
- message += "\nArguments: ";
- message += server.args();
- message += "\n";
- for (uint8_t i = 0; i < server.args(); i++) {
- message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
- }
- server.send(404, "text/plain", message);
- digitalWrite(led, 0);
- }
- void setup(void) {
- pinMode(builtinLed, OUTPUT);
- digitalWrite(led, 0);
- Serial.begin(115200);
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);// Connecte au réseau WiFi
- //WiFi.config(IPAddress(static_ip), IPAddress(0), IPAddress(0)); // Configure l'adresse IP statique
- WiFi.setAutoReconnect(true); // Active la reconnexion automatique
- Serial.println("");
- // Wait for connection
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.print("Connected to ");
- Serial.println(ssid);
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP());
- if (MDNS.begin("esp32")) {
- Serial.println("MDNS responder started");
- }
- server.on("/", handleRoot);
- server.on("/inline", []() {
- server.send(200, "text/plain", "this works as well");
- });
- server.onNotFound(handleNotFound);
- server.begin();
- Serial.println("HTTP server started");
- }
- void loop(void) {
- server.handleClient();
- delay(2);//allow the cpu to switch to other tasks
- // 3 traits
- digitalWrite(builtinLed, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(dureeTrait); // wait for a second
- digitalWrite(builtinLed, LOW); // turn the LED off by making the voltage LOW
- delay(dureeStop); // wait for a second
- digitalWrite(builtinLed, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(dureeTrait); // wait for a second
- digitalWrite(builtinLed, LOW); // turn the LED off by making the voltage LOW
- delay(dureeStop); // wait for a second
- digitalWrite(builtinLed, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(dureeTrait); // wait for a second
- digitalWrite(builtinLed, LOW); // turn the LED off by making the voltage LOW
- delay(dureeStop); // wait for a second
- delay(dureeStop); // wait for a second
- delay(dureeStop); // wait for a second
- // 3 points
- digitalWrite(builtinLed, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(dureePoint); // wait for a second
- digitalWrite(builtinLed, LOW); // turn the LED off by making the voltage LOW
- delay(dureeStop); // wait for a second
- digitalWrite(builtinLed, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(dureePoint); // wait for a second
- digitalWrite(builtinLed, LOW); // turn the LED off by making the voltage LOW
- delay(dureeStop); // wait for a second
- digitalWrite(builtinLed, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(dureePoint); // wait for a second
- digitalWrite(builtinLed, LOW); // turn the LED off by making the voltage LOW
- delay(dureeStop); // wait for a second
- delay(dureeStop); // wait for a second
- delay(dureeStop); // wait for a second
- // 3 traits
- digitalWrite(builtinLed, HIGH); // trait1
- delay(dureeTrait); // wait for a second
- digitalWrite(builtinLed, LOW); // turn the LED off by making the voltage LOW
- delay(dureeStop); // wait for a second
- digitalWrite(builtinLed, HIGH); // trait2
- delay(dureeTrait); // wait for a second
- digitalWrite(builtinLed, LOW); // turn the LED off by making the voltage LOW
- delay(dureeStop); // wait for a second
- digitalWrite(builtinLed, HIGH); // trait3
- delay(dureeTrait); // wait for a second
- digitalWrite(builtinLed, LOW); // turn the LED off by making the voltage LOW
- delay(dureeStop); // wait for a second
- delay(1000); // wait for a second
- }
Advertisement
Comments
-
- Se connecte au Wifi et émet S.O.S sur la LED interne
Add Comment
Please, Sign In to add comment
Advertisement