Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating two webservers in AT mode 3 ? #198

Open
DurenMateo opened this issue Jun 22, 2020 · 1 comment
Open

Creating two webservers in AT mode 3 ? #198

DurenMateo opened this issue Jun 22, 2020 · 1 comment

Comments

@DurenMateo
Copy link

DurenMateo commented Jun 22, 2020

I'm trying to set up a webpage with fixed IP-adress by using an Arduino Nano (master) and an ESP-01 (as a shield) in Station-, softAP- and combined mode. AT mode 3 = #44 .

The webpage in station mode as well as the webpage in softAP mode are working fine. But when I lounge my code in combined mode only the webpage on the softAP is reachable. I found my similar question solved for the ESP8266WiFi.h library, but it is too late for me to switching from library.
https://arduino.stackexchange.com/questions/67269/create-one-server-in-ap-mode-and-another-in-station-mode

Basically: I want to use two servers separated by the IP-adress and port. Is there a solution for in the WiFiEsp.h library?

My code for the webserver in softAP mode:

 #include <Arduino.h>
 #include <stddef.h>
 #include <WiFiEsp.h>
bool AP = HIGH;                                      //permanent aan of uit
char ssidAP[] = "MasterproefMateo";     // your AP network SSID (name)
char passAP[] = "*********";                   // your AP network password min 8 karakters
IPAddress IpAP(192, 168, 1, 12);           //Gewenst IP-adres van Acces Point

WiFiEspClient client;
WiFiEspServer server(80);
RingBuffer  buf(8);

void setup() {
  Serial1.begin(115200);    //Serial1 programmed as Serial and ESP-01 connected by hardware.serial
  WiFi.init(&Serial1);
  if (WiFi.status() == WL_NO_SHIELD) {
      Serial.println("WiFi shield not present");
      i = LOW;  }
  if(i && AP){
      statusAP = WiFi.beginAP(ssidAP, 11, passAP, ENC_TYPE_WPA2_PSK, true);
      WiFi.configAP(IpAP);
      IpAP = WiFi.APlocalIP();         //Modified version on .localIP() to force getIpAddressAP
  }
  if (statusAP == WL_CONNECTED){server.begin();}
}
void loop() {
  WriteServer();
}

void WriteServer() {
  WiFiEspClient client = server.available();  // listen for incoming clients
     if (client) {                                              // if you get a client,
        buf.init();                                            // initialize the circular buffer
        while (client.connected()) {               // loop while the client's connected
           if (client.available()) {                     // if there's bytes to read from the client,
               char c = client.read();                // read a byte, then
               buf.push(c);                              // push it to the ring buffer
               if (buf.endsWith("\r\n\r\n")) {
                   WebPage1(client);
                   break;
               }
              execute2();
           }
       }
       delay(1);
       client.stop();
   }
}

My code for the webserver in Station mode:
Same code but AP in names changed in WF and AP in commands ( .AP***) deleted.
(Works Fine)

What I would like to do and probably gonna need to write myself in te library:

#include <Arduino.h>
 #include <stddef.h>
 #include <WiFiEsp.h>

char ssidAP[] = "MasterproefMateo";     // your AP network SSID (name)
char passAP[] = "*********";                    // your AP network password min 8 karakters
IPAddress IpAP(192, 168, 1, 12);            //Gewenst IP-adres van Acces Point

char ssidWF[] = "MasterproefMateoWF";     // your AP network SSID (name)
char passWF[] = "*********";                        // your AP network password min 8 karakters
IPAddress IpAP(192, 168, 1, 21);                 //Gewenst IP-adres van station


WiFiEspClient client;
WiFiEspServer serverAP(80);
WiFiEspServer serverWF(81);
RingBuffer  buf(8);

void setup() {
  Serial1.begin(115200);    //Serial1 programmed as Serial and ESP-01 connected by hardware.serial
  WiFi.init(&Serial1);
  if (WiFi.status() == WL_NO_SHIELD) {
      Serial.println("WiFi shield not present");
      i = LOW;  }
  if(i){
      statusAP = WiFi.beginAP(ssidAP, 11, passAP, ENC_TYPE_WPA2_PSK, false);
      WiFi.configAP(IpAP);
      IpAP = WiFi.APlocalIP();         //Modified version on .localIP() to force getIpAddressAP

     statusWF = WiFi.begin(ssidWF, passWF, false); 
     WiFi.config(IpWF_setup);    
     IpWF = WiFi.localIP(); 
  }
 if (statusAP == WL_CONNECTED){serverAP = WiFiEspServer(WiFi.APlocalIP(), 80); serverAP.begin();}
 if (statusWF == WL_CONNECTED){serverWF = WiFiEspServer(WiFi.localIP(), 81); serverWF.begin();}
}
void loop() {
  WriteServer();
}

void WriteServer() {
  WiFiEspClient client = serverAP.available();  // QUESTIONABLE
     if (client) {                                        // if you get a client,
        buf.init();                                      // initialize the circular buffer
        while (client.connected()) {          // loop while the client's connected
           if (client.available()) {                // if there's bytes to read from the client,
               char c = client.read();           // read a byte, then
               buf.push(c);                          // push it to the ring buffer
               if (buf.endsWith("\r\n\r\n")) {
                   WebPage1(client);
                   break;
               }
              execute2();
           }
       }
       delay(1);
       client.stop();
   }
WiFiEspClient client = serverWF.available();  // QUESTIONABLE
     if (client) {                                           // if you get a client,
        buf.init();                                          // initialize the circular buffer
        while (client.connected()) {              // loop while the client's connected
           if (client.available()) {                    // if there's bytes to read from the client,
               char c = client.read();               // read a byte, then
               buf.push(c);                              // push it to the ring buffer
               if (buf.endsWith("\r\n\r\n")) {
                   WebPage1(client);
                   break;
               }
              execute2();
           }
       }
       delay(1);
       client.stop();
   }
}
@JAndrassy
Copy link

the AT firmeware can run only one server. this can listen on both interfaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants