[esp8266]nodemcu esp8266 IOT开发板资料和教学
常用工具下载: - esplorer
- https://esp8266.ru/esplorer/
- esplorer需要jave7或者以上的版本
- https://www.java.com/en/download/
- ESP8266Flasher.exe刷固件软件
- https://github.com/nodemcu/nodemcu-flasher/raw/master/Win64/Release/ESP8266Flasher.exe
- nodemch pyflasher(macos & win)
- https://github.com/marcelstoer/nodemcu-pyflasher/releases/tag/v4.0
复制代码
有时候用usb线连接不了电脑,建议换根质量好点的USB线试, 有些USB线只接了地址和电源给设备充电用,并没有连接数据线!
Lua error: stdin:1: bad argument #1 to 'config' (config table not found!)
解决方法:--connect to Access Point (DO NOT save config to flash)
station_cfg={}
station_cfg.ssid="NODE-AABBCC"
station_cfg.pwd="password"
wifi.sta.config(station_cfg)
--connect to Access Point (DO save config to flash)
station_cfg={}
station_cfg.ssid="NODE-AABBCC"
station_cfg.pwd="password"
station_cfg.save=true
wifi.sta.config(station_cfg)
--connect to Access Point with specific MAC address
station_cfg={}
station_cfg.ssid="NODE-AABBCC"
station_cfg.pwd="password"
station_cfg.bssid="AA:BB:CC:DD:EE:FF"
wifi.sta.config(station_cfg)
--configure station but don't connect to Access point
station_cfg={}
station_cfg.ssid="NODE-AABBCC"
station_cfg.pwd="password"
station_cfg.auto=false
wifi.sta.config(station_cfg)
CH34XX芯片版本 - (base) VM:~ hello$ ll /dev/tty.*
- crw-rw-rw- 1 root wheel 18, 4 Jul 19 15:45 /dev/tty.Bluetooth-Incoming-Port
- crw-rw-rw- 1 root wheel 18, 16 Jul 19 16:18 /dev/tty.usbserial-14220
- crw-rw-rw- 1 root wheel 18, 14 Jul 19 16:18 /dev/tty.wchusbserial14220 <-------选择这个
复制代码
arduino IDE安装 esp8266 - http://arduino.esp8266.com/stable/package_esp8266com_index.json
复制代码然后在tools-->boards manager里面搜esp8266安装
- /* NodeMCU建立WiFi Access Point */
- #include <ESP8266WiFi.h>
- #include <WiFiClient.h>
- #include <ESP8266WebServer.h>
- /* 无线设置*/
- const char *ssid = "test ok"; //WiFi名称
- const char *password = "12345678"; //WiFi密码
- ESP8266WebServer server(80);
- /* 建立一个web server,任何连接到这个热点的设备
- * 可以通过浏览器访问http://192.168.4.1
- */
- void handleRoot() {
- server.send(200, "text/html", "<h1>Hello from ESP8266 AP!</h1>");
- }
- void setup() {
- delay(1000);
- Serial.begin(921600);
- Serial.println();
- Serial.print("Configuring access point...");
- /* You can remove the password parameter if you want the AP to be open. */
- WiFi.softAP(ssid, password);
- IPAddress myIP = WiFi.softAPIP();
- Serial.print("AP IP address: ");
- Serial.println(myIP);
- server.on("/", handleRoot);
- server.begin();
- Serial.println("HTTP server started");
- }
- void loop() {
- server.handleClient();
- }
复制代码
esp8266连接wifi设置
- #include <ESP8266WiFi.h>
- // ********** set wifi ***************
- const char* ssid = "你的ssid"; //wifi SSID which you want to join
- const char* password = "你的密码"; //wifi password
- void setup(void){
- Serial.begin(115200);
- WiFi.mode(WIFI_STA); //set to STA mode
- WiFi.begin(ssid, password); //connect to WiFi
- Serial.println("esp8266 module start");
- // 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
- Serial.print("ESP8266 MAC: "); //show nodemcu mac address
- Serial.println(WiFi.macAddress());
- }
- void loop(void){
- }
复制代码
wifi_set_macaddr:
ESP8266 无需设置 MAC 地址,芯片出厂时自带 MAC 地址,并保证其唯一性。有部分用户不想使用厂家的 MAC 地址,希望自定义 MAC 地址,因此提供了接口 wifi_set_macaddr。这个接口的设置不会保存到 Flash,开发者如有需要,需自行保存到 Flash。如果自定义 MAC 地址,需自行保证其唯一性。
|