|
nodemcu wifi code
nodemcu esp8266有三种wifi模式:WIFI_AP, WIFI_STA,WIFI_AP_STA
通过修改WIFI.mode(WIFI_STA)来设置
WIFI_AP, WIFI_STA, WIFI_AP_STA or WIFI_OFF
- #include <Arduino.h>
- #include <ESP8266WiFi.h>
- #include <WiFiClient.h>
- #include <ESP8266WebServer.h>
- // ********** set wifi and bit rate ***************
- const char* ssid = "xxxxx"; //wifi SSID which you want to join
- const char* password = "xxxx"; //wifi password
- void light (int delaySecond){
- delay ( delaySecond * 1000);
- }
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(921600); //default bit rate
- WiFi.mode(WIFI_STA); //set to STA mode
- WiFi.begin(ssid, password); //connect to WiFi
- Serial.println("ESP8266 module start!");
- Serial.print("ESP8266 MAC: "); //show nodemcu mac address before connect to wifi. as some network env bond mac address
- Serial.println(WiFi.macAddress()); //show nodemcu mac address
- // Wait for connection
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- // show info after connected!
- Serial.println("");
- Serial.print("Connected to ");
- Serial.println(ssid);
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP()); //show nodemcu ip address
复制代码
|
|