I'm on an ESP32-DevKitC-VIE kit (WROVER-IE module). I configure the wifi as WIFI_AP_STA and spin up a webserver on port 80.
It connects to the local network fine and serves webpages over that, but when I connect to the device AP directly, the webserver doesn't respond (which is reasonable of course, as no other configuration has been done.)
I've seen a few threads where people are struggling with this (many on ESP8266) but I can't find any answers for my device/code. Looking at the APIs there doesn't seem to be any provision for specifying the interface to use.
Any ideas? Ideally I would have one webserver respond to both interfaces, but if I have to spin up a separate webserver I think that would be acceptable as well.
Should I be using a different library to achieve this?
Current code (summary):
#include <Arduino.h>
#include <WiFi.h>
#include "esp_wifi.h"
const char* wifi_network_ssid = "localssid";
const char* wifi_network_password = "password";
const char *soft_ap_ssid = "ap_netname";
const char *soft_ap_password = NULL; // NULL for no password
const int channel = 10; // WiFi Channel number between 1 and 13
const bool hide_SSID = false; // To disable SSID broadcast -> SSID will not appear in a basic WiFi scan
const int max_connection = 2; // Maximum simultaneous connected clients on the AP
WiFiServer espServer(80);
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
WiFi.mode(WIFI_AP_STA);
Serial.println("\n[*] Creating ESP32 AP");
WiFi.softAP(soft_ap_ssid, soft_ap_password, channel, hide_SSID, max_connection);
Serial.print("[+] AP Created with IP Gateway ");
Serial.println(WiFi.softAPIP());
IPAddress ip(192,168,3,23);
IPAddress gateway(192,168,3,1);
IPAddress subnet(255,255,255,0);
WiFi.config(ip, gateway, subnet);
WiFi.begin(wifi_network_ssid, wifi_network_password);
Serial.println("\n[*] Connecting to WiFi Network");
while(WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(100);
}
Serial.print("\n[+] Connected to the WiFi network with local IP : ");
Serial.println(WiFi.localIP());
Serial.println("Starting webserver");
espServer.begin();
Serial.println("Started webserver");
}
void loop()
{
WiFiClient client = espServer.available();
if (client) handleWebClient(client);
}