it's work great, thank you!!
but i have one more question: the ESP8266WebServer.h can work whis just one client each time, do you think that i can do multiple clinet that work on the same server in diffrent timeing?
it's make any sense?
thank you!
Explore... Chat... Share...
Moderator: igrr
/*
*/
#include <ESP8266WiFi.h>
const char *ssid = "MyESPAP";
const char *password = "MyPassword";
const char *host = "192.168.4.1";
int rate_toogle = 0;
void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
delay(8000);
if (rate_toogle == 0)
rate_toogle = 1;
else
rate_toogle = 0;
Serial.print("connecting to ");
Serial.println(host);
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
String url = "/frate";
if (rate_toogle == 0)
url = "/srate";
String count2 = "/count2";
String count1 = "/count1?";
String num = "5";
Serial.print("Requesting URL: ");
Serial.println(url);
client.print(String("GET ") + count1 + "COUNTER = " + num + "HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
delay(10);
client.print(String("POST ") + count2 + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Content-Type: application\r\nContent-Length: 20\r\n\r\napples=12&oranges=45\r\n\r\n");
delay(10);
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
}
/*
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
const char *ssid = "MyESPAP";
const char *password = "MyPassword";
ESP8266WebServer server(80);
String count = "0";
int led = 2;
int blink_count = 0;
int blink_rate = 250;
void handleRoot() {
server.send(200, "text/html", "<html><body><h1>MyESPAP Home Page</h1>\r\n<a href=\"/frate\">Fast Rate</a><br>\r\n<a href=\"/srate\">Slow Rate</a><br>\r\n<h2 href=\"/count1\">counter = "+ count + " </h2><br>\r\n</body></html>");
}
void handleFRate() {
blink_rate = 125;
Serial.println("FastRate mode !");
server.send(200, "text/html", "<html><head><script>window.onload = function() { setInterval(function() {window.location.replace('/');}, 1000); };</script></head><body><h1>Fast Rate mode</h1></body></html>");
}
void handleSRate() {
blink_rate = 500;
Serial.println("SlowRate mode !");
server.send(200, "text/html", "<html><head><script>window.onload = function() { setInterval(function() {window.location.replace('/');}, 1000); };</script></head><body><h1>Slow Rate mode</h1></body></html>");
}
void handleCount1() {
Serial.println("MSG mode !");
server.send(200, "text/html", "<html><head><script>window.onload = function() { setInterval(function() {window.location.replace('/');}, 1000); };</script></head><body><h1>count1</h1></body></html>");
}
void handleCount2() {
Serial.println("MSG mode !");
server.send(200, "text/html", "<html><head><script>window.onload = function() { setInterval(function() {window.location.replace('/');}, 1000); };</script></head><body><h1>count2</h1></body></html>");
}
void setup() {
pinMode(led, OUTPUT);
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.println("Configuring Access Point ...");
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
server.on("/", handleRoot);
server.on("/frate", handleFRate);
server.on("/srate", handleSRate);
server.on("/count1", handleCount1);
server.on("/count2", handleCount2);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
if (blink_count >= blink_rate) {
digitalWrite(led, HIGH);
blink_count = 0;
}
if (blink_count == blink_rate / 2) {
digitalWrite(led, LOW);
}
delay(1);
blink_count++;
}
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[…]