基本範例
1)將GPIO 2 (pin 4)設為高電位(HIGH)
pin = 4
gpio.mode(pin,gpio.OUTPUT)
gpio.write(pin,gpio.HIGH)
gpio.mode(pin,gpio.INPUT)
print(gpio.read(pin))
2)開啟WiFi 加入 AP
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","password")
print(wifi.sta.getip())
3)開啟AP Mode 設定IP , 並開啟 DHCP
wifi.setmode(wifi.SOFTAP)
cfgap={}
cfgap.ssid="ws2812"
cfgap.pwd="12345678"
wifi.ap.config(cfgap)
cfg =
{
ip="192.168.10.1",
netmask="255.255.255.0",
gateway="192.168.10.1"
}
wifi.ap.setip(cfg)
dhcp_config ={}
dhcp_config.start = "192.168.10.100"
wifi.ap.dhcp.config(dhcp_config)
wifi.ap.dhcp.start()