Hi Zhe Weng,
Welcome to NuttX mailing list!
What a great first message here! It worked perfectly:
In the ESP32:
nsh> ?
help usage: help [-v] [<cmd>]
. cd exec kill pwd true
[ cp exit ls reboot truncate
? cmp false mkdir rm uname
addroute dirname fdinfo mkrd rmdir umount
alias dd free mount route unset
unalias delroute help mv set uptime
arp df hexdump nslookup sleep usleep
basename dmesg ifconfig pidof source xd
break echo ifdown printf test
cat env ifup ps time
Builtin Apps:
dhcpd dhcpd_stop nsh renew telnetd
dhcpd_start iptables ping sh wapi
nsh> ifconfig
wlan0 Link encap:Ethernet HWaddr bc:dd:c2:d4:a9:ec at RUNNING mtu 1504
inet addr:192.168.0.7 DRaddr:192.168.0.1 Mask:255.255.255.0
wlan1 Link encap:Ethernet HWaddr bc:dd:c2:d4:a9:ed at DOWN mtu 1504
inet addr:0.0.0.0 DRaddr:0.0.0.0 Mask:0.0.0.0
nsh> dhcpd_start wlan1
nsh> wapi psk wlan1 mypasswd 3
nsh> wapi essid wlan1 nuttxap 1
nsh> route
SEQ TARGET NETMASK ROUTER
1. 0.0.0.0 0.0.0.0 10.0.0.1
nsh> delroute 0.0.0.0 0.0.0.0
nsh> addroute 0.0.0.0 0.0.0.0 192.168.0.1
nsh> route
SEQ TARGET NETMASK ROUTER
1. 0.0.0.0 0.0.0.0 192.168.0.1
nsh> iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
nsh>
In the computer connected to ESP32 board with NuttX SoftAP:
$ ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 5666 bytes 547514 (547.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5666 bytes 547514 (547.5 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp0s20f3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.4 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::162b:ec2:fe98:87 prefixlen 64 scopeid 0x20<link>
ether ec:63:d7:0b:ef:af txqueuelen 1000 (Ethernet)
RX packets 127217 bytes 146539379 (146.5 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 37079 bytes 23604536 (23.6 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
alan@dev:~$ ping 10.0.0.1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=3.28 ms
64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=9.72 ms
64 bytes from 10.0.0.1: icmp_seq=3 ttl=64 time=2.63 ms
64 bytes from 10.0.0.1: icmp_seq=4 ttl=64 time=18.9 ms
64 bytes from 10.0.0.1: icmp_seq=5 ttl=64 time=4.82 ms
64 bytes from 10.0.0.1: icmp_seq=6 ttl=64 time=4.45 ms
64 bytes from 10.0.0.1: icmp_seq=7 ttl=64 time=3.57 ms
64 bytes from 10.0.0.1: icmp_seq=8 ttl=64 time=3.87 ms
64 bytes from 10.0.0.1: icmp_seq=9 ttl=64 time=2.20 ms
64 bytes from 10.0.0.1: icmp_seq=10 ttl=64 time=4.74 ms
64 bytes from 10.0.0.1: icmp_seq=11 ttl=64 time=8.60 ms
64 bytes from 10.0.0.1: icmp_seq=12 ttl=64 time=11.5 ms
^C
--- 10.0.0.1 ping statistics ---
12 packets transmitted, 12 received, 0% packet loss, time 11018ms
rtt min/avg/max/mdev = 2.201/6.527/18.917/4.688 ms
alan@dev:~$ ping 192.168.0.1
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=63 time=19.1 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=63 time=21.7 ms
64 bytes from 192.168.0.1: icmp_seq=3 ttl=63 time=94.5 ms
64 bytes from 192.168.0.1: icmp_seq=4 ttl=63 time=23.8 ms
^C
--- 192.168.0.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 19.125/39.788/94.484/31.622 ms
alan@dev:~$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=63.0 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=111 time=51.4 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=111 time=55.0 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=111 time=64.3 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=111 time=52.8 ms
^C
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 51.428/57.314/64.327/5.322 ms
I will create a wifishare board config and a Documentation/ explaining
how to do it.
Thank you very much!
BR,
Alan
On 10/17/23, 翁喆 <[email protected]> wrote:
> Hi Robert & Alan,
>
> Although I don't have an ESP32 board yet, you may need NAT applied on wlan0,
> I guess.
>
> Under Alan's configuration, there are two subnets: the 192.168.0.0/24 and
> 10.0.0.0/24. With only routing and ipforward, the ping from 10.0.0.x (take
> 10.0.0.2 as an example) normally can reach the router (192.168.0.1), but the
> router doesn't know where 10.0.0.2 is, and it may just reply via its default
> route (packet may be sent to the internet, or dropped by the router's
> firewall).
>
> The router's default route (normally the Internet)
> ↑ reply: 192.168.0.1 -> 10.0.0.2
> ----------
> | Router |
> ----------
> ↑ ping: 10.0.0.2 -> 192.168.0.1
> ----------
> | ESP32 | <- Just forward
> ----------
> ↑ ping: 10.0.0.2 -> 192.168.0.1
> ----------
> | Device |
> ----------
>
> You may try NAT with CONFIG_NET_NAT and CONFIG_SYSTEM_IPTABLES enabled,
> using the command 'iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE' to
> apply NAT to all outbound traffic on wlan0, then you may get:
>
> ----------
> | Router |
> ----------
> ↑ ping: 192.168.0.7 -> 192.168.0.1
> ↓ reply: 192.168.0.1 -> 192.168.0.7
> ----------
> | ESP32 | <- Doing NAT, mapping 10.0.0.2 to 192.168.0.7
> ----------
> ↑ ping: 10.0.0.2 -> 192.168.0.1
> ↓ reply: 192.168.0.1 -> 10.0.0.2
> ----------
> | Device |
> ----------
>
> Hope this may help.
>
> BTW, It's my first time replying to this mailing list, I'm not sure if I'm
> doing it correctly.
>
> Best regards,
> Zhe Weng
> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件!
> This e-mail and its attachments contain confidential information from
> XIAOMI, which is intended only for the person or entity whose address is
> listed above. Any use of the information contained herein in any way
> (including, but not limited to, total or partial disclosure, reproduction,
> or dissemination) by persons other than the intended recipient(s) is
> prohibited. If you receive this e-mail in error, please notify the sender by
> phone or email immediately and delete it!******/#
>