Assalam-o-Alaikum!
How are you friends, hope you will be fine. Today we are going to discuss on Static IP in WeMos. You will be able to assign static IP to WeMos after reading this tutorial. So let’s start.
Friends as you know that WeMos is used to connect via WiFi and it can also be access by the IP. You can create static HTML pages within the WeMos and then through IP you can access that HTML Static pages, but there is a problem, WeMos try to assign IP that is nearly available. But it is not real problem, you can assign static IP to WeMos and then can access it remotely. Here is the 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 |
//include libraries #include <ESP8266HTTPClient.h> #include <ESP8266WiFi.h> //Access point credentials const char* ssid = "Password lyna hay"; const char* pwd = "Google@007"; const char* host = "http://192.168.8.100"; WiFiServer server(80); // open port 80 for server connection void setup() { Serial.begin(115200); //initialise the serial communication delay(20); //connecting to wifi Serial.print("Connecting to WiFi SSID = "); Serial.println(ssid); // Static IP details... IPAddress ip(192, 168, 8, 109); IPAddress gateway(192, 168, 8, 249); IPAddress subnet(255, 255, 255, 0); IPAddress dns(192, 168, 1, 249); // Static IP Setup Info Here... WiFi.config(ip, gateway, subnet); //If you need Internet Access You should Add DNS also... WiFi.begin(ssid, pwd); //starting the server server.begin(); Serial.print("Connected. This is your ip address: "); Serial.print("http://"); Serial.print(WiFi.localIP()); Serial.println("/"); } void loop() { WiFiClient client = server.available(); //Read the first line of the request String request = client.readStringUntil('\r'); Serial.println(request); client.flush(); client.println("<!DOCTYPE HTML>"); client.println("<html>"); client.println("<body style=background-color:skyblue> </body>"); client.println("<head><style>div.relative{position:relative; left:200px; height:20px; width:350px; border:2px solid #73AD21;}</style></head>"); client.println("<h1 style='text-align:center'>Welcome to Wemose Static IP Programme</h1>"); client.println("</html>"); } |
Please change following values as per your system configuaration
- const char* ssid = “Password lyna hay”;
- const char* pwd = “Google@007”;
- const char* host = “http://192.168.8.100”;
In line number 6, 7 and 8. Also change following values