|     Inicio    |   |         |  |   FOROS      |  |      |      
   Elastix - VoIP B4A (Basic4Android) App inventor 2 PHP - MySQL
  Estación meteorológica B4J (Basic4Java) ADB Shell - Android Arduino
  Raspberry Pi Visual Basic Script (VBS) FireBase (BD autoactualizable) NodeMCU como Arduino
  AutoIt (Programación) Visual Basic Cosas de Windows Webs interesantes
Translate:
Búsqueda en este sitio:


.

Tutorial del Internet de las Cosas y Bluetooth con el ESP32
Juan Antonio Villalpando

Volver al índice del tutorial

____________________________

122B.- Wemos D1 R32 ESP32. Punto de Acceso y Estación de un Router. Repetidor.

- En este ejemplo se intenta realizar un Repetidor, pero no llega a funcionar.

- Configuramos el ESP32 como estación del Router con IP = 192.168.1.123

- Además el ESP32 lo vamos a configurar como Punto de Acceso, es decir, creará un red de tipo 192.168.4.X (Puerta de enlace 192.168.4.1. IP 192.168.4.2)

- El código está obtenido de:

https://gist.github.com/port3r/3a768df1a7d99b6e37ebe9e0389bd980

- Logra hacer las conexiones pero no conecta con internet.

punto_acceso_estacion.ino

// Juan A. Villalpando.
// KIO4.COM

 
#define IP_FORWARD 1

#include <WiFi.h>
#include <WiFiUDP.h>

// Set these to your desired credentials for ESP32 AP. */
const char *ssid = "Repetidor";
const char *password = "12345678";
IPAddress apIP(192,168,4,1);
IPAddress apdns(8,8,8,8);

// Setup credentials for original WiFi, that we plan to repeat
const char* ssidExt = "Mi_Red_WiFi";
const char* passwordExt = "La_clave_de_mi_Red_Wifi";

const byte DNS_PORT = 53;

// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
byte packetBuffer[512]; //buffer to hold incoming and outgoing packets

WiFiUDP Udp8;

// Update these with values suitable for your network.
IPAddress ip(192, 168, 1, 123); // Establecemos una IP estatica.
IPAddress gateway(192, 168, 1, 1); // IP de nuestro Router.
IPAddress subnet(255, 255, 255, 0);
IPAddress dns(8,8,8,8);

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

   WiFi.mode(WIFI_AP_STA);
   //WiFi.mode(WIFI_AP);

  Serial.println("Conexion con nuestro Router.");
  WiFi.begin(ssidExt, passwordExt);
  WiFi.config(ip,gateway,subnet,dns);

  //Wifi connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssidExt);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.print("dnsIP address: ");
  Serial.println(WiFi.dnsIP());
  Serial.print("gatewayIP address: ");
  Serial.println(WiFi.gatewayIP());
  Serial.print("subnetMask address: ");
  Serial.println(WiFi.subnetMask());


  Serial.println("");
  Serial.println("Configuring access point...");
  /* You can remove the password parameter if you want the AP to be open. */
  WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
  // WiFi.config(ip, dns, gateway, subnet);
  // WiFi.softAP(ssid, password);
  //WiFi.softAPConfig(IPAddress(192,168,1,123), IPAddress(192,168,4,1),IPAddress(255,255,255,0));
  WiFi.softAP(ssid, password);

 // dnsServer.start (DNS_PORT, " * " , apIP);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);

  Udp.begin(DNS_PORT);
  Udp8.begin(DNS_PORT);
}

void loop()
{

  int noBytes = Udp.parsePacket();
  if ( noBytes ) {
    //    Serial.print(millis() / 1000);
    //    Serial.print(":Packet of ");
    //    Serial.print(noBytes);
    //    Serial.print(" received from ");
    //    Serial.print(Udp.remoteIP());
    //    Serial.print(":");
    //    Serial.println(Udp.remotePort());
    // We've received a packet, read the data from it
    Udp.read(packetBuffer, noBytes); // read the packet into the buffer

    // display the packet contents in HEX
    //    for (int i = 1; i <= noBytes; i++) {
    //      Serial.print(packetBuffer[i - 1], HEX);
    //      if (i % 32 == 0) {
    //        Serial.println();
    //      }
    //      else Serial.print(' ');
    //    } // end for
    //    Serial.println();

    IPAddress ip8(8, 8, 8, 8);
    Udp8.beginPacket(ip8, DNS_PORT); //NTP requests are to port 123
    Udp8.write(packetBuffer, noBytes);
    Udp8.endPacket();
    delay(100);

    int cb = Udp8.parsePacket();
    if (!cb) {
     // Serial.println("no packet yet");
    }
    else {
      //      Serial.print("packet received, length=");
      //      Serial.println(cb);
      byte packetBuffer8[cb];
      Udp8.read(packetBuffer8, cb);
      Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
      Udp.write(packetBuffer8, cb);
      Udp.endPacket();
    }

  } // end if
}


- Cambiando el firmware

https://github.com/martin-ger/esp32_nat_router

_______________________________

- Mi correo:
juana1991@yahoo.com
- KIO4.COM - Política de cookies. Textos e imágenes propiedad del autor:
© Juan A. Villalpando
No se permite la copia de información ni imágenes.
Usamos cookies propias y de terceros que entre otras cosas recogen datos sobre sus hábitos de navegación y realizan análisis de uso de nuestro sitio.
Si continúa navegando consideramos que acepta su uso. Acepto    Más información