Skip to content

cpu/esp*: esp_now and esp_wifi cleanup#10929

Merged
MrKevinWeiss merged 9 commits intoRIOT-OS:masterfrom
gschorcht:esp_now_wifi_cleanup
Aug 1, 2019
Merged

cpu/esp*: esp_now and esp_wifi cleanup#10929
MrKevinWeiss merged 9 commits intoRIOT-OS:masterfrom
gschorcht:esp_now_wifi_cleanup

Conversation

@gschorcht
Copy link
Contributor

@gschorcht gschorcht commented Feb 2, 2019

Contribution description

This PR is a cleanup of modules esp_now and esp_wifi to get them working together, for example to realize a border router which connects an ESP-NOW based mesh network of ESP32 an ESP8266 nodes with an infrastructure mode WiFi network.

Testing procedure

Build a border router using project RIOT_ESP_NOW_WiFi_Border_Router and some ESP-NOW nodes. Follow the instructions in README.md.

Although the test could be performed on either ESP8266 nodes or ESP32 nodes only, a configuration is recommended in an ESP32 is used as border router and ESP8266s are used as ESP NOW nodes.
[Update] However, if an ESP8266 is used as a boundary router, RPL must not be enabled due to its limited RAM. After merging PR # 10981, the limited amount of RAM for ESP8266 should no longer be a problem.

Issues/PRs references

Since it cleans up esp_wifi for ESP32 as well as ESP8266, it depends on PR #9917.

@gschorcht gschorcht added Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation Platform: ESP Platform: This PR/issue effects ESP-based platforms Area: cpu Area: CPU/MCU ports labels Feb 17, 2019
@gschorcht gschorcht added this to the Release 2019.04 milestone Mar 3, 2019
@gschorcht gschorcht requested a review from smlng April 12, 2019 08:50
@gschorcht
Copy link
Contributor Author

@smlng The same as with PR #10883

@MrKevinWeiss
Copy link
Contributor

release status ping, should I change the milestone?

@gschorcht
Copy link
Contributor Author

@MrKevinWeiss I have to find some time to rebase it. I will try it in next days. And of course, someone would have to review it 😄

@MrKevinWeiss MrKevinWeiss self-requested a review June 17, 2019 07:34
@MrKevinWeiss
Copy link
Contributor

Great, when you do I will test and mercilessly bug @smlng for the review

@gschorcht gschorcht force-pushed the esp_now_wifi_cleanup branch 2 times, most recently from 2591165 to 6d0651e Compare June 24, 2019 12:52
@MrKevinWeiss MrKevinWeiss added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 25, 2019
@MrKevinWeiss
Copy link
Contributor

I just want to see if murdock is happy. I can try testing soon.

Copy link
Contributor

@MrKevinWeiss MrKevinWeiss left a comment

Choose a reason for hiding this comment

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

Well I don't know what I did but I followed the testing procedure and was able to ping6 back and forth with a esp border router and node using rpl (with this PR). I don't know if that counts as tested, I think it was only with the esp_now though.

@gschorcht
Copy link
Contributor Author

@MrKevinWeiss Most import is that both network interfaces esp_wifi and esp_now can be used simultaneously.

First, you should check on the border router whether it can connect to the configured WiFi AP.

[esp_wifi] associated with ssid whatever

Second, you should be able to ping another ESP-NOW node using network interface esp_now and any computer in your LAN using network interface esp_wifi at the same time.

I guess these both tests could also be done using examples/gnrc_networking

USEMODULE='esp_now esp_wifi' \
CFLAGS='-DESP_NOW_CHANNEL=<channel> -DESP_WIFI_SSID=\"<SSID>\" -DESP_WIFI_PASS=\"<passphrase>\"' \
make BOARD=... PORT=/dev/... flash

Please note, the channel used for ESP-NOW has to be the same as the channel used by your WiFi AP.

If you use the ESP-NOW to WiFi border router project and you configure a route to 2001:db8::/64 on your machine in the LAN using the link local unicast address of the WiFi interface of the border router, you should be able to ping the ESP-NOW nodes from your machine and vise versa.

@MrKevinWeiss
Copy link
Contributor

ping @smlng I would have like this for the release.

Copy link
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

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

LGTM code-wise, haven't tested myself but: @MrKevinWeiss if you're confident do the merge

@smlng smlng added Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines labels Jun 28, 2019
@MrKevinWeiss
Copy link
Contributor

OK. I will retest on Monday. If possible can you squash and fix the murdock errors?

@gschorcht
Copy link
Contributor Author

@MrKevinWeiss I fixed the problems in TravisCI and Murdock but I didn't squash yet so that you are able to see how I had them to fix.

@MrKevinWeiss
Copy link
Contributor

Many thanks. It is squash time!


#ifdef __cplusplus
}
#endif /* CPU_CONF_H */
Copy link
Contributor

Choose a reason for hiding this comment

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

(comment wrong)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ups

@gschorcht
Copy link
Contributor Author

gschorcht commented Jul 30, 2019

@MrKevinWeiss I tested it again with two ESP32s in another environment where I had problems too as long as the LAN doesn't use global unicast addresses 2000::/3.

That is, as long as ESP32's WiFi interface and the machine in the LAN have only link local addresses fe80::/10, pinging the ESP-NOW network from LAN does not work. After setting the global unicast adresses by hand

ESP32: ifconfig 8 add unicast 2001:db9::1/64
LAN node: ip -6 addr add 2001:db9::2/64 dev eth0

pinging the ESP-NOW node behind the border router worked without problems. Of course, The route to 2001:db8::/64 has to be set ip -6 route add 2001:db8::/64 via 2001:db9::1 dev eth0.

Did you have global unicast addresses in your LAN?

@MrKevinWeiss
Copy link
Contributor

Tested again with the additional CFLAGS += -DGNRC_NETIF_IPV6_ADDRS_NUMOF=4 and it still doesn't work.

All I want to do is ping the esp node from the esp border router when the esp border router is connected to wifi. If I enter the wrong wifi ssid I can ping the esp node and if the wifi ssid is correct it cannot ping.

@gschorcht
Copy link
Contributor Author

gschorcht commented Jul 30, 2019

@MrKevinWeiss Did you use the global unicast address 2001:db8:: or the link local address fe80:: for pinging the ESP-NOW node from the border router? In latter case, you would have to specify the interface that should be use for pinging.

@gschorcht
Copy link
Contributor Author

gschorcht commented Jul 30, 2019

@MrKevinWeiss I set up a completly new test environment which exactly corresponds to your test environment:

+-------+      +---------+     +-------+     +---------+
| Linux |------| WiFi AP |-----| ESP32 |-----|  ESP32  |
+-------+      +---------+     |  BR   |     | ESP-NOW |
                               +-------+     +---------+

On border router:

> ifconfig
Iface  7  HWaddr: 30:AE:A4:18:7A:3D 
          L2-PDU:249 MTU:1280  HL:64  RTR  
          RTR_ADV  6LO  Source address length: 6
          Link type: wireless
          inet6 addr: fe80::32ae:a4ff:fe18:7a3d  scope: local  VAL
          inet6 addr: 2001:db8::32ae:a4ff:fe18:7a3d  scope: global  VAL
          ...

Iface  8  HWaddr: 30:AE:A4:18:7A:3C  Link: up 
          L2-PDU:1500 MTU:1500  HL:64  RTR  
          Source address length: 6
          Link type: wireless
          inet6 addr: fe80::32ae:a4ff:fe18:7a3c  scope: local  VAL
          inet6 addr: fd22:5c78:9ead:8:32ae:a4ff:fe18:7a3c  scope: global  VAL
          inet6 addr: fd35:ed4d:6c92:0:32ae:a4ff:fe18:7a3c  scope: global  VAL
          ...

On ESP-NOW node:

> ifconfig
Iface  9  HWaddr: 30:AE:A4:41:60:F9 
          L2-PDU:249 MTU:1280  HL:64  RTR  
          RTR_ADV  6LO  Source address length: 6
          Link type: wireless
          inet6 addr: fe80::32ae:a4ff:fe41:60f9  scope: local  VAL
          inet6 addr: 2001:db8::32ae:a4ff:fe41:60f9  scope: global  VAL

Pinging border router from Linux:

$ ping6 fd22:5c78:9ead:8:32ae:a4ff:fe18:7a3c
PING fd22:5c78:9ead:8:32ae:a4ff:fe18:7a3c(fd22:5c78:9ead:8:32ae:a4ff:fe18:7a3c) 56 data bytes
64 bytes from fd22:5c78:9ead:8:32ae:a4ff:fe18:7a3c: icmp_seq=3 ttl=64 time=62.2 ms
64 bytes from fd22:5c78:9ead:8:32ae:a4ff:fe18:7a3c: icmp_seq=4 ttl=64 time=85.7 ms
64 bytes from fd22:5c78:9ead:8:32ae:a4ff:fe18:7a3c: icmp_seq=5 ttl=64 time=206 ms

Pinging ESP-NOW node from ESP32 border router:

> ping6 2001:db8::32ae:a4ff:fe41:60f9
12 bytes from 2001:db8::32ae:a4ff:fe41:60f9: icmp_seq=0 ttl=64 time=7.681 ms
12 bytes from 2001:db8::32ae:a4ff:fe41:60f9: icmp_seq=1 ttl=64 time=7.565 ms
12 bytes from 2001:db8::32ae:a4ff:fe41:60f9: icmp_seq=2 ttl=64 time=6.103 ms
> ping6 fe80::32ae:a4ff:fe41:60f9

--- fe80::32ae:a4ff:fe41:60f9 PING statistics ---
3 packets transmitted, 0 packets received, 100% packet loss
> ping6 fe80::32ae:a4ff:fe41:60f9%7
12 bytes from fe80::32ae:a4ff:fe41:60f9: icmp_seq=0 ttl=64 time=7.452 ms
12 bytes from fe80::32ae:a4ff:fe41:60f9: icmp_seq=1 ttl=64 time=6.515 ms
12 bytes from fe80::32ae:a4ff:fe41:60f9: icmp_seq=2 ttl=64 time=6.069 ms

On Linux:

$ sudo ip -6 route add 2001:db8::/64 via fd22:5c78:9ead:8:32ae:a4ff:fe18:7a3c
$ ping6 2001:db8::32ae:a4ff:fe41:60f9
PING 2001:db8::32ae:a4ff:fe41:60f9(2001:db8::32ae:a4ff:fe41:60f9) 56 data bytes
64 bytes from 2001:db8::32ae:a4ff:fe41:60f9: icmp_seq=1 ttl=63 time=35.9 ms
64 bytes from 2001:db8::32ae:a4ff:fe41:60f9: icmp_seq=2 ttl=63 time=41.5 ms
64 bytes from 2001:db8::32ae:a4ff:fe41:60f9: icmp_seq=3 ttl=63 time=63.4 ms

So the environment looks exactly like yours. I can ping the ESP-NOW node with connected WiFi interface either using its global unicast address 2001:db8::32ae:a4ff:fe41:60f9 or its link local address when specifying the interface fe80::32ae:a4ff:fe41:60f9%7.

After setting the route on the Linux machine to 2001:db8::/64, I can also ping the ESP-NOW node directly from my Linux machine.

Sorry, when I'm nerving a bit, but could you double check whether you have tried in exactly this way., please. There is no reason why it should not work in your environment.

Update: No matter whether RPL is activated on BR or not. RPL is not required for direct links between the border router and the ESP-NOW node.

@MrKevinWeiss
Copy link
Contributor

I know, I am sorry that I cannot get it but I really would like for anyone else to test to confirm.
@smlng @MichelRottleuthner @leandrolanzieri
Anyone try this out. I just cannot ack the testing if it isn't working for me.

@gschorcht gschorcht force-pushed the esp_now_wifi_cleanup branch from a8fe593 to 97bb337 Compare July 31, 2019 11:54
@gschorcht
Copy link
Contributor Author

Rebased

@MichelRottleuthner
Copy link
Contributor

I tested with the freshly rebased version and the following setup: PC<->WiFiAP<->ESPbr<->ESPnow

Both ESPs used gnrc_networking, programed as follows:
ESPbr:

USEMODULE='esp_now esp_wifi' \
CFLAGS='-DGNRC_IPV6_NIB_CONF_SLAAC=1 -DGNRC_NETIF_IPV6_ADDRS_NUMOF=4 -DESP_NOW_CHANNEL=11 -DESP_WIFI_SSID=\"somessid\" -DESP_WIFI_PASS=\"somepw\"' \
make BOARD=esp32-wroom-32 PORT=/dev/ttyUSB0 all flash term

ESPnow:

USEMODULE='esp_now' CFLAGS='-DESP_NOW_CHANNEL=11' make all flash term BOARD=esp32-wroom-32 PORT=/dev/ttyUSB1

Notes:
GNRC_NETIF_IPV6_ADDRS_NUMOF=4 was added because the ESPbr already needs to store two addresses it gets from the WiFiAP plus its own LLA.
Without GNRC_IPV6_NIB_CONF_SLAAC=1 all the addresses on ESPbr's esp_wifi interface were marked as tentative so pinging other hosts from ESPbr didn't work.

Setup of the nodes:
ESPnow: nothing

ESPbr:

ifconfig 9 add 2001:db8::1
rpl init 9
rpl root 1 2001:db8::1

PC:

*connect to same WiFiAP as ESPbr*
ip -6 route add 2001:db8::/64 via <global_IPv6_addr_of_ESPbr> dev <wireless_interface>

Using that setup everything worked: I could ping every host from every other host in the setup.

I found one (unrelated?) problem where I left the ESPbr in this setup running without using it and after around 40 minutes it printed the following message before the shell stopped responding to input:
W (1422385) [ wifi]: no timer handle. Though, I didn't manage to reproduce it yet.

Nonetheless I can confirm that this PR indeed enabled using esp_now and esp_wifi on the same node, so I will add the tested label.

@MichelRottleuthner MichelRottleuthner added the Reviewed: 3-testing The PR was tested according to the maintainer guidelines label Jul 31, 2019
@MichelRottleuthner
Copy link
Contributor

I'll leave merging to @MrKevinWeiss or @smlng as I didn't have the slightest look at the code ;)

@gschorcht
Copy link
Contributor Author

@MichelRottleuthner Many thanks for testing it . Theses are really good news. I'm really happy that someone else than me could get it working 🚀

The problem you saw might have the same reason as the problem I described in issue #11941. I'm already investigating it and it seems that it is caused to be caused by using mutexes in WiFi interface callbacks within interrupt context. I have already changed it in a test version which seems to be working stable, also with multiheap enabled.

@MrKevinWeiss MrKevinWeiss dismissed their stale review August 1, 2019 07:53

My setup was bad

@MrKevinWeiss MrKevinWeiss added the Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines label Aug 1, 2019
@MrKevinWeiss
Copy link
Contributor

Many thanks @MichelRottleuthner now that we confirmed it was my setup I am happy to merge it. Also the documentation seems good.

@MrKevinWeiss MrKevinWeiss merged commit 2be1323 into RIOT-OS:master Aug 1, 2019
@gschorcht
Copy link
Contributor Author

Thank you all for your support and your patience 😄

@gschorcht gschorcht deleted the esp_now_wifi_cleanup branch August 1, 2019 07:57
@gschorcht gschorcht restored the esp_now_wifi_cleanup branch September 18, 2019 16:15
@gschorcht gschorcht deleted the esp_now_wifi_cleanup branch September 18, 2019 16:52
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 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 Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants