Skip to content

Commit

Permalink
Part of theheraldproject#113. MESH advertising broken by CONFIG_BT_CE…
Browse files Browse the repository at this point in the history
…NTRAL=y

Signed off by: Adam Fowler <[email protected]>
  • Loading branch information
adamfowleruk committed Apr 15, 2022
1 parent 7b68603 commit dab11d0
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 359 deletions.
14 changes: 9 additions & 5 deletions config/zephyr/receiver.conf
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# Receiver (i.e. scanner, central) settings
CONFIG_BT_CENTRAL=y
# ^^^ The above causes MESH advertising to fail if ANY connections are open (E.g. Herald beacon payload reading)

# GATT Client settings
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_GATT_DM=y
# # GATT Client settings
# CONFIG_BT_GATT_CLIENT=y
# CONFIG_BT_GATT_DM=y

# Scanning
CONFIG_BT_SCAN=y
# # Scanning
# CONFIG_BT_SCAN=y

# Issue #50 to prevent stack overflow in CPU (was 8192, defaults to 2200 in Zephyr)
CONFIG_BT_RX_STACK_SIZE=6144
# ^ Needs to be higher on nRF52832DK for some reason

# Since v2.1 Required for NUS Service alongside BT Scanning - too high in testing
# CONFIG_BT_RX_STACK_SIZE=8192


# TODO figure out what in this file causes MESH to fail immediately
2 changes: 1 addition & 1 deletion herald-mesh-relay/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ target_sources(app PRIVATE
#${HERALD_SOURCES_MBEDTLS}
${HERALD_SOURCES_MESH}
src/main.cpp
src/lb_service_handler.c
# src/lb_service_handler.c
src/model_handler.c
src/herald_handler.cpp
)
Expand Down
25 changes: 0 additions & 25 deletions herald-mesh-relay/include/lb_service_handler.h

This file was deleted.

26 changes: 22 additions & 4 deletions herald-mesh-relay/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ CONFIG_BT_PERIPHERAL=y
CONFIG_BT_SETTINGS=y

CONFIG_BT_EXT_ADV=y
CONFIG_BT_EXT_ADV_MAX_ADV_SET=2
# This defaults to 1!
CONFIG_BT_EXT_ADV_MAX_ADV_SET=5
# CONFIG_BT_EXT_ADV_MAX_ADV_SET=2
CONFIG_BT_MAX_CONN=3

# Disable unused Bluetooth features
Expand All @@ -122,22 +124,32 @@ CONFIG_BT_CTLR_CHAN_SEL_2=n
CONFIG_BT_CTLR_MIN_USED_CHAN=n
CONFIG_BT_CTLR_PRIVACY=n

# Use the BLE 5.0 2M phy for more ADV_EXT throughput
# TODO verify it's actually being used
CONFIG_BT_CTLR_PHY_2M=y

# Bluetooth mesh configuration
CONFIG_BT_MESH=y
CONFIG_BT_MESH_RELAY=y
CONFIG_BT_MESH_FRIEND=y
CONFIG_BT_MESH_ADV_BUF_COUNT=13
CONFIG_BT_MESH_TX_SEG_MAX=10
CONFIG_BT_MESH_PB_GATT=y
# The following is needed to set mesh model and publishing config from a phone
CONFIG_BT_MESH_GATT_PROXY=y

# TODO replace the below with a Herald NFC provisioner instead
CONFIG_BT_MESH_DK_PROV=y

# The following is separate from BT_EXT_ADV
CONFIG_BT_MESH_ADV_EXT=y

# Bluetooth mesh models
CONFIG_BT_MESH_ONOFF_SRV=y

# Enable the LBS service
CONFIG_BT_LBS=y
CONFIG_BT_LBS_POLL_BUTTON=y
CONFIG_BT_LBS=n
CONFIG_BT_LBS_POLL_BUTTON=n

# CONFIG_USE_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y
Expand All @@ -154,4 +166,10 @@ CONFIG_BT_MESH_DEBUG_ACCESS=y
CONFIG_BT_MESH_DEBUG_MODEL=y
CONFIG_BT_MESH_DEBUG_TRANS=n
CONFIG_BT_MESH_DEBUG_NET=n
CONFIG_BT_MESH_DEBUG_CRYPTO=n
CONFIG_BT_MESH_DEBUG_CRYPTO=n


# For issues with advertising failing:-
# CONFIG_BT_DEBUG_HCI_DRIVER=y
# CONFIG_BT_DEBUG_HCI_CORE=y
CONFIG_BT_DEBUG_CONN=y
138 changes: 69 additions & 69 deletions herald-mesh-relay/src/herald_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
// #include "../../herald/herald.h" // This is convenient, but leads to large
// binaries!
#include "herald/ble/ble_sensor_configuration.h"
#include "herald/ble/zephyr/concrete_ble_receiver.h"
#include "herald/ble/zephyr/concrete_ble_transmitter.h"
#include "herald/ble/zephyr/nordic_uart/nordic_uart_sensor_delegate.h"
// #include "herald/ble/zephyr/concrete_ble_receiver.h"
// #include "herald/ble/zephyr/concrete_ble_transmitter.h"
// #include "herald/ble/zephyr/nordic_uart/nordic_uart_sensor_delegate.h"
#include "herald/datatype/date.h"
#include "herald/datatype/immediate_send_data.h"
#include "herald/datatype/location.h"
Expand Down Expand Up @@ -107,72 +107,72 @@ void herald_entry() {
using namespace herald::payload::extended;

// Create Herald sensor array
ZephyrContextProvider zcp;
Context ctx(zcp, zcp.getLoggingSink(), zcp.getBluetoothStateManager());
// using CT =
// Context<ZephyrContextProvider,ZephyrLoggingSink,BluetoothStateManager>;

// Disable receiver / scanning mode - we're just transmitting our value
BLESensorConfiguration config = ctx.getSensorConfiguration(); // copy ctor
config.scanningEnabled = true; // To see other nearby BLE devices
// config.advertisingEnabled = true; // default
ctx.setSensorConfiguration(config);

ConcreteExtendedDataV1 extendedData;
extendedData.addSection(ExtendedDataSegmentCodesV1::TextPremises,
erinsStakehouse.name);

// TODO get this from configuration of the MESH element (Nav beacon model)
payload::beacon::ConcreteBeaconPayloadDataSupplierV1 pds(
erinsStakehouse.country, erinsStakehouse.state, erinsStakehouse.code,
extendedData);

// this is unusual, but required. Really we should log activity to serial BLE
// or similar
DummyDelegate appDelegate;
SensorDelegateSet sensorDelegates(appDelegate);

ConcreteBLESensor ble(ctx, ctx.getBluetoothStateManager(), pds,
sensorDelegates);
SensorArray sa(ctx, pds, ble);

// Start array (and thus start advertising)
sa.start();

int iter = 0;
// APP_DBG("got iter!");
// k_sleep(K_SECONDS(2));
Date last;
// APP_DBG("got last!");
// k_sleep(K_SECONDS(2));
int delay = 250; // KEEP THIS SMALL!!! This is how often we check to see if
// anything needs to happen over a connection.

APP_DBG("Entering herald iteration loop");
k_sleep(K_SECONDS(2));
while (1) {
k_sleep(K_MSEC(delay));
Date now;
if (iter > 40 /* && iter < 44 */) { // some delay to allow us to see
// advertising output
// You could only do first 3 iterations so we can see the older log
// messages without continually scrolling through log messages
APP_DBG("Calling Sensor Array iteration");
// k_sleep(K_SECONDS(2));
sa.iteration(now - last);
}

if (0 == iter % (5000 / delay)) {
APP_DBG("herald thread still running. Iteration: %d", iter);
// runner.run(Date()); // Note: You may want to do this less or more
// regularly depending on your requirements
APP_ERR("Memory pages free in Data Arena: %d",
herald::datatype::Data::getArena().pagesFree());
}

last = now;
++iter;
}
// ZephyrContextProvider zcp;
// Context ctx(zcp, zcp.getLoggingSink(), zcp.getBluetoothStateManager());
// // using CT =
// // Context<ZephyrContextProvider,ZephyrLoggingSink,BluetoothStateManager>;

// // Disable receiver / scanning mode - we're just transmitting our value
// BLESensorConfiguration config = ctx.getSensorConfiguration(); // copy ctor
// config.scanningEnabled = true; // To see other nearby BLE devices
// // config.advertisingEnabled = true; // default
// ctx.setSensorConfiguration(config);

// ConcreteExtendedDataV1 extendedData;
// extendedData.addSection(ExtendedDataSegmentCodesV1::TextPremises,
// erinsStakehouse.name);

// // TODO get this from configuration of the MESH element (Nav beacon model)
// payload::beacon::ConcreteBeaconPayloadDataSupplierV1 pds(
// erinsStakehouse.country, erinsStakehouse.state, erinsStakehouse.code,
// extendedData);

// // this is unusual, but required. Really we should log activity to serial BLE
// // or similar
// DummyDelegate appDelegate;
// SensorDelegateSet sensorDelegates(appDelegate);

// ConcreteBLESensor ble(ctx, ctx.getBluetoothStateManager(), pds,
// sensorDelegates);
// SensorArray sa(ctx, pds, ble);

// // Start array (and thus start advertising)
// sa.start();

// int iter = 0;
// // APP_DBG("got iter!");
// // k_sleep(K_SECONDS(2));
// Date last;
// // APP_DBG("got last!");
// // k_sleep(K_SECONDS(2));
// int delay = 250; // KEEP THIS SMALL!!! This is how often we check to see if
// // anything needs to happen over a connection.

// APP_DBG("Entering herald iteration loop");
// k_sleep(K_SECONDS(2));
// while (1) {
// k_sleep(K_MSEC(delay));
// Date now;
// if (iter > 40 /* && iter < 44 */) { // some delay to allow us to see
// // advertising output
// // You could only do first 3 iterations so we can see the older log
// // messages without continually scrolling through log messages
// APP_DBG("Calling Sensor Array iteration");
// // k_sleep(K_SECONDS(2));
// sa.iteration(now - last);
// }

// if (0 == iter % (5000 / delay)) {
// APP_DBG("herald thread still running. Iteration: %d", iter);
// // runner.run(Date()); // Note: You may want to do this less or more
// // regularly depending on your requirements
// APP_ERR("Memory pages free in Data Arena: %d",
// herald::datatype::Data::getArena().pagesFree());
// }

// last = now;
// ++iter;
// }
}

/** MARK: HERALD HANDLER PUBLIC HEADER METHODS **/
Expand Down
Loading

0 comments on commit dab11d0

Please sign in to comment.