Another project that demonstrate how to wire the ESP82366 Module and 16×2 i2C LCD as a network monitoring device to observe the network web/app server communication and can handle many host depend on your requirements. ESP8266 is a WiFi full TCP/IP stack and Microcontroller & coded can manage to do this task with the help of its own code libraries. The objective of this project is to run as standalone to monitor the server’s communication if it is disconnected from the network or remove from the internet. As you can see the diagram below there are two choices the first diagram uses 16×2 LCD Screen which is hookup to NodeMCU. The second diagram below is using ESP8233 12/12E module which you need to wire other component to make it worked properly.
Component Required
- ESP8266 12, 12E, ESP8266 NodeMCU, ESPDuino, WeMos
- USB UART / TTL
- LCD Screen (16×2/24×4)
- If your using ESP8266 12/12E chip that you to use 5v from the USB on your PC you need to use AMS1117 fixed 3.3v Voltage Regulator/ Step down Voltage Regulator .
- If your using Node MCU / ESPDuino, WeMOS you dont need voltage regulator
- Push Button / Tacktile Push Button
- Resistors (See the diagram below)
- Electrolytic Capacitors (See the diagram below)
Wiring Guide
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
/* 14CORE Test Code for: Server / Host Network Monitor with ESP8266 as stand alone. www.14core.com .:+osysso++:` `+yhs/-` `-+s+` `:/+++++++++` .:/++ooo++/-` .ooooooooooo+: :///////////- `odh/` `:y+` /ddhsooooooo+ /hddhsooooydddh sdddoooooosdddy` `////////////` -hds` `sy. +ddy` .ddd: sddy.dddo +ddd- .-----------` `hds :sssss/ -ossssso-yy` `hdd: oddy `ddd/oddd:......+dddo .++++++++++++ +dd` :sdddh` :ydddddddo +y/ .ddd+........ `hddy:.....:yddy.hdddddddddddy+. ```````````` ydy .hddd/+hdddhydddh/.+yo /hdddddddddd. :shddddddddhs/`+ddd:````-yddy- :ooooooooooo+ odh` sdddooyyyyyhddddyy.sy+ ` `......... ``.... ....` ```...` ` `` `` ` -dd+`::::` .:::- /yy. -oos+:-oos+--oos+: /o `+y o/: o:+/ h:`yos /+-`/+/+ s:y/y. /dd/ `+yy: +//+ +/:+ +/:+ -. `/ -:o.:/:`//+- + +:- :`-+:`://: +`o`+. -yds. `/yys- .`-.. .``` ```` .`` ` ` ``` ``-..` ` :ydy/.`````.-/oyhs: `+++oo+oo+:.+-++/-/ooo+o +:o/oo///:+/ .:oyhhhhhhhso:` `. ``` */ #include <Wire.h> #include <LiquidCrystal_I2C.h> //Download the library below #include <ESP8266WiFi.h> #include <ESP8266Ping.h> LiquidCrystal_I2C lcd(0x3F,16,2); //Set 0x27 if your using different i2c address (20,4 if your using 20/4 LCD) const char* ssid = "C0R3"; //Your WiFi Access Point Here const char* password = "1234567890"; //Your wifi password here const char* rhost1 = "www.14core.com"; //you can replace the host1 as you like const char* rhost2 = "www.google.com"; //you can replace the host2 as you like //const IPAddress rhost3 (192, 168, 111, 1); //const IPAddress rhost4 (192, 168, 111, 2); const long wlConTimeout = 30 * 1000; const long pingProbeHost = 2; const long wanCountFail = 2; const long delayWanCheck = 1 * 60 * 1000; const long delayReboot = 5 * 60 * 1000; void setup() { Serial.begin(115200); delay(100); Wire.begin(2,14); lcd.init(); lcd.backlight(); lcd.setCursor(0,0); lcd.print("14CORE | SERVER-MON"); lcd.setCursor(0,1); lcd.print(">Initializing..."); delay(4000); lcd.clear(); lcd.setCursor(0,0); lcd.print("CONNECTING TO"); lcd.setCursor(0,1); lcd.print("SSID>> "); lcd.setCursor(8,1); lcd.print(ssid); delay(4000); } void loop() { long chkProve = 0; long lastCheck = 0; while (true) { ++chkProve; lcd.clear(); lcd.setCursor(0,0); lcd.print("> WL/WAN PROBING..."); lcd.setCursor(0,1); lcd.print("PROC-ID > "); lcd.setCursor(10,1); lcd.print(chkProve); delay(2000); bool connected = ChkNetCon(); if (connected) { lastCheck = chkProve; } else { lcd.clear(); lcd.setCursor(0,0); lcd.print("WL/WAN FAILED"); lcd.setCursor(0,1); lcd.print("PROC-ID >"); lcd.setCursor(10,1); lcd.print(chkProve - lastCheck); delay(3000); lcd.clear(); lcd.setCursor(0,0); lcd.print("EXEC RETRY >"); lcd.setCursor(0,1); lcd.print("> TIME -"); lcd.setCursor(8,1); lcd.print(wanCountFail); delay(3000); } if (chkProve - lastCheck >= wanCountFail) { break; } sleep(">SLEEP MODE", delayWanCheck); lcd.setCursor(0,0); } // Reboot lcd.clear(); lcd.setCursor(0,0); lcd.print("CON IS FAILED"); lcd.setCursor(0,1); lcd.print(wanCountFail); delay(2000); lcd.clear(); lcd.setCursor(0,0); lcd.print("ALERT....."); lcd.setCursor(0,1); lcd.print("> REBOOTING"); delay(2000); RebootPower(); sleep(">TM SLP-REBOOT", delayReboot); //ESP.restart(); //Set to reboot itself return; } // SLEEP FUNCTION void sleep(const char* msg, long sleepTimeInMs){ lcd.clear(); lcd.setCursor(0,0); lcd.print(msg); lcd.setCursor(0,1); lcd.print("TIMER >"); lcd.setCursor(8,1); lcd.print(sleepTimeInMs); delay(sleepTimeInMs); } // REBOOT FUNCTION void RebootPower(){ lcd.clear(); lcd.setCursor(0,0); lcd.print("REBOOTING"); lcd.setCursor(0,1); lcd.print(">WL DISCONNECTED"); delay(31 * 1000); } // DISCONNECT FUNCTION void Disconnect(){ WiFi.disconnect(); lcd.clear(); lcd.setCursor(0,0); lcd.print("WL/WAN CON STATUS >"); lcd.setCursor(0,1); lcd.print(">DISCONNECTED"); delay(2000);} // PROVING CONNECTION/SENDING PING FUNCTION bool ChkNetCon() { bool success = false; success = Connect(); if (success) { success = false; success |= sendProbe(rhost1); success |= sendProbe(rhost2); /*You can add more remote host here*/ //success |= sendProbe(rhost3); //success |= sendProbe(rhost4); Disconnect(); } delay(100); if (success) { lcd.clear(); lcd.setCursor(0,0); lcd.print("SRV/HOST STATUS >"); lcd.setCursor(0,1); lcd.print(">>> HOST IS UP"); delay(3000); } else { lcd.clear(); lcd.setCursor(0,0); lcd.print("SRV/HST STATUS >"); lcd.setCursor(0,1); lcd.print(">>> HOST IS DOWN"); delay(3000); } return success; } // CONNECT FUNCTION bool Connect() { WiFi.begin(ssid, password); long varProgress = 10; long varProgIndex = 0; while (WiFi.status() != WL_CONNECTED && varProgIndex < varProgress) { delay(wlConTimeout / varProgress); ++varProgIndex; } delay(100); bool success = (WiFi.status() == WL_CONNECTED); if (success) { lcd.clear(); lcd.setCursor(0,0); lcd.print("CONNECTED TO/IP:"); lcd.setCursor(0,1); lcd.print("IP> "); lcd.setCursor(4,1); lcd.print(WiFi.localIP()); delay(4000); } else {; lcd.clear(); lcd.setCursor(0,0); lcd.print("CONNECTION STATUS >"); lcd.setCursor(0,1); lcd.print(">> TIMER: "); lcd.setCursor(3,1); lcd.print(WiFi.status(), true); delay(4000); } return success; } // CONNECTION STATUS FUNCTION void conStatus(long status, bool includeSpace) { switch (status) { case WL_NO_SHIELD: lcd.clear(); lcd.setCursor(0,0); lcd.print("WL/WAN STATUS"); lcd.setCursor(0,1); lcd.print(">>>WL NOSHIELD"); delay(2000); break; case WL_IDLE_STATUS: lcd.clear(); lcd.setCursor(0,0); lcd.print("WL/WAN STATUS"); lcd.setCursor(0,1); lcd.print(">>> WL IDLE"); delay(2000); break; case WL_NO_SSID_AVAIL: lcd.clear(); lcd.setCursor(0,0); lcd.print("WL/WAN STATUS"); lcd.setCursor(0,1); lcd.print(">WL NO SSID AVAIL"); delay(2000); break; case WL_SCAN_COMPLETED: lcd.clear(); lcd.setCursor(0,0); lcd.print("WL/WAN STATUS"); lcd.setCursor(0,1); lcd.print(">WL SCAN COMPLETED"); delay(2000); break; case WL_CONNECTED: lcd.clear(); lcd.setCursor(0,0); lcd.print("WL/WAN STATUS"); lcd.setCursor(0,1); lcd.print(">> WL CONNECTED"); delay(2000); break; case WL_CONNECT_FAILED: lcd.clear(); lcd.setCursor(0,0); lcd.print("WL/WAN STATUS"); lcd.setCursor(0,1); lcd.print(">WL CONNECT FAILED"); delay(2000); break; case WL_CONNECTION_LOST: lcd.clear(); lcd.setCursor(0,0); lcd.print("WL/WAN STATUS"); lcd.setCursor(0,1); lcd.print("> WL CON FAIL"); delay(2000); break; case WL_DISCONNECTED: lcd.clear(); lcd.setCursor(0,0); lcd.print("WL/WAN STATUS"); lcd.setCursor(0,1); lcd.print("> WAN FAIL"); delay(2000); break; } if (includeSpace) { Serial.print("."); } } // REPORTING FUNCTION bool sendProbe(const char* host) { lcd.clear(); lcd.setCursor(0,0); lcd.print("SNDING PROBE TO>"); lcd.setCursor(0,1); lcd.print(host); delay(1000); bool success = false; for (int i = 0; i < pingProbeHost; ++i) { success |= probeOnce(host); } if (success) { lcd.clear(); lcd.setCursor(0,0); lcd.print("SRV/HST STATUS"); lcd.setCursor(0,1); lcd.print("> HOST IS UP"); delay(2000); } else { lcd.clear(); lcd.setCursor(0,0); lcd.print("SRV/HST STATUS"); lcd.setCursor(0,1); lcd.print("> HOST IS DOWN"); delay(2000); } return success; } // PING ONES FUNCTION bool probeOnce(const char* host) { bool success = Ping.ping(host); if (success) { lcd.clear(); lcd.setCursor(0,0); lcd.print("SND PING2HOST"); lcd.setCursor(0,1); lcd.print(">> REPLY-RCV"); delay(2000); } else { lcd.clear(); lcd.setCursor(0,0); lcd.print("SND PING2HOST"); lcd.setCursor(0,1); lcd.print(">>> NOREPLY"); delay(2000); } return success; } |
Downloads
Download LCD Screen 16×2 | 20×4 i2c Display Code Libraries | Zip