-->
Page 1 of 4

Send data from one module (AP) to another (station connected

PostPosted: Thu Aug 13, 2015 3:46 am
by AlexPilk
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!

Re: Send data from one module (AP) to another (station conne

PostPosted: Thu Aug 13, 2015 8:33 am
by martinayotte
Simply use the example under libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino and change the connect to point to your AP.

Re: Send data from one module (AP) to another (station conne

PostPosted: Thu Aug 13, 2015 8:43 am
by kolban
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

Re: Send data from one module (AP) to another (station conne

PostPosted: Fri Aug 14, 2015 3:48 am
by AlexPilk
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!