From 31245849fb1ac8227400ebd133a780c3d3e899ba Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 3 Mar 2020 23:38:33 +0100 Subject: [PATCH] examples/gnrc_border_router: add example for WiFi <-> esp_now BR This adds an example configuration to use the gnrc_border_router to route between a regular WiFi network and an esp_now network. All you need is an esp based board (esp8266, esp32). Configure the access data for your WiFi network in `Makefile.esp.conf`, then run make BOARD=esp32-wroom-32 USE_ETHOS=0 USE_ESP=1 flash term to turn a e.g. `esp32-wroom-32` into a boarder router. You can use other esp based boards as nodes in the network by flashing e.g. the `gnrc_networking` example. Be sure to add `CFLAGS += -DGNRC_IPV6_NIB_CONF_SLAAC=1` as otherwise your esp_now node will not receive a link-local IP address. --- examples/gnrc_border_router/Makefile | 31 ++++++++++++++----- .../gnrc_border_router/Makefile.board.dep | 11 +++++-- .../gnrc_border_router/Makefile.wifi.conf | 2 ++ 3 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 examples/gnrc_border_router/Makefile.wifi.conf diff --git a/examples/gnrc_border_router/Makefile b/examples/gnrc_border_router/Makefile index 00348ed2fe..8f2f6e8686 100644 --- a/examples/gnrc_border_router/Makefile +++ b/examples/gnrc_border_router/Makefile @@ -7,6 +7,18 @@ BOARD ?= samr21-xpro # This has to be the absolute path to the RIOT base directory: RIOTBASE ?= $(CURDIR)/../.. +# Default to using ethos for providing the uplink when not on native +UPLINK ?= ethos + +# Check if the selected Uplink is valid +ifeq (,$(filter ethos slip wifi,$(UPLINK))) + $(error Supported uplinks are `ethos`, `slip` and `wifi`) +endif + +# Set the SSID and password of your WiFi network here +WIFI_SSID ?= "Your_WiFi_name" +WIFI_PASS ?= "Your_secure_password" + # Include packages that pull up and auto-init the link layer. # NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present USEMODULE += gnrc_netdev_default @@ -24,8 +36,12 @@ USEMODULE += ps # configure the node as a RPL DODAG root when receiving a prefix. #USEMODULE += gnrc_rpl -# Optionally use DHCPv6 instead of UHCP -USE_DHCPV6 ?= 0 +# When using a WiFi uplink we should use DHCPv6 +ifeq (wifi,$(UPLINK)) + USE_DHCPV6 ?= 1 +else + USE_DHCPV6 ?= 0 +endif ifeq (1,$(USE_DHCPV6)) # include DHCPv6 client for 6LoWPAN border router @@ -35,10 +51,6 @@ else USEMODULE += gnrc_uhcpc endif -# Optionally use SLIP instead of ethos when not on native -# (added to USEMODULE in Makefile.board.dep) -USE_SLIP ?= 0 - # Use two network interfaces GNRC_NETIF_NUMOF := 2 @@ -60,14 +72,17 @@ IPV6_PREFIX ?= 2001:db8::/64 # communication and stdio over UART, but not on native, as native has a tap # interface towards the host. ifeq (,$(filter native,$(BOARD))) - ifeq (1,$(USE_SLIP)) + ifeq (slip,$(UPLINK)) # SLIP baudrate and UART device can be configured from make command SLIP_BAUDRATE ?= 115200 include $(CURDIR)/Makefile.slip.conf - else + else ifeq (ethos,$(UPLINK)) # ethos baudrate can be configured from make command ETHOS_BAUDRATE ?= 115200 include $(CURDIR)/Makefile.ethos.conf + else ifeq (wifi,$(UPLINK)) + # SSID and Password need to be configured + include $(CURDIR)/Makefile.wifi.conf endif else include $(CURDIR)/Makefile.native.conf diff --git a/examples/gnrc_border_router/Makefile.board.dep b/examples/gnrc_border_router/Makefile.board.dep index 7636d3482e..32fc82bde2 100644 --- a/examples/gnrc_border_router/Makefile.board.dep +++ b/examples/gnrc_border_router/Makefile.board.dep @@ -1,9 +1,16 @@ # Put board specific dependencies here ifeq (,$(filter native,$(BOARD))) - ifeq (1,$(USE_SLIP)) + ifeq (slip,$(UPLINK)) USEMODULE += slipdev_stdio - else + else ifeq (ethos,$(UPLINK)) USEMODULE += stdio_ethos + else ifeq (wifi,$(UPLINK)) + ifneq (,$(filter esp32 esp8266,$(CPU))) + USEMODULE += esp_wifi + USEMODULE += esp_now + else + $(error Only esp32 and esp8266 are currently supported) + endif endif else USEMODULE += socket_zep diff --git a/examples/gnrc_border_router/Makefile.wifi.conf b/examples/gnrc_border_router/Makefile.wifi.conf new file mode 100644 index 0000000000..5d34ef71a6 --- /dev/null +++ b/examples/gnrc_border_router/Makefile.wifi.conf @@ -0,0 +1,2 @@ +CFLAGS += -DESP_WIFI_SSID=\"$(WIFI_SSID)\" +CFLAGS += -DESP_WIFI_PASS=\"$(WIFI_PASS)\"