1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests: add NimBLE/esp_wifi coexistence test

This commit is contained in:
Gunar Schorcht 2022-08-19 07:44:46 +02:00
parent f848f668e3
commit 4b0d920e9d
3 changed files with 194 additions and 0 deletions

View File

@ -0,0 +1,68 @@
include ../Makefile.tests_common
# If no BOARD is found in the environment, use this default:
BOARD ?= esp32-wroom-32
# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/../..
# We use the xtimer and the shell in this example
USEMODULE += shell
# works only for ESP32x SoC that have WiFi and BLE
FEATURES_REQUIRED += esp_ble
FEATURES_REQUIRED += esp_wifi
# use ESP WiFi in station mode as network interface
USEMODULE += esp_wifi
# configure and use Nimble
USEPKG += nimble
USEMODULE += nimble_scanner
USEMODULE += nimble_scanlist
# Include packages that pull up and auto-init the link layer.
# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present
USEMODULE += netdev_default
USEMODULE += auto_init_gnrc_netif
# Enable single interface optimization.
# Remove this if more than one interface is present
USEMODULE += gnrc_netif_single
# Activate ICMPv6 error messages
USEMODULE += gnrc_icmpv6_error
# Specify the mandatory networking module for a IPv6 routing node
USEMODULE += gnrc_ipv6_router_default
# Add a routing protocol
USEMODULE += gnrc_rpl
USEMODULE += auto_init_gnrc_rpl
# Additional networking modules that can be dropped if not needed
USEMODULE += gnrc_icmpv6_echo
USEMODULE += gnrc_udp_cmd
# Add also the shell, some shell commands
USEMODULE += shell
USEMODULE += shell_commands
USEMODULE += ps
USEMODULE += netstats_l2
USEMODULE += netstats_ipv6
USEMODULE += netstats_rpl
# Optionally include DNS support. This includes resolution of names at an
# upstream DNS server and the handling of RDNSS options in Router Advertisements
# to auto-configure that upstream DNS server.
# USEMODULE += sock_dns # include DNS client
# USEMODULE += gnrc_ipv6_nib_dns # include RDNSS option handling
# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
DEVELHELP ?= 1
# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1
EXTERNAL_BOARD_DIRS += $(RIOTBASE)/tests/external_board_dirs/esp-ci-boards
include $(RIOTBASE)/Makefile.include
# Set a custom channel if needed
include $(RIOTMAKE)/default-radio-settings.inc.mk

View File

@ -0,0 +1,20 @@
# About
This application tests the coexistence of Bluetooth and WiFi interface.
For that purpose it uses the `NimBLE` BLE stack as a scanner and the
ESP32x WiFi interface simultaneously.
# Usage
Comile and flash the application with command
```
CFLAGS='-DESP_WIFI_SSID=\"myssid\" -DESP_WIFI_PASS=\"mypass\"'
BOARD=esp32-wroom-32 make -C tests/nimble_esp_wifi_coexist flash term
```
Once the test application is flashed and the WiFi connection is established,
ping the node from the host with command
```
sudo ping6 fe80::xxxx:xxxx:xxxx:xxxx%eth0 -i 0.01 -s 1280
```
to produce network load and execute the command `scan` on the node.
The scan should still work.

View File

@ -0,0 +1,106 @@
/*
* Copyright (C) 2019 Freie Universität Berlin
* 2022 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup examples
* @{
*
* @file
* @brief Example for using NimBLE as a BLE scanner and ESP WiFi in coexistence
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Gunar Schorcht <gunar@schorcht.net>
*
* @}
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "msg.h"
#include "timex.h"
#include "ztimer.h"
#include "shell.h"
#include "nimble_scanner.h"
#include "nimble_scanlist.h"
#define MAIN_QUEUE_SIZE (8)
static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
/* default scan interval */
#define DEFAULT_SCAN_INTERVAL_MS 30
/* default scan duration (1s) */
#define DEFAULT_DURATION_MS (1 * MS_PER_SEC)
int _cmd_scan(int argc, char **argv)
{
uint32_t timeout = DEFAULT_DURATION_MS;
if ((argc == 2) && (memcmp(argv[1], "help", 4) == 0)) {
printf("usage: %s [timeout in ms]\n", argv[0]);
return 0;
}
if (argc >= 2) {
timeout = atoi(argv[1]);
}
nimble_scanlist_clear();
printf("Scanning for %"PRIu32" ms now ...\n", timeout);
nimble_scanner_start();
ztimer_sleep(ZTIMER_MSEC, timeout);
nimble_scanner_stop();
puts("Done, results:");
nimble_scanlist_print();
puts("");
return 0;
}
static const shell_command_t _commands[] = {
{ "scan", "trigger a BLE scan", _cmd_scan },
{ NULL, NULL, NULL }
};
int main(void)
{
puts("NimBLE Scanner Example Application");
puts("Type `scan help` for more information");
/* in this example, we want Nimble to scan 'full time', so we set the
* window equal the interval */
nimble_scanner_cfg_t params = {
.itvl_ms = DEFAULT_SCAN_INTERVAL_MS,
.win_ms = DEFAULT_SCAN_INTERVAL_MS,
#if IS_USED(MODULE_NIMBLE_PHY_CODED)
.flags = NIMBLE_SCANNER_PHY_1M | NIMBLE_SCANNER_PHY_CODED,
#else
.flags = NIMBLE_SCANNER_PHY_1M,
#endif
};
/* initialize the nimble scanner */
nimble_scanlist_init();
nimble_scanner_init(&params, nimble_scanlist_update);
/* we need a message queue for the thread running the shell in order to
* receive potentially fast incoming networking packets */
msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);
puts("RIOT network stack example application");
/* start shell */
puts("All up, running the shell now");
char line_buf[SHELL_DEFAULT_BUFSIZE];
shell_run(_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
return 0;
}