I've tried the client device configured in both WIFI_STA and WIFI_AP_STA.
I am using IPAddress host(192,168,4,1) on the client.
Has anyone done this?
Thanks!
Explore... Chat... Share...
Moderator: igrr
#include <ESP8266WiFi.h>
const char *ssid = "ESPap";
WiFiServer server(80);
void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.print("Configuring access point...");
WiFi.softAP(ssid);
while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }
Serial.println("done");
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
}
#include <ESP8266WiFi.h>
const char* ssid = "ESPap";
IPAddress host(192,168,4,1);
void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop() {
delay(5000);
++value;
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
client.print(String("GET /test/page.html HTTP/1.1\r\n") +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(10);
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
}
global variables ...
MDNSResponder mdns;
WiFiServer server(80);
void startAP()
{
WiFi.disconnect();
delay(100);
WiFi.mode(WIFI_STA);
WiFi.softAP(ssid,mypass);
delay(500);
Serial.print("Local server only @ ");
Serial.println(WiFi.localIP());
server.begin();
Serial.println("Server started");
}
and in a function called by the loop code
mdns.update(); // Check for any mDNS queries and send responses
WiFiClient client = server.available(); // Check if a client has connected
if (!client) {
return (NOCLIENT);
}
Serial.println("");
Serial.println("New client");
// Wait for data from client to become available
while (client.connected() && !client.available()) {
delay(1);
}
// Read the first line of HTTP request
String req = client.readStringUntil('\r');
globals ..
MDNSResponder mdns;
WiFiServer server(80);
void startSTA()
{
WiFi.disconnect();
delay(100);
WiFi.mode(WIFI_STA);
WiFi.begin("THE_SERVER", "thisIsAPassword");
while ( WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println(WiFi.status());
}
Serial.println("WIFI connected");
Serial.println(WiFi.softAPIP()); // get interface IP address mask
}
and the request function...
void set_position (int position)
{
WiFiClient client;
const char* host = "192.168.4.1";
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
String url = "/";
url += "?pos=";
url += String(position);
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
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()) {
String line = client.readStringUntil('\r');
// String line = client.readStringUntil("</html>");
Serial.println(line);
int addr_start = line.indexOf("value=\"");
int addr_end = line.indexOf('\"', addr_start + 7);
if (addr_start == -1 || addr_end == -1) {
Serial.print("no data in line");
}
else {
String req = line.substring(addr_start + 7, addr_end);
Serial.print("start: ");
Serial.println(addr_start);
Serial.print("end: ");
Serial.println(addr_end);
Serial.print("Possy: ");
Serial.println(req);
}
}
Serial.println();
Serial.println("closing connection");
}
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]