Greetings,
I am working with serial mesh (nrfSDk 15.2 for mesh 3.1 with softdevice s132_nrf52_6.1.0) .
1. I followed the serial example available and its working.
2. I want to use serial mesh without Interactive pyACI, so tried with light switch server client example, I added serial part and can provision and the serial mesh is initialised and enabled.
After this I want to transmit string with nrf_mesh_serial_tx function, only when the client and server are binded with appkey and publication adrress is applied via the nrf mesh app.
I have two dk nrf51 and 52, for server(code I am using same as the example lightswitch server with serial intialisation and enabling) and client (as attached) respectively.
In server configuration app_key binding is not working as, in callback it is used to rest the node.
Please tell me if I am doing it right to achieve the communication without Interactive pyACI
Thanking you in advance
Best Regards
Deepa
*********** CLIENT*****************
#include <stdint.h>
#include <string.h>
/* HAL */
#include "boards.h"
#include "simple_hal.h"
#include "app_timer.h"
#include "mesh_opt_prov.h"
/* Core */
#include "nrf_mesh_config_core.h"
#include "nrf_mesh_gatt.h"
#include "nrf_mesh_configure.h"
#include "nrf_mesh.h"
#include "mesh_stack.h"
#include "device_state_manager.h"
#include "access_config.h"
/* Provisioning and configuration */
#include "mesh_provisionee.h"
#include "mesh_app_utils.h"
/* Models */
#include "generic_onoff_client.h"
/* Logging and RTT */
#include "log.h"
#include "rtt_input.h"
/* Example specific includes */
#include "app_config.h"
#include "nrf_mesh_config_examples.h"
#include "light_switch_example_common.h"
#include "example_common.h"
#include "ble_softdevice_support.h"
#include "example_network_config.h"
#include "network_setup_types.h"
#include "provisioner_helper.h"
#include "node_setup.h"
#ifndef NRF_MESH_SERIAL_ENABLE
#define NRF_MESH_SERIAL_ENABLE 1
#endif
#if NRF_MESH_SERIAL_ENABLE
#include "nrf_mesh_serial.h"
#endif
#define APP_STATE_OFF (0)
#define APP_STATE_ON (1)
#define APP_UNACK_MSG_REPEAT_COUNT (2)
static bool m_device_provisioned;
void nrf_mesh_rx_cb(const uint8_t* p_data, uint32_t length) {
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Rx received\r\n");
}
static void device_identification_start_cb(uint8_t attention_duration_s)
{
hal_led_mask_set(LEDS_MASK, false);
hal_led_blink_ms(BSP_LED_2_MASK | BSP_LED_3_MASK,
LED_BLINK_ATTENTION_INTERVAL_MS,
LED_BLINK_ATTENTION_COUNT(attention_duration_s));
}
static void provisioning_aborted_cb(void)
{
hal_led_blink_stop();
}
static void provisioning_complete_cb(void)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Successfully provisioned\n");
#if MESH_FEATURE_GATT_ENABLED
/* Restores the application parameters after switching from the Provisioning
* service to the Proxy */
gap_params_init();
conn_params_init();
#endif
dsm_local_unicast_address_t node_address;
dsm_local_unicast_addresses_get(&node_address);
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Node Address: 0x%04x \n", node_address.address_start);
hal_led_blink_stop();
hal_led_mask_set(LEDS_MASK, LED_MASK_STATE_OFF);
hal_led_blink_ms(LEDS_MASK, LED_BLINK_INTERVAL_MS, LED_BLINK_CNT_PROV);
}
static void node_reset(void)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- Node reset -----\n");
hal_led_blink_ms(LEDS_MASK, LED_BLINK_INTERVAL_MS, LED_BLINK_CNT_RESET);
/* This function may return if there are ongoing flash operations. */
mesh_stack_device_reset();
}
static void config_server_evt_cb(const config_server_evt_t * p_evt)
{
if (p_evt->type == CONFIG_SERVER_EVT_NODE_RESET)
{
node_reset();
}
}
static void app_config_client_event_cb(config_client_event_type_t event_type, const config_client_event_t * p_event, uint16_t length)
{
/* USER_NOTE: Do additional processing of config client events here if required */
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Config client event\n");
/* Pass events to the node setup helper module for further processing */
node_setup_config_client_event_process(event_type, p_event, length);
}
static void models_init_cb(void)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing and adding models\n");
ERROR_CHECK(config_client_init(app_config_client_event_cb));
}
static void mesh_init(void)
{
mesh_stack_init_params_t init_params =
{
.core.irq_priority = NRF_MESH_IRQ_PRIORITY_LOWEST,
.core.lfclksrc = DEV_BOARD_LF_CLK_CFG,
.core.p_uuid = NULL,
.models.models_init_cb = models_init_cb,
.models.config_server_cb = config_server_evt_cb
};
ERROR_CHECK(mesh_stack_init(&init_params, &m_device_provisioned));
#if NRF_MESH_SERIAL_ENABLE
ERROR_CHECK(nrf_mesh_serial_init(NULL));
#endif
}
static void initialize(void)
{
__LOG_INIT(LOG_SRC_APP | LOG_SRC_ACCESS | LOG_SRC_BEARER, LOG_LEVEL_INFO, LOG_CALLBACK_DEFAULT);
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- BLE Mesh Light Switch Client Demo -----\n");
ERROR_CHECK(app_timer_init());
hal_leds_init();
ble_stack_init();
#if MESH_FEATURE_GATT_ENABLED
gap_params_init();
conn_params_init();
#endif
mesh_init();
}
static void start(void)
{
if (!m_device_provisioned)
{
static const uint8_t static_auth_data[NRF_MESH_KEY_SIZE] = STATIC_AUTH_DATA;
mesh_provisionee_start_params_t prov_start_params =
{
.p_static_data = static_auth_data,
.prov_complete_cb = provisioning_complete_cb,
.prov_device_identification_start_cb = device_identification_start_cb,
.prov_device_identification_stop_cb = NULL,
.prov_abort_cb = provisioning_aborted_cb,
.p_device_uri = EX_URI_LS_CLIENT
};
ERROR_CHECK(mesh_provisionee_prov_start(&prov_start_params));
}
#if NRF_MESH_SERIAL_ENABLE
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Enabling serial interface...\n");
ERROR_CHECK(nrf_mesh_serial_enable());
#endif
mesh_app_uuid_print(nrf_mesh_configure_device_uuid_get());
ERROR_CHECK(mesh_stack_start());
hal_led_mask_set(LEDS_MASK, LED_MASK_STATE_OFF);
hal_led_blink_ms(LEDS_MASK, LED_BLINK_INTERVAL_MS, LED_BLINK_CNT_START);
}
int main(void)
{
initialize();
start();
char data[] = "\r\nHello from Nordic\r\n";
uint32_t result = nrf_mesh_serial_tx(data, sizeof(data));
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Send: %d\r\n", result);
for (;;)
{
(void)sd_app_evt_wait();
}
}