├── README.md
├── mainPage.h
├── screenshot.png
└── smarthome.ino
/README.md:
--------------------------------------------------------------------------------
1 | ## :house: Simple, ESP-Hosted, web Smart Sockets system
2 |
3 | ### Demo
4 | 
5 |
6 | ### Usage
7 | Download `.ino` and `.h` files from the repository and upload it to your ESP board using Arduino IDE.
8 | After successfull flash webpage to control ESP's pins will be available at ESP's IP address.
9 |
10 | ### Tweaking
11 | You can edit `mainPage.h` according to your needs. You can add more pins by declaring more load pins and adding more `@@Ln@@`and `t_state` lines.
12 |
13 | ### Licensing
14 | Code is distributed as public domain. Use it however and wherever you want.
15 |
--------------------------------------------------------------------------------
/mainPage.h:
--------------------------------------------------------------------------------
1 | const char MAIN_page[] PROGMEM = R"=====(
2 |
3 |
4 | Smart Sockets v2 by revox
5 |
40 |
41 |
42 |
43 |
74 |
75 |
76 | )=====";
77 |
--------------------------------------------------------------------------------
/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/revoxhere/ESP8266-SmartHome/447ee3704dcc87418359d76abe812251c5abb78c/screenshot.png
--------------------------------------------------------------------------------
/smarthome.ino:
--------------------------------------------------------------------------------
1 | //Smart Sockets v2 system for ESP boards by revox
2 | //libraries
3 | #include
4 | #include
5 | #include
6 |
7 | #include "mainPage.h" //add webpage
8 |
9 | const char *ssid = "ssid"; //wifi ssif
10 | const char *password = "pass"; //wifi pass
11 |
12 | //input pins
13 | const int Load1 = 16;
14 | const int Load2 = 14;
15 | const int Load3 = 12;
16 | const int Load4 = 13;
17 | const int Load5 = 4;
18 | const int Load6 = 5;
19 |
20 | String L1Status, L2Status, L3Status, L4Status, Temperature, L5Status, L6Status;
21 | ESP8266WebServer server(80);
22 |
23 | void handleRoot() {
24 | String s = MAIN_page;
25 | s.replace("@@L1@@", L1Status); //variables for web - replace @@xx@@ for switch state
26 | s.replace("@@L2@@", L2Status);
27 | s.replace("@@L3@@", L3Status);
28 | s.replace("@@L4@@", L4Status);
29 | s.replace("@@L5@@", L5Status);
30 | s.replace("@@L6@@", L6Status);
31 | server.send(200, "text/html", s);
32 | }
33 | //obsluga klienta
34 | void handleForm() {
35 | String t_state = server.arg("submit");
36 |
37 | if (t_state == "ON1")
38 | {
39 | L1Status = "(ON)";
40 | digitalWrite(Load1, HIGH);
41 | }
42 |
43 | if (t_state == "OFF1")
44 | {
45 | L1Status = "(OFF)";
46 | digitalWrite(Load1, LOW);
47 | }
48 |
49 | if (t_state == "ON2")
50 | {
51 | L2Status = "(ON)";
52 | digitalWrite(Load2, HIGH);
53 | }
54 |
55 | if (t_state == "OFF2")
56 | {
57 | L2Status = "(OFF)";
58 | digitalWrite(Load2, LOW);
59 | }
60 |
61 | if (t_state == "ON3")
62 | {
63 | L3Status = "(ON)";
64 | digitalWrite(Load3, HIGH);
65 | }
66 |
67 | if (t_state == "OFF3")
68 | {
69 | L3Status = "(OFF)";
70 | digitalWrite(Load3, LOW);
71 | }
72 |
73 | if (t_state == "ON4")
74 | {
75 | L4Status = "(ON)";
76 | digitalWrite(Load4, HIGH);
77 | }
78 |
79 | if (t_state == "OFF4")
80 | {
81 | L4Status = "(OFF)";
82 | digitalWrite(Load4, LOW);
83 | }
84 |
85 | if (t_state == "ON5")
86 | {
87 | L5Status = "(ON)";
88 | digitalWrite(Load5, HIGH);
89 | }
90 |
91 | if (t_state == "OFF5")
92 | {
93 | L5Status = "(OFF)";
94 | digitalWrite(Load5, LOW);
95 | }
96 |
97 | if (t_state == "ON6")
98 | {
99 | L6Status = "(ON)";
100 | }
101 |
102 | if (t_state == "OFF6")
103 | {
104 | L6Status = "(OFF)";
105 | }
106 |
107 | //everything is on single page thanks to this redirect
108 | server.sendHeader("Location", "/");
109 | server.send(302, "text/plain", "Updated-- Press Back Button");
110 | delay(100);
111 | }
112 |
113 | void setup() {
114 | delay(500);
115 | WiFi.mode(WIFI_AP_STA); //wifi config
116 | WiFi.begin(ssid, password);
117 | IPAddress myIP = WiFi.softAPIP();
118 | server.on("/", handleRoot);
119 | server.on("/form", handleForm);
120 | server.begin();
121 |
122 | pinMode(Load1, OUTPUT); //pin configurations
123 | pinMode(Load2, OUTPUT);
124 | pinMode(Load3, OUTPUT);
125 | pinMode(Load4, OUTPUT);
126 | pinMode(Load5, OUTPUT);
127 | pinMode(Load6, OUTPUT);
128 | }
129 |
130 | void loop() {
131 | server.handleClient(); //let ESP handle clients
132 | }
133 |
--------------------------------------------------------------------------------