Advertisement
Ruddog

AnotherHTML_Example

Sep 16th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. // WiLamp Version 1
  2. // Made by Muhammed Fasil K-https://github.com/mhdfasilwyd/Arduino_Projects
  3. #include <ESP8266WiFi.h>
  4. #include <WiFiClient.h>
  5. #include <ESP8266WebServer.h>
  6. const char MAIN_page[] PROGMEM = R"=====(
  7.  <!DOCTYPE html>
  8.  <html>
  9.  <body>
  10.  <center>
  11.  <h1>WiLamp</h1><br>
  12.  Ciclk to turn <a href="ledOn">LED ON</a><br>
  13.  Ciclk to turn <a href="ledOff">LED OFF</a><br>
  14.  </center>
  15.  </body>
  16.  </html>
  17. )=====";
  18. IPAddress staticIP(192, 168, 43, 90);
  19. IPAddress gateway(192, 168, 43, 1);  
  20. IPAddress subnet(255, 255, 255, 0);
  21. IPAddress dns(8, 8, 8, 8);  //DNS
  22. const char* deviceName = "pcweek";
  23. #define LED 2
  24. const char* ssid = "pcweek";
  25. const char* password = "wilamp123";
  26. ESP8266WebServer server(80);
  27. void handleRoot()
  28. {
  29.  String s = MAIN_page;
  30.  server.send(200, "text/html", s);
  31. }
  32. void handleLEDon() {
  33.  Serial.println("LED on page");
  34.  digitalWrite(LED,LOW);
  35.  server.send(200, "text/html", "LED is ON");
  36. }
  37. void handleLEDoff()
  38. {
  39.  Serial.println("LED off page");
  40.  digitalWrite(LED,HIGH);
  41.  server.send(200, "text/html", "LED is OFF");
  42. }
  43. void setup(void){
  44.   Serial.begin(115200);
  45.   WiFi.begin(ssid, password);
  46.   Serial.println("");
  47.   pinMode(LED,OUTPUT);
  48.   digitalWrite(LED,HIGH);
  49.   WiFi.disconnect();
  50.   WiFi.hostname(deviceName);
  51.   WiFi.config(staticIP, subnet, gateway, dns);
  52.   WiFi.begin(ssid, password);
  53.   WiFi.mode(WIFI_STA);
  54.   while (WiFi.status() != WL_CONNECTED) {
  55.   delay(500);
  56.   Serial.print(".");
  57.   }
  58.   server.on("/", handleRoot);    
  59.   server.on("/ledOn", handleLEDon);
  60.   server.on("/ledOff", handleLEDoff);
  61.   server.begin();                
  62.   Serial.println("WiLamp Server Started");
  63. }
  64. void loop(void){
  65. server.handleClient();        
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement