Post topics, source code that relate to the Arduino Platform

User avatar
By AlexPilk
#25979
martinayotte wrote:
AlexPilk wrote:Any ideas why ESP_STA fails to connect to ESP_AP, but works well with a separate router?


I've done some tests more than a month ago, because someone had such problem too. I've written simple MyAPServer and MyAPClient sketch, and it was working without any problem. So, in your case, you need to troubleshoot why your STA isn't able to connect to AP. Are your sure that your STA is really in STA only and not in AP+STA mode ? Because in such case, there will be routing problems where packets of your STA will be routed to itself if you have another AP on it.


Turned off the AP module and tested the STA alone, didn't see any suspicious SSIDs from my phone. I added "WiFi.mode(WIFI_STA)" before "WiFi.begin()". It however prints the IP address after connecting, so it is does connect in the beginning, but you can't ping or access it (AP ip is 192.168.4.1, STA gets 192.168.4.2)
User avatar
By AlexPilk
#26351 Just wanted to let you know that I found what was causing the issue. When I connected to the AP from the phone or the PC to try to get onto the STA's server or simply ping it - the new device on the network was breaking the connection between AP and STA. To test it I made the AP to send GET requests to the STA twice a second and the station was instructed to blink a led when the server was accessed. It worked :)
User avatar
By TimK
#71798
kolban wrote:Howdy Alex,
Assume ESP_AP is the ESP being used as an access point.
Assume ESP_STA is the ESP being used as a station connected to ESP_AP.

I hear you say that you are running a WebServer on ESP_AP and that ESP_STA wants to get data from ESP_AP. Are you sure you need to run a WebServer on ESP_AP? ESP_STA can make a TCP request directly to ESP_AP to request data without going anywhere near WebServer technology. I just want to make sure you aren't going through the WebServer story because you aren't aware of that? Perhaps if you describe the overall story that might assist?

Neil


Hi, I am currently looking into designing a system that requires sending data in between multiple ESP8266's. However I do not need to design a webserver for this as I would simply need raw data. How would I go about doing this? Thanks.
User avatar
By thoicb12
#78636
AlexPilk wrote:I've set up an access point (ESP_AP) and tried connecting to it from another module (ESP_STA). It prints an IP address, but you can't ping it or access it from a browser. However if you connect it to a router it works well, gets an ip and you can access the server, works well even with requesting a static ip. Here's the ESP_AP code:

Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

ESP8266WebServer server(80);
boolean trigger = 1;
const char* host = "192.168.4.5";
String requested_data = "None";

void handleRoot() {
  server.send(200, "text/html", "<h1>Requested data from ESP_AP: </h1>" + requested_data);
}

void setup() {
  delay(1000);
  pinMode(2, INPUT);
  WiFi.softAP("ESPap", "thereisnospoon");
  server.on("/", handleRoot);
  server.begin();
}

void send_request() {
  WiFiClient client;
  if (!client.connect(host, 80)) {
    return;
  }
  String url = "/station_test/";
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  delay(10);

  while (client.available()) {
    requested_data = client.readStringUntil('\r');
  }
}

void loop() {
  server.handleClient();
  if (digitalRead(2) != HIGH and trigger == 1) {
    send_request();
    trigger = 0;
  } else {
    trigger = 1;
  }
}


And here's the ESP_STA code:

Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

ESP8266WebServer server(80);
int request_number = 0;

void handleRoot(){
  server.send(200, "text/html", "<h1>Number of requests: </h1>"+String(request_number));
}
void handleRequestData(){
  server.send(200, "text/html", "<h2>I'm the requested data :)</h2>");
  request_number+=1;
}

void setup() {
  Serial.begin(115200);
  delay(10);
  WiFi.begin("ESPap", "thereisnospoon");
  //WiFi.config(IPAddress(192,168,4,5), IPAddress(192,168,4,1), IPAddress(255,255,255,0));
  pinMode(2,OUTPUT);
  digitalWrite(2,LOW);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
  Serial.println("");
  Serial.println("WiFi connected"); 
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  server.on("/", handleRoot);
  server.on("/station_test/", handleRequestData);
  server.begin();
  digitalWrite(2,HIGH);
}

void loop() {
  server.handleClient();
}


For now I'm trying to figure out how to connect the station to the access point, so I haven't yet tested the "request" code.


Can you please give me your edited code.
Sorry my English is not very good