1

I'm developing a application that needs to be somewhat secure, so to configure the parameters it handles a GPIO interrupt (from a button) to open a server, that lets you configure it. The problem is that it is configured to send an email, so it is connected to the wifi.

With this in mind, I need to detect the source of the connection so I can serve the html only to the access point connections.

Is it possible?

  • I think what you want is that it's only accessible on the local network, and not from the internet, right? – Gerben Jun 4 at 13:32
  • Not only the local, no. I don't really know the exact terms, but I create a WiFi with my ESP and I want only people accessing from this exclusive WiFi to be able to change the configuration. Someone in the internet or accessing the same WiFi my esp is connected to gets rejected. – Luiz Felipe Jun 4 at 13:35
  • When the flag from the interrupt is 1, it puts the WebServer in STA_AP mode, I want it only be accessible via the AP side of the WebServer. I don't know if this clarifies. – Luiz Felipe Jun 4 at 13:37
  • 1
    So it's set to both be a client on the Wifi that's connected to the internet, and be an Accesspoint at the same time. Now it makes sense. (I didn't even know the ESP could do that.) I think you can filter based on IP address. – Gerben Jun 4 at 13:44
  • Maybe this is a good solution that I simply overlooked. I'll take a look. – Luiz Felipe Jun 4 at 13:47
0

It is not documented, but you can construct WiFiServer or ESP8266WebServer with IP address. If you use the IP address of the AP, the server will be available only on the SoftAP. If you use the IP address of the station, the server will be available only on STA interface.

#include <ESP8266WiFi.h>

WiFiServer telneServer(23);

void setup() {
  ...
  telneServer = WiFiServer(WiFi.softAPIP(), 23);
//  telneServer = WiFiServer(WiFi.localIP(), 23);
  telneServer.begin();
  • 1
    Thanks! I had already solved with the comment from above, but your answer seemed a lot more elegant, so I tried and it works just fine! I just used had to declare the server with the IP and configure the softAP to be the same using: ESP8266WebServer server(local_ip,80) and WiFi.softAPConfig(local_ip, local_ip, IPAddress(255, 255, 255, 0)) . – Luiz Felipe Jun 4 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.