#include #include /* Put your SSID & Password */ const char* ssid = "NodeMCU"; // Enter SSID here const char* password = ""; //Enter Password here /* default is 192.168.4.1 */ /* Put IP Address details */ /* IPAddress local_ip(192,168,1,56); IPAddress gateway(192,168,1,2); IPAddress subnet(255,255,255,0); */ ESP8266WebServer server(80); uint8_t DOWNpin = D6; bool DOWNstatus; uint8_t UPpin = D7; bool UPstatus; int fine_run_time = 100; void setup() { bool DOWNstatus = LOW; delay(1000); bool UPstatus = LOW; Serial.begin(115200); pinMode(DOWNpin, OUTPUT); pinMode(UPpin, OUTPUT); WiFi.softAP(ssid, password); /* WiFi.softAPConfig(local_ip, gateway, subnet); WiFi.setSleepMode(WIFI_NONE_SLEEP); */ delay(100); server.on("/", handle_OnConnect); server.on("/downon", handle_downon); server.on("/downfon", handle_downfon); server.on("/downoff", handle_downoff); server.on("/upon", handle_upon); server.on("/upfon", handle_upfon); server.on("/upoff", handle_upoff); server.onNotFound(handle_NotFound); server.begin(); Serial.println("HTTP server started"); } void loop() { server.handleClient(); if(DOWNstatus) {digitalWrite(DOWNpin, HIGH);} else {digitalWrite(DOWNpin, LOW);} if(UPstatus) {digitalWrite(UPpin, HIGH);} else {digitalWrite(UPpin, LOW);} } void handle_OnConnect() { DOWNstatus = LOW; UPstatus = LOW; Serial.println("GPIO7 Status: OFF | GPIO6 Status: OFF"); server.send(200, "text/html", SendHTML(UPstatus,DOWNstatus)); } void handle_upon() { if (DOWNstatus == LOW and UPstatus == LOW) { UPstatus = HIGH; Serial.println("GPIO7 Status: ON"); server.send(200, "text/html", SendHTML(UPstatus,DOWNstatus)); } else {DOWNstatus = LOW; UPstatus = LOW; server.send(200, "text/html", SendHTML(UPstatus,DOWNstatus)); } } void handle_upfon() { if (DOWNstatus == LOW and UPstatus == LOW) { Serial.println("GPIO7 Status: ON"); server.send(200, "text/html", SendHTML(UPstatus,DOWNstatus)); digitalWrite(UPpin, HIGH); delay(fine_run_time); digitalWrite(UPpin, LOW); Serial.println("GPIO7 Status: OFF"); server.send(200, "text/html", SendHTML(UPstatus,DOWNstatus)); } else {DOWNstatus = LOW; UPstatus = LOW; server.send(200, "text/html", SendHTML(UPstatus,DOWNstatus)); } } void handle_upoff() { UPstatus = LOW; Serial.println("GPIO7 Status: OFF"); server.send(200, "text/html", SendHTML(UPstatus,DOWNstatus)); } void handle_downon() { if (DOWNstatus == LOW and UPstatus == LOW) { DOWNstatus = HIGH; Serial.println("GPIO6 Status: ON"); server.send(200, "text/html", SendHTML(UPstatus,DOWNstatus)); } else {DOWNstatus = LOW; UPstatus = LOW; server.send(200, "text/html", SendHTML(UPstatus,DOWNstatus)); } } void handle_downfon() { if (DOWNstatus == LOW and UPstatus == LOW) { Serial.println("GPIO6 Status: ON"); server.send(200, "text/html", SendHTML(UPstatus,DOWNstatus)); digitalWrite(DOWNpin, HIGH); delay(fine_run_time); digitalWrite(DOWNpin, HIGH); Serial.println("GPIO6 Status: OFF"); server.send(200, "text/html", SendHTML(UPstatus,DOWNstatus)); } else {DOWNstatus = LOW; UPstatus = LOW; server.send(200, "text/html", SendHTML(UPstatus,DOWNstatus)); } } void handle_downoff() { DOWNstatus = LOW; Serial.println("GPIO6 Status: OFF"); server.send(200, "text/html", SendHTML(UPstatus,DOWNstatus)); } void handle_NotFound(){ server.send(404, "text/plain", "Not found"); } String SendHTML(uint8_t upstat,uint8_t downstat){ String ptr = " \n"; ptr +="\n"; ptr +="Screwdriver Antenna Controller\n"; ptr +="\n"; ptr +="\n"; ptr +="\n"; ptr +="

Antenna Controller

\n"; ptr +="

\n"; if(upstat) {ptr +="Off\n";} else {ptr +="UP\n";} ptr +="UP Fine\n"; ptr +="DOWN Fine\n"; if(downstat) {ptr +="Off\n";} else {ptr +="DOWN\n";} ptr +="

\n"; ptr +="\n"; ptr +="\n"; return ptr; }