Post topics, source code that relate to the Arduino Platform

User avatar
By AlexPilk
#25874 I want to have one module as an access point and the second module as a station connected to the access point. The station should read the webpage on the access point's server.
Say my access point code is this:

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

const char *ssid = "ESPapnew";
const char *password = "thereisnospoon";
ESP8266WebServer server(80);

void handleRoot() {
  server.send(200, "text/html", "Hello, world!");
}

void setup() {
  delay(1000);
  WiFi.softAP(ssid, password);
  server.on("/", handleRoot);
  server.begin();
}

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


How should the code look like for the second module set up as the station for it to read that webpage and store "Hello world!" in a string variable for future use? I saw some examples with functions like wifi.send(), but I still have no idea how to implement it. It can also be set up like this: the server on the access point sends data to the server on the station when an event occurs (no matter what, a button is pressed, a url on the server is visited) and the station stores it in a variable. Thanks!
User avatar
By kolban
#25893 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
User avatar
By AlexPilk
#25945
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! Yes, it needs to have a server, it's another part of the project. What I want is ESP_AP sending data to ESP_STA when a button connected to ESP_AP is pressed. I checked out the wifi client sketch, but it looks like it works the other way around, the station sends the request. So is it possible to set up ESP_AP as a client sending the requests to ESP_STA? If not, maybe it's possible to set up ESP_AP as an access point and a station connected to the second module at the same time? Thanks!