NODEMCU ESP8266

  1. Set up your NodeMcu and write code to make it a web server.
  2. Connect NodeMcu to Wi-Fi.
  3. Optionally, if you want to access it from the internet, set up port forwarding on your router.
  4. Access the web server using the NodeMcu's IP address in a web browser on a device connected to the same network.


C++:
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

const char *ssid = "your-ssid";
const char *password = "your-password";

ESP8266WebServer server(80);

void setup() {
  Serial.begin(115200);

  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(250);
    Serial.print(".");
  }
  Serial.println("");

  Serial.println("WiFi connected");
  Serial.println("IP address: " + WiFi.localIP().toString());

  // Define route handlers
  server.on("/", HTTP_GET, handleRoot);

  // Start server
  server.begin();
}

void loop() {
  server.handleClient();
}

void handleRoot() {
  server.send(200, "text/plain", "Hello from NodeMcu!");
}
 

About this Thread

  • 3
    Replies
  • 650
    Views
  • 4
    Participants
Last reply from:
jisoo69

Trending Topics

Online now

Members online
1,277
Guests online
1,385
Total visitors
2,662

Forum statistics

Threads
2,268,815
Posts
28,924,282
Members
1,243,073
Latest member
Christian 0999
Back
Top