-
-
Save luke/e57c727dd3d8698e918d3b2287bc7e22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <WiFiClient.h> | |
#include <ESP8266WebServer.h> | |
#include <ESP8266mDNS.h> | |
#include "ets_sys.h" | |
#include "osapi.h" | |
#include "gpio16.h" | |
void ICACHE_FLASH_ATTRgpio16_output_conf(void){ WRITE_PERI_REG(PAD_XPD_DCDC_CONF, (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); // mux configuration for XPD_DCDC to output rtc_gpio0 | |
WRITE_PERI_REG(RTC_GPIO_CONF, (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //mux configuration for out enable | |
WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe) | (uint32)0x1); //out enable} | |
void ICACHE_FLASH_ATTRgpio16_output_set(uint8 value){ WRITE_PERI_REG(RTC_GPIO_OUT, (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe) | (uint32)(value & 1));} | |
void ICACHE_FLASH_ATTRgpio16_input_conf(void){ WRITE_PERI_REG(PAD_XPD_DCDC_CONF, (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); // mux configuration for XPD_DCDC and rtc_gpio0 connection | |
WRITE_PERI_REG(RTC_GPIO_CONF, (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //mux configuration for out enable | |
WRITE_PERI_REG(RTC_GPIO_ENABLE, READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe); //out disable} | |
uint8 ICACHE_FLASH_ATTRgpio16_input_get(void){ return (uint8)(READ_PERI_REG(RTC_GPIO_IN_DATA) & 1);} | |
const char* ssid = "unifi2"; | |
const char* password = "cokefugu"; | |
ESP8266WebServer server(80); | |
const int relay = 16; | |
const int led = 13; | |
void handleRoot() { | |
digitalWrite(led, 1); | |
server.send(200, "text/plain", "hello from esp8266!"); | |
digitalWrite(led, 0); | |
} | |
void handleNotFound() { | |
digitalWrite(led, 1); | |
String message = "File Not Found\n\n"; | |
message += "URI: "; | |
message += server.uri(); | |
message += "\nMethod: "; | |
message += (server.method() == HTTP_GET) ? "GET" : "POST"; | |
message += "\nArguments: "; | |
message += server.args(); | |
message += "\n"; | |
for (uint8_t i = 0; i < server.args(); i++) { | |
message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; | |
} | |
server.send(404, "text/plain", message); | |
digitalWrite(led, 0); | |
} | |
void handleGate() { | |
if(server.method() == HTTP_POST){ | |
digitalWrite(relay, 1); | |
delay(00); | |
digitalWrite(relay, 0); | |
} | |
server.send(200, "text/html", "<body><form method=\"post\"><input type=\"submit\" value=\"button\" /></form></body>"); | |
} | |
void setup(void) { | |
pinMode(led, OUTPUT); | |
pinMode (relay, OUTPUT); | |
digitalWrite(led, 0); | |
digitalWrite(relay, 0); | |
Serial.begin(115200); | |
WiFi.mode(WIFI_STA); | |
WiFi.begin(ssid, password); | |
Serial.println(""); | |
// Wait for connection | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.print("Connected to "); | |
Serial.println(ssid); | |
Serial.print("IP address: "); | |
Serial.println(WiFi.localIP()); | |
if (MDNS.begin("esp8266")) { | |
Serial.println("MDNS responder started"); | |
} | |
server.on("/", handleRoot); | |
server.on("/gate", handleGate); | |
server.on("/inline", []() { | |
server.send(200, "text/plain", "this works as well"); | |
}); | |
server.onNotFound(handleNotFound); | |
server.begin(); | |
Serial.println("HTTP server started"); | |
} | |
void loop(void) { | |
server.handleClient(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment