Wifi 库旨在控制 Wifi 接口。它支持连接到 wifi 网络、获取网络信息、启动接入点等功能。
它可在以下设备上使用:
* [Espruino WiFi](http://www.espruino.com/WiFi#using-wifi)
* [ESP8266](http://www.espruino.com/EspruinoESP8266)
* [ESP32](http://www.espruino.com/ESP32)
某些功能可能会在您的设备上实现,也可能不会实现,但是我们已经记录了哪些功能可用,哪些功能不可用。
如果您没有使用上述设备之一,则会提供单独的 WiFi 库。例如:
* 连接到 Espruino 板的ESP8266
* [CC3000 WiFi 模块](http://www.espruino.com/CC3000)
GSM、以太网和 LTE 等其他连接网络的方式也有自己的库。
您可以按如下方式使用 WiFi 库:
~~~
var wifi = require("Wifi");
wifi.connect("my-ssid", {password:"my-pwd"}, function(ap){
console.log("connected:", ap);
});
~~~
在 ESP32/ESP8266 上,如果您希望在启动时自动进行连接,请添加`wifi.save();`. 在其他平台上,可以将 .`wifi.connect` 写到 `onInit` 事件内
## 事件
* [Wifi.on('associated', function(details) { ... });](Wifi/associated.md)
* [Wifi.on('auth_change', function(details) { ... });](Wifi/auth_change.md)
* [Wifi.on('connected', function(details) { ... });](Wifi/connected.md)
* [Wifi.on('dhcp_timeout', function() { ... });](Wifi/dhcp_timeout.md)
* [Wifi.on('disconnected', function(details) { ... });](Wifi/disconnected.md)
* [Wifi.on('probe_recv', function(details) { ... });](Wifi/probe_recv.md)
* [Wifi.on('sta_joined', function(details) { ... });](Wifi/sta_joined.md)
* [Wifi.on('sta_left', function(details) { ... });](Wifi/sta_left.md)
## 方法
* [Wifi.connect(ssid, options, callback)](Wifi/connect.md)
* [Wifi.disconnect(callback)](Wifi/disconnect.md)
* [Wifi.getAPDetails(callback)](Wifi/getAPDetails.md)
* [Wifi.getAPIP(callback)](Wifi/getAPIP.md)
* [Wifi.getDetails(callback)](Wifi/getDetails.md)
* [Wifi.getHostByName(hostname, callback)](Wifi/getHostByName.md)
* [Wifi.getHostname(callback)](Wifi/getHostname.md)
* [Wifi.getIP(callback)](Wifi/getIP.md)
* [Wifi.getStatus(callback)](Wifi/getStatus.md)
* [Wifi.ping(hostname, callback)](Wifi/ping.md)
* [Wifi.restore()](Wifi/restore.md)
* [Wifi.save(what)](Wifi/save.md)
* [Wifi.scan(callback)](Wifi/scan.md)
* [Wifi.setAPIP(settings, callback)](Wifi/setAPIP.md)
* [Wifi.setConfig(settings)](Wifi/setConfig.md)
* [Wifi.setHostname(hostname, callback)](Wifi/setHostname.md)
* [Wifi.setIP(settings, callback)](Wifi/setIP.md)
* [Wifi.setSNTP(server, tz\_offset)](Wifi/setSNTP.md)
* [Wifi.startAP(ssid, options, callback)](Wifi/startAP.md)
* [Wifi.stopAP(callback)](Wifi/stopAP.md)
* [Wifi.turbo(enable, callback)](Wifi/turbo.md)
- 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 卡 加载模块
- 从互联网加载模块
- 已有模块
- 常见问题
- 编写和提交模块(或更改)