## 調用方法:
`require("Wifi").connect(ssid,options,callback)`
## 參數
`ssid`\- 接入點網絡 ID。
`options`\- \[可選\] 連接選項。
`callback`\- 完成時要回調`callback(err)`的函數。`err`在成功時為 null,或在失敗時包含錯誤字符串。
## 描述
作為工作站連接到接入點。如果存在與 AP 的現有連接,則如果 SSID 或密碼與作為參數傳遞的 SSID 或密碼不同,則首先斷開連接。換句話說,如果傳遞的SSID和密碼與當前連接的AP相同,則不會更改任何內容。連接嘗試完成后,將使用一個`err`參數調用回調函數,如果沒有錯誤,則為 NULL,如果有錯誤,則為字符串消息。如果啟用了 DHCP,則在獲取 IP 地址后進行回調,如果設置了靜態 IP,則在加入 AP 網絡后進行回調。如果連接已存在且不需要更改,則也會調用回調。
選項屬性(options)可能包含:
* `password`\- 用于訪問網絡的密碼字符串。
* `dnsServers`(array of String) - 最多包含兩個 DNS 服務器的數組,采用帶點的十進制格式字符串。
* `channel`\- 接入點的 Wifi 信道(整數,典型值 0..14,0 表示任何信道),僅在ESP8266上。
* `bssid`\- 接入點的 Mac 地址(字符串,類似于 "00:00:00:00:00:00"),僅在 ESP8266 上。
筆記:
* 這些選項應包括設置靜態 IP 以及關聯的網絡掩碼和網關的能力,這是未來的增強功能。
* 回調中報告的唯一錯誤是“密碼錯誤”,所有其他錯誤(例如找不到接入點或DHCP超時)都會導致連接重試。如果需要報告此類臨時錯誤,調用方必須使用自己的超時和`getDetails().status`字段。
* `connect` 會自動開啟 `station` 模式,可以通過調用 `disconnect` 再次禁用。
- Espruino簡介
- API
- 全局Globals
- acceleration()
- analogRead(pin)
- analogWrite(pin, value, options)
- atob(base64Data)
- btoa(binaryData)
- changeInterval(id, time)
- clearInterval(id)
- clearTimeout(id)
- clearWatch(id)
- compass()
- decodeURIComponent(str)
- digitalPulse(pin, value, time)
- digitalRead(pin)
- digitalWrite(pin, value)
- dump()
- echo(echoOn)
- edit(funcName)
- encodeURIComponent(str)
- eval(code)
- getPinMode(pin)
- getSerial()
- getTime()
- isFinite(x)
- isNaN(x)
- load(filename)
- parseFloat(string)
- parseInt(string, radix)
- peek16(addr, count)
- peek32(addr, count)
- peek8(addr, count)
- pinMode(pin, mode, automatic)
- poke16(addr, value)
- poke32(addr, value)
- poke8(addr,value)
- print(text, ...)
- require(moduleName)
- reset(clearFlash)
- save()
- setBusyIndicator(pin)
- setDeepSleep(sleep)
- setInterval(function, timeout, args, ...)
- setSleepIndicator(pin)
- setTime(time)
- setTimeout(function, timeout, args, ...)
- setWatch(function, pin, options)
- shiftOut(pins, options, data)
- show(image)
- trace()
- ESP8266
- ESP8266.crc32
- ESP8266.deepSleep
- ESP8266.dumpSocketInfo
- ESP8266.getFreeFlash
- ESP8266.getResetInfo
- ESP8266.getState
- ESP8266.logDebug
- ESP8266.neopixelWrite
- ESP8266.ping
- ESP8266.printLog
- ESP8266.readLog
- ESP8266.reboot
- ESP8266.setCPUFreq
- ESP8266.setLog
- ESP32
- ESP32.deepSleep(us)
- ESP32.deepSleepExt0(pin, level)
- ESP32.deepSleepExt1(pinVar, mode)
- ESP32.enableBLE(enable)
- ESP32.enableWifi(enable)
- ESP32.getState()
- ESP32.getWakeupCause()
- ESP32.reboot()
- ESP32.setAtten(pin, atten)
- ESP32.setBLE_Debug(level)
- ESP32.setOTAValid(isValid)
- Wifi
- event associated
- event auth_change
- Wifi.connect(ssid, options, callback)
- event connected
- event dhcp_timeout
- Wifi.disconnect(callback)
- event disconnected
- Wifi.getAPDetails(callback)
- Wifi.getAPIP(callback)
- Wifi.getDetails(callback)
- Wifi.getHostByName(hostname, callback)
- Wifi.getIP(callback)
- Wifi.getStatus(callback)
- Wifi.ping(hostname, callback)
- event probe_recv
- Wifi.restore()
- Wifi.save(what)
- Wifi.scan(callback)
- Wifi.setAPIP(settings, callback)
- Wifi.setConfig(settings)
- Wifi.setHostname(hostname, callback)
- Wifi.setIP(settings, callback)
- Wifi.setSNTP(server, tz_offset)
- event sta_joined
- event sta_left
- Wifi.startAP(ssid, options, callback)
- Wifi.stopAP(callback)
- Wifi.turbo(enable, callback)
- Modules
- Modules.addCached(id, sourcecode)
- Modules.getCached()
- Modules.removeAllCached()
- Modules.removeCached(id)
- Flash
- Flash.erasePage(addr)
- Flash.getFree()
- Flash.getPage(addr)
- Flash.read(length, addr)
- Flash.write(data, addr)
- Storage
- Storage.compact(showMessage)
- Storage.debug()
- Storage.erase(name)
- Storage.eraseAll()
- Storage.getFree(checkInternalFlash)
- Storage.getStats(checkInternalFlash)
- Storage.hash(regex)
- Storage.list(regex, filter)
- Storage.open(name, mode)
- Storage.optimise()
- Storage.read(name, offset, length)
- Storage.readArrayBuffer(name)
- Storage.readJSON(name, noExceptions)
- Storage.write(name, data, offset, size)
- Storage.writeJSON(name, data)
- StorageFile
- StorageFile.erase()
- StorageFile.getLength()
- StorageFile.pipe(destination, options)
- StorageFile.read(len)
- StorageFile.readLine()
- StorageFile.write(data)
- 模塊 Modules
- 使用模塊進行工作
- 內置模塊
- Espruino 模塊
- 來自 Github(或互聯網上的任何地方)
- 從 Storage 加載模塊
- 從 NPM 加載模塊
- 從一個本地文件夾
- 從 SD 卡 加載模塊
- 從互聯網加載模塊
- 已有模塊
- 常見問題
- 編寫和提交模塊(或更改)