├── ESP8266_Control_wiring_diagram.png ├── README.md ├── esp8266Server.ino └── esp8266_systemDiagram_png.png /ESP8266_Control_wiring_diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amphancm/ESP8266WiFiControl/0e4754c453c8a4110d51d129fffc19c68113db60/ESP8266_Control_wiring_diagram.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESP8266WiFiControl 2 | You can control 4 channel relay outputs via WiFi Network with ESP8266 WiFi Module. 3 | Vist for Full detail 4 | http://androidcontrol.blogspot.com/2016/05/esp8266-wifi-control-relay.html 5 | 6 | Need Library Adafruit_GFX.h ( Version 1.0.2 only ) , ESP_Adafruit_SSD1306.h 7 | 8 | Developer amphancm@gmail.com ,digital2u.net@gmail.com http://softpowergroup.net/ 9 | 10 | #### System Diagram 11 | ![System diagram](/esp8266_systemDiagram_png.png) 12 | 13 | ##### Wiring Diagram 14 | ![System diagram](/ESP8266_Control_wiring_diagram.png) 15 | -------------------------------------------------------------------------------- /esp8266Server.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define OLED_RESET 4 9 | Adafruit_SSD1306 display(OLED_RESET); 10 | 11 | 12 | 13 | #if (SSD1306_LCDHEIGHT != 64) 14 | #error("Height incorrect, please fix Adafruit_SSD1306.h!"); 15 | #endif 16 | 17 | const char* ssid = "Connectify-pc"; 18 | const char* password = "0816452400"; 19 | 20 | ESP8266WebServer server(80); 21 | 22 | const int output1 = 14; 23 | const int output2 = 12; 24 | const int output3 = 13; 25 | const int output4 = 15; 26 | 27 | boolean device1 = false; 28 | boolean device2 = false; 29 | boolean device3 = false; 30 | boolean device4 = false; 31 | 32 | void handleRoot() { 33 | //digitalWrite(led, 1); 34 | //server.send(200, "text/plain", "hello from esp8266!"); 35 | //digitalWrite(led, 0); 36 | 37 | String cmd; 38 | cmd += "\r\n"; 39 | cmd += "\r\n"; 40 | //cmd += "
ESP8266 Webserver

\"ESP8266 Web Server Control\"

"; 41 | cmd += ""; 42 | cmd += ""; 43 | cmd += ""; 44 | 45 | if(device1){ 46 | cmd +=("
Device1 : ON"); 47 | } 48 | else{ 49 | cmd +=("
Device1 : OFF"); 50 | } 51 | 52 | if(device2){ 53 | cmd +=("
Device2 : ON"); 54 | } 55 | else{ 56 | cmd +=("
Device2 : OFF"); 57 | } 58 | 59 | if(device3){ 60 | cmd +=("
Device3 : ON"); 61 | } 62 | else{ 63 | cmd +=("
Device3 : OFF"); 64 | } 65 | 66 | if(device4){ 67 | cmd +=("
Device4 : ON"); 68 | } 69 | else{ 70 | cmd +=("
Device4 : OFF"); 71 | } 72 | 73 | cmd += "\r\n"; 74 | server.send(200, "text/html", cmd); 75 | } 76 | 77 | void handleNotFound(){ 78 | //digitalWrite(led, 1); 79 | String message = "File Not Found\n\n"; 80 | message += "URI: "; 81 | message += server.uri(); 82 | message += "\nMethod: "; 83 | message += (server.method() == HTTP_GET)?"GET":"POST"; 84 | message += "\nArguments: "; 85 | message += server.args(); 86 | message += "\n"; 87 | for (uint8_t i=0; i>1); // init done 113 | 114 | display.clearDisplay(); // Clear the buffer. 115 | 116 | display.setTextSize(2); 117 | display.setTextColor(WHITE); 118 | //display.setTextColor(BLACK, WHITE); // 'inverted' text 119 | display.setCursor(0,0); 120 | display.println(" ESP8266"); 121 | 122 | display.setTextSize(3); //Size4 = 5 digit , size3 = 7 digits 123 | //display.setTextColor(BLACK, WHITE); // 'inverted' text 124 | display.setTextColor(WHITE); 125 | display.setCursor(0,18); 126 | display.println("Control"); 127 | 128 | display.setTextSize(1); 129 | display.setTextColor(WHITE); 130 | //display.setTextColor(BLACK, WHITE); // 'inverted' text 131 | display.setCursor(0,52); 132 | display.println("Version 0.1"); 133 | 134 | display.display(); 135 | delay(2000); 136 | 137 | display.clearDisplay(); 138 | 139 | display.setTextSize(2); 140 | display.setTextColor(WHITE); 141 | //display.setTextColor(BLACK, WHITE); // 'inverted' text 142 | display.setCursor(0,0); 143 | display.println("Connecting"); 144 | 145 | 146 | // Wait for connection 147 | while (WiFi.status() != WL_CONNECTED) { 148 | delay(500); 149 | Serial.print("."); 150 | 151 | display.print("."); 152 | display.display(); 153 | } 154 | Serial.println(""); 155 | Serial.print("Connected to "); 156 | Serial.println(ssid); 157 | Serial.print("IP address: "); 158 | Serial.println(WiFi.localIP()); 159 | 160 | display.clearDisplay(); 161 | display.setTextSize(1); display.setTextColor(WHITE); 162 | display.setCursor(0,0); display.println(ssid); 163 | display.setTextSize(2); display.setTextColor(WHITE); 164 | display.setCursor(0,18); display.println(WiFi.localIP()); 165 | //display.setCursor(0,36); display.println(WiFi.localIP()); 166 | 167 | display.display(); 168 | 169 | 170 | 171 | if (MDNS.begin("esp8266")) { 172 | Serial.println("MDNS responder started"); 173 | } 174 | 175 | server.on("/", handleRoot); 176 | 177 | server.on("/status1=1", [](){ 178 | server.send(200, "text/plain", "device1 = ON"); 179 | digitalWrite(output1, HIGH); 180 | device1 = true; 181 | }); 182 | 183 | server.on("/status1=0", [](){ 184 | server.send(200, "text/plain", "device1 = OFF"); 185 | digitalWrite(output1, LOW); 186 | device1 = false; 187 | }); 188 | 189 | server.on("/status2=1", [](){ 190 | server.send(200, "text/plain", "device2 = ON"); 191 | digitalWrite(output2, HIGH); 192 | device2 = true; 193 | }); 194 | 195 | server.on("/status2=0", [](){ 196 | server.send(200, "text/plain", "device2 = OFF"); 197 | digitalWrite(output2, LOW); 198 | device2 = false; 199 | }); 200 | 201 | server.on("/status3=1", [](){ 202 | server.send(200, "text/plain", "device3 = ON"); 203 | digitalWrite(output3, HIGH); 204 | device3 = true; 205 | }); 206 | 207 | server.on("/status3=0", [](){ 208 | server.send(200, "text/plain", "device3 = OFF"); 209 | digitalWrite(output3, LOW); 210 | device3 = false; 211 | }); 212 | 213 | server.on("/status4=1", [](){ 214 | server.send(200, "text/plain", "device4 = ON"); 215 | digitalWrite(output4, HIGH); 216 | device4 = true; 217 | }); 218 | 219 | server.on("/status4=0", [](){ 220 | server.send(200, "text/plain", "device4 = OFF"); 221 | digitalWrite(output4, LOW); 222 | device4 = false; 223 | }); 224 | 225 | server.onNotFound(handleNotFound); 226 | server.begin(); 227 | Serial.println("HTTP server started"); 228 | } 229 | 230 | void loop(void){ 231 | server.handleClient(); 232 | } 233 | -------------------------------------------------------------------------------- /esp8266_systemDiagram_png.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amphancm/ESP8266WiFiControl/0e4754c453c8a4110d51d129fffc19c68113db60/esp8266_systemDiagram_png.png --------------------------------------------------------------------------------