Difference between revisions of "Bibliothèque Wi-Fi ESP32"

From
Jump to: navigation, search
(Created page with " ESP32")
 
(ESP32)
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
==== ESP32 ====
  
ESP32
+
https://www.raspberryme.com/fonctions-utiles-de-la-bibliotheque-wi-fi-esp32-arduino-ide/
 +
 
 +
==== ESP32 exemple 1 ====
 +
<b>WiFiScan</b> Analyser les réseaux Wi-Fi<br>
 +
<b>exemple 1</b>&#x2705;<br>
 +
 
 +
[[File:Grove Base for XIAO 1.PNG|200px]]
 +
[[File:XIAO-ESP32S3 1.PNG|125px]]
 +
 
 +
Grove Base for XIAO<br>
 +
XIAO-ESP32S3<br>
 +
 
 +
<PRE>
 +
/*
 +
  Example from WiFi > WiFiScan
 +
  Complete details at https://RandomNerdTutorials.com/esp32-useful-wi-fi-functions-arduino/
 +
*/
 +
 
 +
#include "WiFi.h"
 +
 
 +
void setup() {
 +
  Serial.begin(115200);
 +
 
 +
  // Set WiFi to station mode and disconnect from an AP if it was previously connected
 +
  WiFi.mode(WIFI_STA);
 +
  WiFi.disconnect();
 +
  delay(100);
 +
 
 +
  Serial.println("Setup done");
 +
}
 +
 
 +
void loop() {
 +
  Serial.println("scan start");
 +
 
 +
  // WiFi.scanNetworks will return the number of networks found
 +
  int n = WiFi.scanNetworks();
 +
  Serial.println("scan done");
 +
  if (n == 0) {
 +
      Serial.println("no networks found");
 +
  } else {
 +
    Serial.print(n);
 +
    Serial.println(" networks found");
 +
    for (int i = 0; i < n; ++i) {
 +
      // Print SSID and RSSI for each network found
 +
      Serial.print(i + 1);
 +
      Serial.print(": ");
 +
      Serial.print(WiFi.SSID(i));
 +
      Serial.print(" (");
 +
      Serial.print(WiFi.RSSI(i));
 +
      Serial.print(")");
 +
      Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
 +
      delay(10);
 +
    }
 +
  }
 +
  Serial.println("");
 +
 
 +
  // Wait a bit before scanning again
 +
  delay(5000);
 +
}
 +
</PRE>
 +
 
 +
==== ESP32 exemple 2 ====
 +
<b>exemple 2</b>&#x2705;<br>
 +
 
 +
[[File:Grove Base for XIAO 1.PNG|200px]]
 +
[[File:XIAO-ESP32S3 1.PNG|125px]]
 +
 
 +
Grove Base for XIAO<br>
 +
XIAO-ESP32S3<br>
 +
 
 +
<PRE>
 +
/*
 +
  Complete details at https://RandomNerdTutorials.com/esp32-useful-wi-fi-functions-arduino/
 +
*/
 +
 
 +
#include <WiFi.h>
 +
 
 +
// Replace with your network credentials (STATION)
 +
const char* ssid = "REPLACE_WITH_YOUR_SSID";
 +
const char* password = "REPLACE_WITH_YOUR_PASSWORD";
 +
 
 +
void initWiFi() {
 +
  WiFi.mode(WIFI_STA);
 +
  WiFi.begin(ssid, password);
 +
  Serial.print("Connecting to WiFi ..");
 +
  while (WiFi.status() != WL_CONNECTED) {
 +
    Serial.print('.');
 +
    delay(1000);
 +
  }
 +
  Serial.println(WiFi.localIP());
 +
}
 +
 
 +
void setup() {
 +
  Serial.begin(115200);
 +
  initWiFi();
 +
  Serial.print("RRSI: ");
 +
  Serial.println(WiFi.RSSI());
 +
}
 +
 
 +
void loop() {
 +
  // put your main code here, to run repeatedly:
 +
}
 +
</PRE>
 +
 
 +
==== ESP32 exemple 3 ====
 +
<b>exemple 3</b>&#x2705;<br>
 +
 
 +
[[File:Grove Base for XIAO 1.PNG|200px]]
 +
[[File:XIAO-ESP32S3 1.PNG|125px]]
 +
 
 +
Grove Base for XIAO<br>
 +
XIAO-ESP32S3<br>
 +
 
 +
<PRE>
 +
/*
 +
  Rui Santos & Sara Santos - Random Nerd Tutorials
 +
  Complete project details at https://RandomNerdTutorials.com/esp32-set-custom-hostname-arduino/
 +
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files. 
 +
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 +
*/
 +
#include <WiFi.h>
 +
 
 +
// Replace with your network credentials
 +
const char* ssid = "REPLACE_WITH_YOUR_SSID";
 +
const char* password = "REPLACE_WITH_YOUR_PASSWORD";
 +
// Change the hostname
 +
const char* hostname = "esp32-node-temperature";
 +
 
 +
void initWiFi() {
 +
  WiFi.mode(WIFI_STA);
 +
  WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
 +
  WiFi.setHostname(hostname);
 +
 
 +
  WiFi.begin(ssid, password);
 +
  Serial.print("Connecting to WiFi...");
 +
  while (WiFi.status() != WL_CONNECTED) {
 +
    Serial.print('.');
 +
    delay(1000);
 +
  }
 +
 
 +
  Serial.print("\nESP32 IP Address: ");
 +
  Serial.println(WiFi.localIP());
 +
  Serial.print("ESP32 HostName: ");
 +
  Serial.println(WiFi.getHostname());
 +
  Serial.print("RRSI: ");
 +
  Serial.println(WiFi.RSSI());
 +
}
 +
 
 +
void setup() {
 +
  Serial.begin(115200);
 +
  initWiFi();
 +
}
 +
 
 +
void loop() {
 +
  // put your main code here, to run repeatedly:
 +
}
 +
</PRE>

Latest revision as of 19:36, 14 September 2025

ESP32[edit]

https://www.raspberryme.com/fonctions-utiles-de-la-bibliotheque-wi-fi-esp32-arduino-ide/

ESP32 exemple 1[edit]

WiFiScan Analyser les réseaux Wi-Fi
exemple 1

Grove Base for XIAO 1.PNG XIAO-ESP32S3 1.PNG

Grove Base for XIAO
XIAO-ESP32S3

/*
  Example from WiFi > WiFiScan
  Complete details at https://RandomNerdTutorials.com/esp32-useful-wi-fi-functions-arduino/
*/

#include "WiFi.h"

void setup() {
  Serial.begin(115200);

  // Set WiFi to station mode and disconnect from an AP if it was previously connected
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

  Serial.println("Setup done");
}

void loop() {
  Serial.println("scan start");

  // WiFi.scanNetworks will return the number of networks found
  int n = WiFi.scanNetworks();
  Serial.println("scan done");
  if (n == 0) {
      Serial.println("no networks found");
  } else {
    Serial.print(n);
    Serial.println(" networks found");
    for (int i = 0; i < n; ++i) {
      // Print SSID and RSSI for each network found
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(WiFi.SSID(i));
      Serial.print(" (");
      Serial.print(WiFi.RSSI(i));
      Serial.print(")");
      Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
      delay(10);
    }
  }
  Serial.println("");

  // Wait a bit before scanning again
  delay(5000);
}

ESP32 exemple 2[edit]

exemple 2

Grove Base for XIAO 1.PNG XIAO-ESP32S3 1.PNG

Grove Base for XIAO
XIAO-ESP32S3

/*
  Complete details at https://RandomNerdTutorials.com/esp32-useful-wi-fi-functions-arduino/
*/

#include <WiFi.h>

// Replace with your network credentials (STATION)
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

void initWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi ..");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(1000);
  }
  Serial.println(WiFi.localIP());
}

void setup() {
  Serial.begin(115200);
  initWiFi();
  Serial.print("RRSI: ");
  Serial.println(WiFi.RSSI());
}

void loop() {
  // put your main code here, to run repeatedly:
}

ESP32 exemple 3[edit]

exemple 3

Grove Base for XIAO 1.PNG XIAO-ESP32S3 1.PNG

Grove Base for XIAO
XIAO-ESP32S3

/*
  Rui Santos & Sara Santos - Random Nerd Tutorials
  Complete project details at https://RandomNerdTutorials.com/esp32-set-custom-hostname-arduino/
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.  
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/
#include <WiFi.h>

// Replace with your network credentials
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";
// Change the hostname
const char* hostname = "esp32-node-temperature";

void initWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
  WiFi.setHostname(hostname);

  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi...");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(1000);
  }
  
  Serial.print("\nESP32 IP Address: ");
  Serial.println(WiFi.localIP());
  Serial.print("ESP32 HostName: ");
  Serial.println(WiFi.getHostname());
  Serial.print("RRSI: ");
  Serial.println(WiFi.RSSI());
}

void setup() {
  Serial.begin(115200);
  initWiFi();
}

void loop() {
  // put your main code here, to run repeatedly:
}