-->
Page 1 of 9

P2P: ESP in AP mode and ESP in STA mode not working

PostPosted: Fri Jul 17, 2015 2:33 pm
by Demos Anastasakis
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);
  }
}

Re: P2P: ESP in AP mode and ESP in STA mode not working

PostPosted: Fri Jul 17, 2015 4:40 pm
by martinayotte
Look like the same problem as described in this thread :

viewtopic.php?f=29&t=4006

It is a clash between subnet 192.168.4.x.
So, maybe you should simply do the WiFi.mode(WIFI_STA); AFTER the WiFi.begin(ssid, password);

Re: P2P: ESP in AP mode and ESP in STA mode not working

PostPosted: Sat Jul 18, 2015 10:33 am
by Demos Anastasakis
Thanks,
I read the post you mention and tried what you suggested but it didn't help...

Re: P2P: ESP in AP mode and ESP in STA mode not working

PostPosted: Sat Jul 18, 2015 11:54 am
by martinayotte
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.