Skip to main content

การ Fix IP ให้ NodeMCU

ทดสอบ Fix IP ดังนี้
IP Address: 192.168.1.50
Subnet mask: 255.255.255.0
Gateway: 192.168.1.1

===================================================

#include <ESP8266WiFi.h>
const char* ssid     = "ชื่อwifi";           // SSID wifi name
const char* password = "รหัสwifi";    // Wifi password
void setup() 
{
    Serial.begin(115200);   // serial baudrate 115200
    delay(10);
    Serial.println();
    Serial.println();
    Serial.print("Connecting to "); // Show message “Connecting to”
    Serial.println(ssid);       // Show SSID 
    WiFi.begin(ssid, password); // Connected AP
   
    while (WiFi.status() != WL_CONNECTED)   // wait
{
            delay(500);
            Serial.print(".");
    }
     
IPAddress local_ip = {192,168,1,50};   // Fix IP
    IPAddress gateway={192,168,1,1};    //Fix IP Gateway
    IPAddress subnet={255,255,255,0};   // FixSubnet
    WiFi.config(local_ip,gateway,subnet);   //setting to module
 
    Serial.println(""); 
    Serial.println("WiFi connected");  
    Serial.println("IP address: "); 
    Serial.println(WiFi.localIP()); // show IP of ESP8266
}
void loop() {}

====================================================


ip02

ทดสอบ ping ไปยังไอพี 192.168.1.50 ที่ fix ไว้

ip03