import network
import socket
from machine import Pin,RTC,Timer,WDT
import time,utime
import rp2
rp2.country('CN')
wap = network.WLAN(network.AP_IF)
wap.config(essid='PicoW', password='12345678')
wap.ifconfig(('192.168.0.4', '255.255.255.0', '192.168.0.1', '8.8.8.8'))
wap.active(True)
netConfig = wap.ifconfig()
# Handle connection error
if wlan.status() != 3:
wdt=WDT(timeout=5000)
#raise RuntimeError('network connection failed')
else:
print('connected')
led.value(1)
status = wlan.ifconfig()
print( 'ip = ' + status[0] )
# Open socket
addr = socket.getaddrinfo(netConfig [0] , 4002)[0][-1]
s = socket.socket()
s.bind(addr)
s.listen(10)
print('listening on', addr)
try:
print(wlan.status())
cl, addr = s.accept()
print('client connected from', addr)
request = cl.recv(1024)
print(request)
cl.send("led on")
cl.close()
except OSError as e:
cl.close()
print('connection closed')
Pico W 启动AP,同时启动本地服务器
-
- 随机主题
- 回复总数
- 阅读次数
- 最新文章
-
- 2回复总数
- 103 阅读次数
- 最新文章 由 shaoziyang
2024年 2月 18日 08:32
-
- 3回复总数
- 132 阅读次数
- 最新文章 由 孤独枫
2024年 2月 19日 19:42
-
- 1回复总数
- 107 阅读次数
- 最新文章 由 shaoziyang
2024年 2月 19日 11:35