Chat here is you are connecting ESP-xx type modules to existing AVR based Arduino

Moderator: igrr

User avatar
By Demos Anastasakis
#23519 Hello,
I have two ESPs. One is setup in AP mode the other in STA mode.
The problem I have is that the STA will not connect to the network that the AP sets up.
The STA will connect within 1 sec to my Home Wifi.
And I can connect to the AP with my phone/laptop.

Here's the code:

Server side

Code: Select all#include <ESP8266WiFi.h>
#define LED_PIN            5

const char *ssid      = "ESPap";
const char *passwd    = "1234567890";

void setup()
{
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);
 
  SetupWiFi();
 
  digitalWrite(LED_PIN, LOW);
}

void loop()
{
}

void SetupWiFi()
{
  WiFi.mode(WIFI_AP);
  WiFi.softAP(ssid, passwd);
}


Client side
Code: Select all#include <ESP8266WiFi.h>
#define LED_PIN            5

const char *ssid      = "ESPap";
const char *passwd    = "1234567890";
byte LedState;

void setup()
{
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);
 
  ConnectWiFi();
 
  digitalWrite(LED_PIN, LOW);
}

void loop()
{
}

void ConnectWiFi()
{
  LedState = HIGH;

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, passwd);

  while (WiFi.status() != WL_CONNECTED) {
    LedState = (LedState == HIGH) ? LOW : HIGH;
    digitalWrite(LED_PIN, LedState);
    delay(100);
  }
}
User avatar
By martinayotte
#23577 I've decided to give a try myself ! ;)
I've took the esp8266/libraries/ESP8266WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino for the APServer and I took the esp8266/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino for it client.
Not much other changes except adding a LED on the APServer and HTTP handling callbacks to switch the blinking rate of the LED, the main web page provides links for Fast/Slow rates.
Then in the APClient, it is sending HTTP Request to the APServer, alternating between Fast and Slow URLs.
It works flawlessly, I didn't even faced the famous subnet clash. :)
Here are the sketches in attachment, so it can be a good staring point for your project.
You do not have the required permissions to view the files attached to this post.