espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.32k stars 7.36k forks source link

Problem in routing on ESP's Board #5201

Closed Mohammadreza-Sorouriyan closed 3 years ago

Mohammadreza-Sorouriyan commented 3 years ago

Hi, I'm working on a project where I need to set an esp32 as an access point, and some esp8266-01 as a client.

Then i running a web server on each of the esp822 chips to get the sensor data in json format. Now I have done this, when I connect to this network with my mobile and enter the IP of one of the esp8266s, i get response but with two special esp8266.

And other esp8266's there's get ip from access point but the web server doesn't send any response and timed out. I even tried 7 type esp8266 models but it didn't work, but when I replace the access point with the home modem instead of esp32. All of esp8266 works perfectly!!

I think the esp32 can't handle and route the IP's. But here is a contradiction, why those two models of esp8266 working perfectly amd other no??

This is access point Code for ESP32



const char* ssid     = "esprouter";
const char* password = "9167997734";

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

  Serial.print("Setting AP (Access Point)…");
  WiFi.softAP(ssid, password);
}

void loop(){

}```

**And this Client code for ESP8266's**

```#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <DHT.h>
#include <WiFiUdp.h>

#define DHTPin 2 
#define DHTTYPE DHT11 
DHT dht(DHTPin, DHTTYPE);                

const char* ssid = "esprouter";  
const char* password = "9167997734"; 

ESP8266WebServer server(80);

void handle_OnConnect();
void handle_OnConnect2();
void handle_NotFound();

float Temperature;
float Humidity;

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

  Serial.println("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
  delay(1000);
  Serial.print(".");
  } 
  Serial.println("");
  Serial.println("Connected to WiFi");
  Serial.print("IP: ");  Serial.println(WiFi.localIP());

  server.on("/info", handle_OnConnect);
  server.on("/get", handle_OnConnect2);

  server.onNotFound(handle_NotFound);
  server.begin();
  dht.begin();
}
void loop() {

  server.handleClient();

}

void handle_OnConnect() {
  DynamicJsonDocument doc(1024);
    doc["type"] = "dht-sensor" ;
    doc["id"]   = 128;
    doc["ip"]   =  WiFi.localIP().toString();
    String response;
    serializeJson(doc, response);
    server.send(200, "content/json", response);
}

void handle_OnConnect2() {

  Temperature = dht.readTemperature(); 
  Humidity = dht.readHumidity(); 
  DynamicJsonDocument doc(1024);
    doc["temp"] = Temperature;
    doc["hum"]   = Humidity;
    String response;
    serializeJson(doc, response);
  server.send(200, "content/json", response);

}

void handle_NotFound(){
  server.send(404, "text/plain", "Not found");
}```

Thanks if anyone can guide me... 
TheRealDJ commented 3 years ago

SoftAP has a limit of 4 connections ... Is it possible that 4 devices were already connected?

FYI ... for code sections to look like this ...

code
code
code

Use the following syntax:

```
code
code
code
```
Mohammadreza-Sorouriyan commented 3 years ago

SoftAP has a limit of 4 connections ... Is it possible that 4 devices were already connected?

FYI ... for code sections to look like this ...

code
code
code

Use the following syntax:

code code code

No. The devices connected to the AP are less than 4.

TheRealDJ commented 3 years ago

Are you cleanly disconnecting from WiFi on the client side? I did some testing ... If I connect my phone to the WiFi SoftAP, then walk away from the ESP32, it seems to take some time (about 5 minutes if I remember correctly) for the ESP32 to indicate the client count back down to zero.

If I connect my to a different WiFi network or shut off WiFi, the ESP32 indicates a zero client count right away.

stale[bot] commented 3 years ago

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 3 years ago

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.