mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 09:41:19 +00:00
93 lines
1.6 KiB
C
93 lines
1.6 KiB
C
#include <ESP8266WiFi.h>
|
|
|
|
#include <WiFiClient.h>
|
|
|
|
#include <ESP8266WebServer.h>
|
|
|
|
const char *ssid = "ESP8266";
|
|
|
|
const char *password = "password";
|
|
|
|
const int Red = 14;
|
|
const int Green = 12;
|
|
const int Blue = 13;
|
|
|
|
ESP8266WebServer server(80);
|
|
|
|
void handleRoot() {
|
|
|
|
server.send(200, "text/html", "<h1>You are connected</h1>");
|
|
|
|
}
|
|
|
|
void setup() {
|
|
|
|
pinMode(Red, OUTPUT);
|
|
pinMode(Green, OUTPUT);
|
|
pinMode(Blue, OUTPUT);
|
|
|
|
delay(1000);
|
|
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println();
|
|
|
|
Serial.print("Configuring access point...");
|
|
|
|
WiFi.softAP(ssid, password);
|
|
|
|
IPAddress myIP = WiFi.softAPIP();
|
|
|
|
Serial.print("AP IP address: ");
|
|
|
|
Serial.println(myIP);
|
|
|
|
server.on("/", handleRoot);
|
|
|
|
server.on("/inline", [](){
|
|
server.send(200, "text/plain", "this works as well");
|
|
});
|
|
|
|
server.on("/openRed", [](){
|
|
server.send(200, "text/plain", "open red led");
|
|
digitalWrite(Red, HIGH);
|
|
});
|
|
|
|
server.on("/closeRed", [](){
|
|
server.send(200, "text/plain", "close red led");
|
|
digitalWrite(Red, LOW);
|
|
});
|
|
|
|
server.on("/openGreen", [](){
|
|
server.send(200, "text/plain", "open green led");
|
|
digitalWrite(Green, HIGH);
|
|
});
|
|
|
|
server.on("/closeGreen", [](){
|
|
server.send(200, "text/plain", "close green led");
|
|
digitalWrite(Green, LOW);
|
|
});
|
|
|
|
server.on("/openBlue", [](){
|
|
server.send(200, "text/plain", "open blue led");
|
|
digitalWrite(Blue, HIGH);
|
|
});
|
|
|
|
server.on("/closeBlue", [](){
|
|
server.send(200, "text/plain", "close blue led");
|
|
digitalWrite(Blue, LOW);
|
|
});
|
|
|
|
server.begin();
|
|
|
|
Serial.println("HTTP server started");
|
|
|
|
|
|
}
|
|
|
|
void loop() {
|
|
|
|
server.handleClient();
|
|
|
|
} |