-->
Page 1 of 3

[SOLVED] ESP8266 as Time-Multiplexed Server / Client

PostPosted: Sun Sep 17, 2017 3:48 am
by andre_teprom
Hello guys,
   
   
   
I'm aware that this subject was already widely discussed here on this forum, but I was not able to find any working template. So, to make things simpler, I thought about using the libraries already available and instead of concurrently accessing both features (Client / Server), I was just trying to allocate each one at a specific time, but it is not working .

The fact is that when I experiment with client or server functionality separately, it works well, but when I put it all together, it does not.

Here's a snippet of code:

Code: Select all#include <ThingSpeak.h>            // Client library
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>       // Server library

....stuffs

WiFiClient  client;


setup()
   {
   ....stuffs
   ESP8266WebServer server(80);
   server.begin();
   
   ThingSpeak.begin(client);
   ....stuffs   
   }
   
   
loop()
   {
   
   if ( ELAPSED_LONG_TIME )
      {
      ....stuffs      
      server.stop();
   
      ThingSpeak.begin(client);
      Serial.println  ( String( ThingSpeak.readIntField( testChannelNumber , 1, testChannelReadAPIKey ) ) )    ; // read last value stored in cloud
      
      server.begin();
      ....stuffs            
      }
   }   


The concept behind of what I wish:

ARQUITETURA.png


Anyone could give some insigh on how to deal with that ?

Re: ESP8266 as Time-Multiplexed Server / Client

PostPosted: Mon Sep 18, 2017 1:45 am
by gdsports
I do not think you need to stop the server to use the client. Combine this HTTP server example with this HTTP client example.

How can I disable Gateway runtime ?

PostPosted: Mon Sep 18, 2017 4:21 am
by andre_teprom
Hi there, I'm almost there !
After rewriting the code by using common libraries, I finally was able to run either client and server instancies at the same code, HOWEVER there is a little problem.

When I made tests with the part of the code which enable aceess to local clients, it works only if at the Wifi connecting stage I do this:
Code: Select all  WiFi.begin  ( ssid , password )           ;
  WiFi.config ( net , gateway , subnet )    ;

But in order to grant access to remote server ( I mean, board acting as client ), I need to re-compile the code, but now ommiting the gateway/subnet configuration:
Code: Select all  WiFi.begin  ( ssid , password )  // ommiting further gateway/subnet configuration        ;

That´s what I'm meaning:
ARQUITETURA.png

The new arosed question is:

    How can I disable Gateway runtime ?

Re: ESP8266 as Time-Multiplexed Server / Client

PostPosted: Mon Sep 18, 2017 8:07 am
by rudy
I have read your posts here a number of time. I either misunderstand what you are trying to do or you misunderstand how things can work. Maybe both.

As the other poster had said, you can have your application run a server and a client at the same time.

And here is the part that I really don't understand.

Code: Select all  WiFi.begin  ( ssid , password )           ;
  WiFi.config ( net , gateway , subnet )    ;


Why are you trying to change your connection to the router? Are you using a second router that you have omitted in your pictures? Otherwise it doesn't make any sense to me. You have one router that the ESPs connect to in order to gain access to the internet and then you have a second router, with a different SSID/password, that you use to provide local access to the local user.