Skip to content

cpu/esp: implement ESP WiFi SoftAP mode#14117

Merged
benpicco merged 1 commit intoRIOT-OS:masterfrom
btcven:2020_05_22-esp_wifi_ap
Oct 25, 2020
Merged

cpu/esp: implement ESP WiFi SoftAP mode#14117
benpicco merged 1 commit intoRIOT-OS:masterfrom
btcven:2020_05_22-esp_wifi_ap

Conversation

@jeandudey
Copy link
Copy Markdown
Contributor

@jeandudey jeandudey commented May 22, 2020

Contribution description

This is an implementation of the ESP32 SoftAP mode using the esp_wifi_ap pseudomodule.

The clients connected to the AP work normally (they are reachable with ping6). As DHCP isn't implemented most OSes will struggle trying to get an IP from the ESP32 SoftAP.

Testing procedure

  • Use gnrc_networking example and add USEMODULE += esp_wifi_ap. Upon ESP32 initialization a WiFi AP is started with the default SSID RIOT_AP.
  • Use two ESP nodes, one ESP32 as AP and one ESP32/ESP8266 as station. Flash them gnrc_networking, for example
    USEMODULE=esp_wifi_ap make BOARD=esp32-wroom-32 -C examples/gnrc_networking flash PORT=/dev/ttyUSB0
    USEMODULE=esp_wifi make BOARD=esp8266 -C examples/gnrc_networking flash PORT=/dev/ttyUSB1
    
    The ESP32/ESP8266 in station mode should be able to connect, shown by message STA connected on the ESP32 AP. After that, it should be possible to ping in both directions.

Issues/PRs references

#14114

@jeandudey jeandudey requested a review from gschorcht as a code owner May 22, 2020 13:22
@jeandudey
Copy link
Copy Markdown
Contributor Author

jeandudey commented May 22, 2020

False positive? fixed dbb8853

cpu/esp_common/esp-wifi/esp_wifi_netdev.c:560: style (knownConditionTrueFalse): Condition '_esp_wifi_sta_connected==0' is always true

@benpicco benpicco added Area: cpu Area: CPU/MCU ports Type: new feature The issue requests / The PR implemements a new feature for RIOT labels May 24, 2020
@jeandudey jeandudey force-pushed the 2020_05_22-esp_wifi_ap branch from dbb8853 to 60778f5 Compare May 25, 2020 16:34
@jeandudey
Copy link
Copy Markdown
Contributor Author

Btw, what about using the mac as the SSID? e.g: RIOT_AP_aabbccddee?

@benpicco benpicco requested review from gschorcht and removed request for gschorcht June 27, 2020 17:35
@gschorcht
Copy link
Copy Markdown
Contributor

Is there any reason why the SoftAP is limited to ESP32? It should work in same way with ESP8266.

@gschorcht gschorcht added Platform: ESP Platform: This PR/issue effects ESP-based platforms Area: network Area: Networking Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation and removed Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation labels Jun 29, 2020
@jeandudey
Copy link
Copy Markdown
Contributor Author

Is there any reason why the SoftAP is limited to ESP32? It should work in same way with ESP8266.

The limitation is not having the hardware, I'll modify the code to see if a colleague can test it.

@gschorcht
Copy link
Copy Markdown
Contributor

Is there any reason why the SoftAP is limited to ESP32? It should work in same way with ESP8266.

The limitation is not having the hardware, I'll modify the code to see if a colleague can test it.

I will test it for you. Tomorrow at the latest, I'll review your changes and make suggestions on how to change them so that it also works with ESP8266. The background is that I already had a local implementation of the SoftAP a few months ago. However, I had not completed it and therefore I had not yet provided it as PR.

@jeandudey
Copy link
Copy Markdown
Contributor Author

@gschorcht I've dropped the ESP_WIFI_CHANNEL parameter as it causes the ESP32 to freeze when the selected channel is used, I've tested with esp32-wrover-kit and a generic esp32-wroom-32, it will hang after sending beacons I believe as increasing the becaon_interval makes the "time to freeze" a little bit larger.

Works fine if the ESP32 sets the channel alone.

@jeandudey jeandudey requested a review from gschorcht June 29, 2020 22:27
Copy link
Copy Markdown
Contributor

@gschorcht gschorcht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some remarks. I will test it later today.

@gschorcht
Copy link
Copy Markdown
Contributor

@gschorcht I've dropped the ESP_WIFI_CHANNEL parameter as it causes the ESP32 to freeze when the selected channel is used, I've tested with esp32-wrover-kit and a generic esp32-wroom-32, it will hang after sending beacons I believe as increasing the becaon_interval makes the "time to freeze" a little bit larger.

Works fine if the ESP32 sets the channel alone.

Indeed, in my local implementation, I didn't define the used channel.

@gschorcht
Copy link
Copy Markdown
Contributor

Btw, what about using the mac as the SSID? e.g: RIOT_AP_aabbccddee?

We could do it in that way to be able to divide multiple APs in same area, but only as default value. But it must be overridable in case a user wants to set up an ESS where all APs must have the same SSID.

@gschorcht
Copy link
Copy Markdown
Contributor

Tested with one ESP32 and one ESP8266:

  • If I use the ESP32 as AP and the ESP8266 as station works. I can ping in both directions. Probably, two ESP32s will also work.
  • If I use the ESP8266 as AP and ESP32 as station, the ESP32 station can connect to ESP8266 AP, but I can't ping.

@jeandudey
Copy link
Copy Markdown
Contributor Author

On a803312 I've added support for the auto-generated SSID using a common prefix. The default is: RIOT_AP_.

An static SSID can be specified by setting ESP_WIFI_SSID="RIOT_AP" or some other value, or to specify the prefix with ESP_WIFI_AP_PREFIX="ESP_"

Copy link
Copy Markdown
Contributor

@gschorcht gschorcht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new WiFi mode including its configuration parameters have to be documented in cpu/esp32/doc.txt as well as cpu/esp8266/doc.txt.

Copy link
Copy Markdown
Contributor

@gschorcht gschorcht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for nitpicking. Some small changes, which Travis CI pointed out, we could also clean up to improve the quality.

@jeandudey
Copy link
Copy Markdown
Contributor Author

Documentation for ESP32/ESP8266 added on edf7df7

@gschorcht gschorcht changed the title cpu/esp32: implement ESP32 SoftAP mode cpu/esp32: implement ESP WiFi SoftAP mode Jul 2, 2020
@benpicco
Copy link
Copy Markdown
Contributor

benpicco commented Sep 6, 2020

I'd say an AP with limitations is better than no AP at all.
I imagine a lot of use cases would only use the AP for initial configuration to allow for a convenient way to set the credentials of the network the esp should connect to.
For that this should be enough.

@jeandudey jeandudey force-pushed the 2020_05_22-esp_wifi_ap branch from 8c4b11f to 9643c8e Compare September 8, 2020 13:15
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Sep 23, 2020
Copy link
Copy Markdown
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, will test soon.

#ifdef MODULE_ESP_WIFI_AP
.ssid_hidden = ESP_WIFI_SSID_HIDDEN, /* don't make the AP visible */
.max_connection = ESP_WIFI_MAX_CONN, /* maximum number of connections */
.beacon_interval = 100, /* send beacon every 100 ms */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to be that often?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default is 100 ms for Espressif. Will add a configuration define for it though.

@benpicco
Copy link
Copy Markdown
Contributor

HAS_ESP_WIFI_AP also needs to be added to Kconfig

@jeandudey
Copy link
Copy Markdown
Contributor Author

Added the configuration value for the beacon interval, and it's documentation. Also added the Kconfig feature for esp_wifi_ap.

@benpicco
Copy link
Copy Markdown
Contributor

Nice, works like a charm!

esp8266

2020-09-25 02:20:33,245 # Iface  10  HWaddr: EE:FA:BC:5F:82:91  Channel: 0  Link: up 
2020-09-25 02:20:33,248 #           L2-PDU:1500  MTU:1500  HL:64  RTR  
2020-09-25 02:20:33,250 #           RTR_ADV  
2020-09-25 02:20:33,253 #           Source address length: 6
2020-09-25 02:20:33,256 #           Link type: wireless
2020-09-25 02:20:33,261 #           inet6 addr: fe80::ecfa:bcff:fe5f:8291  scope: link  VAL
2020-09-25 02:20:33,264 #           inet6 group: ff02::2
2020-09-25 02:20:33,267 #           inet6 group: ff02::1
2020-09-25 02:20:33,270 #           inet6 group: ff02::1:ff5f:8291
2020-09-25 02:20:33,270 #           
2020-09-25 02:20:33,273 #           Statistics for Layer 2
2020-09-25 02:20:33,276 #             RX packets 0  bytes 0
2020-09-25 02:20:33,281 #             TX packets 1 (Multicast: 1)  bytes 0
2020-09-25 02:20:33,284 #             TX succeeded 0 errors 0
2020-09-25 02:20:33,286 #           Statistics for IPv6
2020-09-25 02:20:33,289 #             RX packets 0  bytes 0
2020-09-25 02:20:33,294 #             TX packets 1 (Multicast: 1)  bytes 64
2020-09-25 02:20:33,298 #             TX succeeded 1 errors 0
2020-09-25 02:20:33,298 # 
> 2020-09-25 02:21:13,737 #  add 1
2020-09-25 02:21:13,737 # aid 1
2020-09-25 02:21:13,740 # station: 00:1f:1f:23:8b:b6 join, AID = 1
2020-09-25 02:21:13,744 # Station 00:1f:1f:23:8b:b6 join (AID=1)
2020-09-25 02:21:26,077 # ping fe80::c878:f490:a31f:2b8a
2020-09-25 02:21:26,113 # 12 bytes from fe80::c878:f490:a31f:2b8a%10: icmp_seq=0 ttl=64 time=26.588 ms
2020-09-25 02:21:27,188 # 12 bytes from fe80::c878:f490:a31f:2b8a%10: icmp_seq=1 ttl=64 time=101.143 ms
2020-09-25 02:21:28,122 # 12 bytes from fe80::c878:f490:a31f:2b8a%10: icmp_seq=2 ttl=64 time=34.749 ms
2020-09-25 02:21:28,122 # 
2020-09-25 02:21:28,125 # --- fe80::c878:f490:a31f:2b8a PING statistics ---
2020-09-25 02:21:28,130 # 3 packets transmitted, 3 packets received, 0% packet loss
2020-09-25 02:21:28,136 # round-trip min/avg/max = 26.588/54.160/101.143 ms

esp32

2020-09-25 02:23:48,480 # Iface  8  HWaddr: 3C:71:BF:9E:13:FD  Channel: 0  Link: up 
2020-09-25 02:23:48,484 #           L2-PDU:1500  MTU:1500  HL:64  RTR  
2020-09-25 02:23:48,486 #           RTR_ADV  
2020-09-25 02:23:48,488 #           Source address length: 6
2020-09-25 02:23:48,491 #           Link type: wireless
2020-09-25 02:23:48,497 #           inet6 addr: fe80::3e71:bfff:fe9e:13fd  scope: link  VAL
2020-09-25 02:23:48,499 #           inet6 group: ff02::2
2020-09-25 02:23:48,502 #           inet6 group: ff02::1
2020-09-25 02:23:48,506 #           inet6 group: ff02::1:ff9e:13fd
2020-09-25 02:23:48,507 #           
2020-09-25 02:23:48,510 #           Statistics for Layer 2
2020-09-25 02:23:48,513 #             RX packets 11  bytes 1827
2020-09-25 02:23:48,517 #             TX packets 2 (Multicast: 2)  bytes 0
2020-09-25 02:23:48,521 #             TX succeeded 0 errors 0
2020-09-25 02:23:48,523 #           Statistics for IPv6
2020-09-25 02:23:48,526 #             RX packets 9  bytes 1029
2020-09-25 02:23:48,530 #             TX packets 2 (Multicast: 2)  bytes 128
2020-09-25 02:23:48,534 #             TX succeeded 2 errors 0
2020-09-25 02:23:48,534 # 
2020-09-25 02:23:53,642 #  ping fe80::c878:f490:a31f:2b8a
2020-09-25 02:23:53,674 # 12 bytes from fe80::c878:f490:a31f:2b8a%8: icmp_seq=0 ttl=64 time=23.885 ms
2020-09-25 02:23:54,765 # 12 bytes from fe80::c878:f490:a31f:2b8a%8: icmp_seq=1 ttl=64 time=115.522 ms
2020-09-25 02:23:55,685 # 12 bytes from fe80::c878:f490:a31f:2b8a%8: icmp_seq=2 ttl=64 time=35.374 ms

Please squash!

@jeandudey jeandudey force-pushed the 2020_05_22-esp_wifi_ap branch from afb81c7 to bde5c64 Compare September 25, 2020 01:21
@jeandudey
Copy link
Copy Markdown
Contributor Author

@benpicco commits squashed 😉

I'm still worried only about the need to look on the packet header to filter it, as Gunar said:

Usually, this frame is simply passed to the GNRC stack or the lwIP stack. To implement a real AP we would have to handle the MAC frame and decide whether to pass it to upper layers or just send it back to the WiFi interface.

This can be replicated by sending a ping to a node that is connected to the AP from another node, it should give "Destination Unreachable" errors on the SoftAP node as I remember

@gschorcht
Copy link
Copy Markdown
Contributor

Nice, works like a charm!

I have to disagree, it doesn't work even if you can ping from an STA node to AP. Since multicast frames for sleeping STA nodes aren't cached by the AP, Neighbor Solicitation for other STA nodes does't work. Therefore STA nodes can't connect to each other. This means that only the communication from an STA node via the AP as router to the outer network, but not the communication between STA nodes inside the WiFi network which is a limitation I wouldn't expect if I have an AP.

I'd say an AP with limitations is better than no AP at all.

At the very least, this limitation would have to be very clearly documented.

@benpicco
Copy link
Copy Markdown
Contributor

We could also call it Client Isolation and mention that the feature can't be turned off 😉

But yea this limitation should be mentioned in doc.txt. I think for most use cases this is fine. I don't want to replace my router with an esp, but have a convenient way to set the credentials of the network it should connect to so I don't have to set them at compile time.

@jeandudey jeandudey force-pushed the 2020_05_22-esp_wifi_ap branch from bde5c64 to 98c0899 Compare September 27, 2020 23:27
This is an implementation of the ESP32 SoftAP mode using the
`esp_wifi_ap` pseudomodule.

Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
@jeandudey jeandudey force-pushed the 2020_05_22-esp_wifi_ap branch from 98c0899 to 295a366 Compare September 27, 2020 23:29
@jeandudey
Copy link
Copy Markdown
Contributor Author

Fixed the tables, and added a big warning for the AP Sleep bug (feature which can not be disabled 😉 ) of the SoftAP.

@benpicco benpicco added State: waiting for CI update State: The PR requires an Update to CI to be performed first and removed State: waiting for CI update State: The PR requires an Update to CI to be performed first labels Sep 30, 2020
@benpicco
Copy link
Copy Markdown
Contributor

benpicco commented Sep 30, 2020

@gschorcht are you fine with the warning?

@benpicco benpicco dismissed gschorcht’s stale review October 21, 2020 22:17

I'd say the comments have been addressed.

@benpicco benpicco added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 21, 2020
@benpicco benpicco merged commit b14e754 into RIOT-OS:master Oct 25, 2020
@jeandudey jeandudey deleted the 2020_05_22-esp_wifi_ap branch October 26, 2020 15:16
@jeandudey
Copy link
Copy Markdown
Contributor Author

Thanks for the review :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: cpu Area: CPU/MCU ports Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ESP Platform: This PR/issue effects ESP-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants