Timothy Pomeroy hace 2 años
padre
commit
44d545a593
Se han modificado 3 ficheros con 362 adiciones y 0 borrados
  1. 98 0
      ESP32_hotspot.ino
  2. 11 0
      config.h
  3. 253 0
      web.h

+ 98 - 0
ESP32_hotspot.ino

@@ -0,0 +1,98 @@
+/// import all of the common libs
+#include <WiFi.h>
+#include <WiFiClient.h>
+#include <WiFiAP.h>
+#include <WebServer.h>
+#include <uri/UriBraces.h>
+#include <ESPmDNS.h>
+
+#include "esp_wifi.h" // common esp wifi methods
+
+#include "web.h"  // our webpage contfigs
+#include "config.h" // out newtowrk configs
+
+WebServer server(port);
+
+void handleRoot() {
+  String message = "<h1>Actions</h1>";
+  String response = formatContent("Actions", message);
+  server.send(200, "text/html", response);
+}
+
+void handleClients() {
+  String message = "Client list\n\n";
+  wifi_sta_list_t wifi_sta_list;
+  tcpip_adapter_sta_list_t adapter_sta_list;
+  esp_wifi_ap_get_sta_list(&wifi_sta_list);
+  tcpip_adapter_get_sta_list(&wifi_sta_list, &adapter_sta_list);
+  if (adapter_sta_list.num > 0) {
+    for (uint8_t i = 0; i < adapter_sta_list.num; i++) {
+      tcpip_adapter_sta_info_t station = adapter_sta_list.sta[i];
+      ip_addr_t client_ip_addr;
+      memcpy((char *)&client_ip_addr.u_addr.ip4, (char *)&station.ip, sizeof(ip4_addr));
+      client_ip_addr.type = IPADDR_TYPE_V4;
+      message += ((String) "[+] Device " + i + " ");
+      message += ("%02X:%02X:%02X:%02X:%02X:%02X", station.mac[0], station.mac[1], station.mac[2], station.mac[3], station.mac[4], station.mac[5]);
+      message += (" ");
+      message += (ip4addr_ntoa(&(client_ip_addr.u_addr.ip4)));
+      message += ("\n");
+    }
+  }
+  String response = formatContent("Clients", "<pre>" + message + "</pre>");
+  server.send(200, "text/html", response);
+}
+
+void handleStatus() {
+  String message = "<h1>Online</h1>";
+  String response = formatContent("Status", message);
+  server.send(200, "text/html", response);
+}
+
+String formatContent(String title, String content) {
+  String response = (String) page_header + (String) page_nav + (String) page_content + (String) page_footer;
+  response.replace("__TITLE__", title);
+  response.replace("__CONTENT__", content);  
+  server.send(200, "text/html", response);
+}
+
+void setup() {
+  Serial.begin(baud);
+  Serial.println("\n[+] Creating AP");
+  WiFi.mode(WIFI_AP);
+  WiFi.softAP(ssid, password, channel, hide_SSID, max_connection);
+  
+  Serial.println((String) " --> ssid: " + ssid);
+  Serial.println((String) " --> password: " + password);
+  Serial.println((String) " --> channel: " + channel);
+  Serial.println((String) " --> hide ssid: " + hide_SSID);
+  Serial.println((String) " --> max connections: " + max_connection);
+  Serial.println(" --> ip address: 10.10.10.1");
+  Serial.println(" --> gateway: 10.10.10.1");
+  Serial.println(" --> subnet: 255.255.255.0");
+  
+  delay(100);
+  WiFi.softAPConfig(ip, ip, subnet);
+  delay(100);
+  IPAddress myIP = WiFi.softAPIP();
+  delay(100);
+  MDNS.begin(host);
+  
+  server.on("/", handleRoot);
+  server.on("/clients", handleClients);
+  server.on("/status", handleStatus);
+  server.onNotFound(handleRoot);
+  server.begin();
+  
+  delay(100);
+  MDNS.addService("http", "tcp", port);
+
+  Serial.print("[+] HTTP server started: http://");
+  Serial.print(host);
+  Serial.print(", http://");
+  Serial.println(myIP);
+}
+
+void loop() {
+  server.handleClient();
+  delay(2);
+}

+ 11 - 0
config.h

@@ -0,0 +1,11 @@
+const int baud = 115200;                  // serial baud rate
+const char *host = "HawkBandAP";          // ap name for mdns
+const char *ssid = "HawkBandLED";         // SSID Name
+const char *password = "j0inth3n3tw0rk";  // SSID Password - Set to NULL to have an open AP
+const int channel = 7;                    // WiFi Channel number between 1 and 13
+const bool hide_SSID = false;             // To disable SSID broadcast -> SSID will not appear in a basic WiFi scan
+const int max_connection = 25;            // Maximum simultaneous connected clients on the AP
+const int port = 80;
+
+const IPAddress ip(10, 10, 10, 1);
+const IPAddress subnet(255, 255, 255, 0);

+ 253 - 0
web.h

@@ -0,0 +1,253 @@
+#ifndef WEB_H
+#define WEB_H
+
+const char* page_header = R"(
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>__TITLE__</title>
+<style>
+body,textarea,input,select{
+background:0;
+border-radius:0;
+font:16px sans-serif;
+margin:0
+}
+.smooth{
+transition:all .2s
+}
+.btn,.nav a{
+text-decoration:none
+}
+.container{
+margin:0 20px;
+width:auto
+}
+label>*{
+display:inline
+}
+form>*{
+display:block;
+margin-bottom:10px
+}
+.btn{
+background:#999;
+border-radius:6px;
+border:0;
+color:#fff;
+cursor:pointer;
+display:inline-block;
+margin:2px 0;
+padding:12px 30px 14px
+}
+.btn:hover{
+background:#888
+}
+.btn:active,.btn:focus{
+background:#777
+}
+.btn-a{
+background:#0ae
+}
+.btn-a:hover{
+background:#09d
+}
+.btn-a:active,.btn-a:focus{
+background:#08b
+}
+.btn-b{
+background:#3c5
+}
+.btn-b:hover{
+background:#2b4
+}
+.btn-b:active,.btn-b:focus{
+background:#2a4
+}
+.btn-c{
+background:#d33
+}
+.btn-c:hover{
+background:#c22
+}
+.btn-c:active,.btn-c:focus{
+background:#b22
+}
+.btn-sm{
+border-radius:4px;
+padding:10px 14px 11px
+}
+.row{
+margin:1% 0;
+overflow:auto
+}
+.col{
+float:left
+}
+.table,.c12{
+width:100%
+}
+.c11{
+width:91.66%
+}
+.c10{
+width:83.33%
+}
+.c9{
+width:75%
+}
+.c8{
+width:66.66%
+}
+.c7{
+width:58.33%
+}
+.c6{
+width:50%
+}
+.c5{
+width:41.66%
+}
+.c4{
+width:33.33%
+}
+.c3{
+width:25%
+}
+.c2{
+width:16.66%
+}
+.c1{
+width:8.33%
+}
+h1{
+font-size:3em
+}
+.btn,h2{
+font-size:2em
+}
+.ico{
+font:33px Arial Unicode MS,Lucida Sans Unicode
+}
+.addon,.btn-sm,.nav,textarea,input,select{
+outline:0;
+font-size:14px
+}
+textarea,input,select{
+padding:8px;
+border:1px solid #ccc
+}
+textarea:focus,input:focus,select:focus{
+border-color:#5ab
+}
+textarea,input[type=text]{
+-webkit-appearance:none;
+width:13em
+}
+.addon{
+padding:8px 12px;
+box-shadow:0 0 0 1px #ccc
+}
+.nav,.nav .current,.nav a:hover{
+background:#000;
+color:#fff
+}
+.nav{
+height:24px;
+padding:11px 0 15px
+}
+.nav a{
+color:#aaa;
+padding-right:1em;
+position:relative;
+top:-1px
+}
+.nav .pagename{
+font-size:22px;
+top:1px
+}
+.btn.btn-close{
+background:#000;
+float:right;
+font-size:25px;
+margin:-54px 7px;
+display:none
+}
+@media(min-width:1310px){
+.container{
+margin:auto;
+width:1270px
+}
+}
+@media(max-width:870px){
+.row .col{
+width:100%
+}
+}
+@media(max-width:500px){
+.btn.btn-close{
+display:block
+}
+.nav{
+overflow:hidden
+}
+.pagename{
+margin-top:-11px
+}
+.nav:active,.nav:focus{
+height:auto
+}
+.nav div:before{
+background:#000;
+border-bottom:10px double;
+border-top:3px solid;
+content:'';
+float:right;
+height:4px;
+position:relative;
+right:3px;
+top:14px;
+width:20px
+}
+.nav a{
+padding:.5em 0;
+display:block;
+width:50%
+}
+}
+.table th,.table td{
+padding:.5em;
+text-align:left
+}
+.table tbody>:nth-child(2n-1){
+background:#ddd
+}
+.msg{
+padding:1.5em;
+background:#def;
+border-left:5px solid #59d
+}
+</style>
+</head>
+<body>
+  )";
+
+const char* page_content = "<div class=\"container\">__CONTENT__</div>";
+
+const char* page_footer = "</body>\n</html>";
+
+const char* page_nav = R"(
+<nav class="nav" tabindex="-1">
+<div class="container">
+<a class="pagename current" href="/">__TITLE__</a>
+<a href="/">Actions</a>
+<a href="/clients">Clients</a> 
+<a href="/status">Status</a>
+</div>
+</nav>
+<button class="btn-close btn btn-sm">×</button>
+)";
+
+#endif