Using NodeMCU as a Client & Server Application
Learn to use NodeMCU in Server mode and Client mode.
Description:
The NodeMCU is a popular development board that makes it easy to connect to Wi-Fi and create IoT applications. In this guide, we’ll walk through the steps to set up your NodeMCU as both a server and a client using the Arduino IDE.
Prerequisites:
- NodeMCU board
- USB cable
- Arduino IDE installed
- Wi-Fi network
Step 1: Set Up the Arduino IDE
1. Install the NodeMCU Board Package:
- Open the Arduino IDE.
- Go to `File` -> `Preferences`.
- In the “Additional Board Manager URLs” field, add: `http://arduino.esp8266.com/stable/package_esp8266com_index.json`.
- Go to `Tools` -> `Board` -> `Boards Manager`.
- Search for `esp8266` and install the latest version.
2. Select the NodeMCU Board:
- Go to `Tools` -> `Board` and select `NodeMCU 1.0 (ESP-12E Module)`.
Step 2: Set Up NodeMCU as a Server
1. Open the Example Sketch:
- Go to `File` -> `Examples` -> `ESP8266WebServer` -> `HelloServer`.
2. Modify the Sketch:
- Update the `ssid` and `password` variables with your Wi-Fi credentials.
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
3. Upload the Sketch:
- Connect your NodeMCU to your computer using a USB cable.
- Select the correct port under `Tools` -> `Port`.
- Click the upload button.
4. Monitor the Serial Output:
- Open the Serial Monitor (`Tools` -> `Serial Monitor`) and set the baud rate to `115200`.
- Once connected, the Serial Monitor will display the IP address of the NodeMCU.
5. Access the Server:
- Open a web browser and enter the IP address displayed in the Serial Monitor.
- You should see a message saying "Hello from ESP8266!".
Step 3: Set Up NodeMCU as a Client
1. Open the Example Sketch:
- Go to `File` -> `Examples` -> `ESP8266WiFi` -> `WiFiClient`.
2. Modify the Sketch:
- Update the `ssid` and `password` variables with your Wi-Fi credentials.
- Set the server's IP address and port (if you're using the previous server example, use the NodeMCU’s IP and port 80).
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
const char* host = "server_IP_address";
const uint16_t port = 80;
3. Upload the Sketch:
- Connect your NodeMCU to your computer.
- Select the correct port and upload the sketch.
4. Monitor the Serial Output:
- Open the Serial Monitor and set the baud rate to `115200`.
- The NodeMCU will attempt to connect to the server and you should see the response from the server in the Serial Monitor.
Step 4: Testing and Further Development
- Testing:
- With the server running, reset the client NodeMCU and observe the communication between the server and client in the Serial Monitor.
- Further Development:
- Explore more examples and libraries to expand your IoT projects.
- Modify the server to handle different types of requests.
- Use the client to send sensor data to the server.
Project Gallery
All Documents :
Use the codes from the eamples as mentioned above.
Click Here to Download
Video Tutorial :
Conclusion :
By following these steps, you've successfully set up your NodeMCU as both a server and a client. This setup forms the foundation for creating more complex IoT applications. For additional projects and resources, check out our website and Skill-Hub by EmbeddedBrew.
Happy coding!