arduino ESP8266设置静态IP

arduino ESP8266设置静态IP

arduino esp8266连接WIFI-打印IP地址mac地址--启动服务端server等待连接

#include <Arduino.h>  
#include <ESP8266WiFi.h>  
#include <ESP8266WiFiMulti.h>  
#include <ESP8266HTTPClient.h>  
//设置两个宏定义用于WiFi名和密码
#define WIFINAME "xxxx"  
#define WIFIPW   "xxxxxxx"  
IPAddress local_IP(192, 168, 166, 200);//想要设定的静态ip
IPAddress gateway(192, 168, 166, 247);//当前网关
IPAddress subnet(255, 255, 255, 0);//当前子网掩码
  
void setup() 
{  
  // put your setup code here, to run once:  
  pinMode(BUILTIN_LED, OUTPUT);  
  Serial.begin(115200);  
  Serial.println("");  
  WiFi.config(local_IP, gateway, subnet);//设置静态IP
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFINAME, WIFIPW);  
  Serial.print("Connecting..");  
  while (WiFi.status() != WL_CONNECTED)  
  {  
    delay(500);  
    Serial.print(".");  
  }  
  Serial.println();  
  Serial.print("Connected,IP Address:");  
  Serial.println(WiFi.localIP());  
   
}  
  
void loop() 
{  
  // put your main code here, to run repeatedly:  
  
}

 

posted @ 2023-04-16 15:11  txwtech  阅读(810)  评论(0)    收藏  举报