Wifi connection for esp32

Hi ,

I try to create an asynchronous server on Esp32 , however , the esp 32 dont output the IP address for me to access the server . I not sure why , Could you guy give me advise please ?


#include <string.h>
#include <Arduino.h>
#include "temperature.h"
#include "charge.h"
#include "current.h"
#include <Wire.h>
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include <AsyncTCP.h>
#include "SPIFFS.h"



// Replace with your network credentials
const char* ssid = "Tp_set";
const char* password = "12345678";

// Create AsyncWebServer object on port 80
AsyncWebServer server(80);

String temperature_text;
String percentage_text;

temperature bms;
charge  battery ;
current battery_2;


void setup() {
 
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");


  // Initialize SPIFFS
  if(!SPIFFS.begin()){
    Serial.println("An Error has occurred while mounting SPIFFS");
    return;
  }

  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }

  // Print ESP32 Local IP Address
  Serial.println(WiFi.localIP());

  // Route for root / web page
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(SPIFFS, "/index.html");
  });
  server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", temperature_text.c_str());
  });
  server.on("/percentage", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", percentage_text.c_str() );
  });


 
  server.begin();
  
  battery.begin();
  bms.begin();
  battery_2.begin(); 
}

void loop() {
  String temperature_text  = String(temperature_battery,3) ;
  String percentage_text  = String(percentage_value) ;
 
  bms.calculate_temperature();
  battery.pin_multiplexer();
  battery.check_voltage();
  battery.percentage(); 
  battery_2.check_current();
}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Here is some advice. I saw you did not use code tags and I did not even bother to look at the code. Use code tags.

THANK YOU , i will fix it

Sorry , my mistake and thank you . I had fix it .

1 Like

Did you happen to look at your access points log to see if the ESP32 is reaching the AP and why the AP is refusing a connection?

I have not look at it yet. How could I access point log to see the AP?

My access point comes with a manual that explains how to do the thing. I could post how to access the logs with my access point but I doubt we have the same access points.

You mean the manual coming with esp32 ? Oh no , I lost the manual.

Good luck.

Try the WiFiScan example.
Is your network listed ?

No it not appear on Wi-Fi scan. My IP is 0.0.0.0 when print out which very wierd.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.