Tadejro

Wemos WIFI_AP_STA problem

Sep 19th, 2020
890
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ESP8266WiFi.h>
  2.  
  3. char SSID_NAME[] = "AP_SSID_NAME";
  4. char SSID_PASSWORD[] = "AP_SSID_PASSWORD";
  5.  
  6. const char *sta_ssid = "ROUTER_SSID_NAME";
  7. const char *sta_password = "ROUTER_SSID_PASSWORD";
  8.  
  9. WiFiServer server(80);
  10. IPAddress staticIP(192,168,1,20);
  11. IPAddress gateway(192,168,1,1);
  12. IPAddress subnet(255,255,255,0);
  13.  
  14. void setup() {
  15.     Serial.begin(115200);
  16.     WiFi.mode(WIFI_AP_STA);
  17.     Serial.println("");
  18.     Serial.print("Configuring access point...");
  19.  
  20.     int channel = 7;         // Channel : 1 - 13
  21.     bool hidden=true;       // true / false
  22.     int max_connection = 5;  // 0 - 8
  23.  
  24.     WiFi.softAP(SSID_NAME, SSID_PASSWORD, channel, hidden, max_connection);
  25.     WiFi.softAPConfig(staticIP, gateway, subnet);
  26.  
  27.     Serial.println();
  28.     Serial.print("Connecting to ");
  29.     Serial.println(sta_ssid);
  30.     WiFi.begin(sta_ssid, sta_password);
  31.  
  32.     while (WiFi.status() != WL_CONNECTED)
  33.     {
  34.         delay(500);
  35.         Serial.print(".");
  36.     }
  37.  
  38.     Serial.println("");
  39.     Serial.println("WiFi connected");
  40.     Serial.println("IP address: ");
  41.     Serial.println(WiFi.localIP());
  42.  
  43.     server.begin();
  44.  
  45.     Serial.println();
  46.     Serial.println("Server");
  47.     Serial.print("IP: ");      Serial.println(WiFi.softAPIP());
  48.     Serial.printf("MAC:%s\n",  WiFi.softAPmacAddress().c_str());
  49.     Serial.print("Status: ");  Serial.println(WiFi.status());    // Network parameters
  50.     Serial.print("IP: ");      Serial.println(WiFi.localIP());
  51.     Serial.print("Subnet: ");  Serial.println(WiFi.subnetMask());
  52.     Serial.print("Gateway: "); Serial.println(WiFi.gatewayIP());
  53.     Serial.print("SSID: ");    Serial.println(WiFi.SSID());
  54.     Serial.print("Signal: ");  Serial.println(WiFi.RSSI());
  55. }
  56.  
  57. void loop()
  58. {
  59.     WiFiClient client = server.available();
  60.     if (!client) {return;}
  61.  
  62.     String request = client.readStringUntil('\r');
  63.     Serial.println("Answer from the station: " + request);
  64.  
  65.     client.flush();
  66. }
  67.  
RAW Paste Data