[ESP8266] How to disable Gateway Wifi settings in runtime ?

Hi there,

I'm using the ESP8266-12 module working as standalone CPU, I mean, with the Arduino sketch running inside it; I have just designed a system on which this module acts either as local server, or as a client for remote servers, exclusivelly ( I mean, one task per time ).

THE PROBLEM IS:

When I compile the code with the following statements, the module is able to work as local server:

WiFi.begin  ( ssid , password )           ;
WiFi.config ( net , gateway , subnet ) ;

However, this works as client only if I compile again, now omitting the Gateway/Subnet settings:

WiFi.begin  ( ssid , password )           ; // omitting further gateway configuration

I'm using the following networking libraries:

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

I even thought about disconnecting and reconnecting the Wifi so that I could now configure it according to the target usage, but this solution seems a bit radical, since a priori network settings should be able to be configured in runtime ( at least this is possible in operating systems ).

So, the question which arose:

  • How to disable Gateway Wifi settings in runtime ?

See bellow an illustration of what I'm talking about:

At compile time, does the ESP know what role it will have? If not, when does it learn what that role will be?

@PaulS,

Thanks for the prompt reply, anyway I did not understand exactly what do you mean by role.

What I'm concerned is to work with the ESP8266 either dealing with local clients (as it is working at the current product), but I wish that some specific status will be available at a cloud server.

AFAIK, it is possible to work with this part either as client and server "at the same time", however the only issue that is impedding this to work is the gateway settings.

As mentioned above, depending on whether I run gateway configuration command or not, it either enable local communication or remote communication, exclusivelly, so I wanted ne able to disable/enable gateway during program execution

Please refer to the following picure which better depicts the system:

Maybe you can call WiFi.config() with suitable parameters to undo whatever was originally done?

...R

Problem solved !

It was just wrong Gateway settings.
Once configured the same IP of the Router, everything is working nicelly.

Thanks.