ESP32:How to use micopython ethernet to ap?How to route ethernet to ap?
import network
import time
from machine import Pin
lan = network.LAN(mdc=Pin(16), mdio=Pin(17), power=None, id=None, phy_addr=1, phy_type=network.PHY_LAN8720)
try:
lan.active(True)
except Exception as err:
print("err:", err)
ret = lan.ifconfig()
print(ret)
ap = network.WLAN(network.AP_IF) # create access-point interface
ap.config(essid='ESP-AP') # set the ESSID of the access point
ap.config(max_clients=10) # set how many clients can connect to the network
ap.active(True) # activate the interface
ap.ifconfig()
print("ap ip:", ap.ifconfig())
Lan and ap can get the right ip. Lan can connect to the ethernet,but my phone conncet the ap but can not conncet to ethernet.
WIFI AP Doesn't work on ESP32
I am using this code to set up a simple ap webpage on the esp32:
try:
import usocket as socket
except:
import socket
import network
import esp
esp.osdebug(None)
import gc
gc.collect()
ssid = "Pigeons Aren't Real"
# password = '123456789'
ap = network.WLAN(network.AP_IF)
# Close any existing connections
ap.active(False)
time.sleep(1)
# Create the access point
ap.active(True)
ap.config(
essid=ssid,
channel=2,
authmode=0,
)
while ap.active() == False:
pass
print('Connection successful')
print(ap.ifconfig())
print("mac: ", ap.config('mac'))
print("essid: ", ap.config('essid'))
print("channel: ", ap.config('channel'))
print("hidden: ", ap.config('hidden'))
print("authmode: ", ap.config('authmode'))
def web_page():
html = """<html><head><meta name="viewport" content="width=device-width, initial-scale=1"></head>
<body style="background-color:powderblue;"><h1 style="text-align:center; font-size:70px;color:#ed0e42;">Linuxhint.com</h1><h2 style="text-align:center; font-size:30px;">ESP32 Access Point </h2></body></html>"""
return html
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5)
while True:
conn, addr = s.accept()
print('Connection established from %s' % str(addr))
request = conn.recv(1024)
print('Content = %s' % str(request))
response = web_page()
conn.send(response)
conn.close()
The network is visible in my wifi settings:
<img width="341" alt="Screenshot 2023-03-21 at 12 27 49" src="https://user-images.githubusercontent.com/34808802/226605966-f9c60cd9-877e-467c-b932-f0846f8ce0c4.png">
But when I go to connect to it I get an error:

I am running on an ESP32.