Part Number: CC2652R
Other Parts Discussed in Thread: ENERGYTRACE
Hello,
I'm working with the Simple Mesh Node example and I would like to implement a task that provisions a device and enables communication between devices without using the UART interface. The callback function exectutes, but when I try to turn on a LED of another device by pressing a button it switches its own LED, therefore I think there is no communication between the two devices that I'm using and each device is on a different network. How can I proceed in order to have only one network so that the devices can be able to communicate ?
Thank you very much,
Alexandra Goloubkov
/*
* start_provisioning.c
*
* Created on: 19 janv. 2023
* Author: alexa
*/
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <math.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Event.h>
#include <ti/sysbios/knl/Queue.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/BIOS.h>
#include <start_provisioning.h>
#include <ti/drivers/GPIO.h>
#include "ti_drivers_config.h"
#include "simple_mesh_node.h"
#include "ti_ble_mesh_config.h"
#include "simple_mesh_node_menu.h"
#include <net/buf.h>
#include <include/bluetooth/mesh/access.h>
#include "static_prov.h"
#define START_PROV_TASK_PRIORITY 3
#ifndef START_PROV_STACK_SIZE
#define START_PROV_STACK_SIZE 2248
#endif
#define GROUP_ADDR 0xc000
extern void start_prov_init(void);
uint8_t button_state = 0;
uint16_t addr;
uint8_t led_state;
uint16_t mesh_device_own_addr = DEVICE_OWN_ADDRESS;
//static const uint16_t app_idx;
Task_Struct start_prov_Task;
uint8_t start_prov_Stack[START_PROV_STACK_SIZE];
Semaphore_Struct semstart_prov_Task_Struct;
Semaphore_Handle semstart_prov_Task_Handle;
struct bt_mesh_model *model;
struct bt_mesh_msg_ctx *ctx;
struct net_buf_simple *buf;
void provision_done_cbk()
{
GPIO_write(CONFIG_GPIO_LED_0,1);
}
void btn1Fxn_cbk(uint_least8_t index)
{
Semaphore_post(semstart_prov_Task_Handle);
}
void turnLed(uint8_t on_off)
{
if (on_off)
{
GPIO_write(CONFIG_GPIO_LED_1,1);
}
else
{
GPIO_write(CONFIG_GPIO_LED_1,0);
}
}
void button_pressed_cb(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
// check own address
/*(ctx->addr == mesh_device_own_addr)*/
if (ctx->addr == mesh_device_own_addr) {
return;
}
led_state = net_buf_simple_pull_u8(buf);
turnLed(led_state);
}
void start_prov_init(void)
{
GPIO_init();
GPIO_setConfig(CONFIG_GPIO_BTN1,
GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING);
GPIO_setCallback(CONFIG_GPIO_BTN1,btn1Fxn_cbk );
GPIO_enableInt(CONFIG_GPIO_BTN1);
GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
}
static void start_prov_taskFxn(UArg a0, UArg a1)
{
start_prov_init();
bleApp_stackInit();
MeshApp_init(DEVICE_OWN_ADDRESS, UNPROVISIONED_BEACON);
/* MeshApp_static_provisioning(DEVICE_OWN_ADDRESS, BT_MESH_KEY_UNUSED);*/
for (;;)
{
Semaphore_pend(semstart_prov_Task_Handle, BIOS_WAIT_FOREVER);
button_state = 1;
MeshApp_button_pressed(button_state);
}
}
void start_prov_CreateTask(void)
{
bleStack_createTasks();
k_sys_work_q_init(NULL);
Semaphore_Params semParams;
Task_Params taskParams;
Task_Params_init(&taskParams);
taskParams.stack = start_prov_Stack;
taskParams.stackSize = START_PROV_STACK_SIZE;
taskParams.priority = START_PROV_TASK_PRIORITY;
Task_construct(&start_prov_Task, start_prov_taskFxn, &taskParams, NULL);
Semaphore_Params_init(&semParams);
Semaphore_construct(&semstart_prov_Task_Struct, 0, &semParams);
semstart_prov_Task_Handle = Semaphore_handle(
&semstart_prov_Task_Struct);
}
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <math.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Event.h>
#include <ti/sysbios/knl/Queue.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/BIOS.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/mesh.h>
#include <bt_le_porting_layer.h>
#include <start_provisioning.h>
#include <ti/drivers/GPIO.h>
#include "ti_drivers_config.h"
#include <simple_mesh_node.h>
#include "ti_ble_mesh_config.h"
#include "simple_mesh_node_menu.h"
#include <net/buf.h>
#include <include/bluetooth/mesh/access.h>
#include "static_prov.h"
#define START_PROV_TASK_PRIORITY 3
#ifndef START_PROV_STACK_SIZE
#define START_PROV_STACK_SIZE 2248
#endif
#define GROUP_ADDR 0xc000
extern void start_prov_init(void);
uint8_t button_state = 0;
uint16_t addr;
uint8_t led_state;
uint16_t mesh_device_own_addr = DEVICE_OWN_ADDRESS;
//static const uint16_t app_idx;
Task_Struct start_prov_Task;
uint8_t start_prov_Stack[START_PROV_STACK_SIZE];
Semaphore_Struct semstart_prov_Task_Struct;
Semaphore_Handle semstart_prov_Task_Handle;
struct bt_mesh_model *model;
struct bt_mesh_msg_ctx *ctx;
struct net_buf_simple *buf;
void provision_done_cbk()
{
GPIO_write(CONFIG_GPIO_LED_0,1);
}
void btn1Fxn_cbk(uint_least8_t index)
{
Semaphore_post(semstart_prov_Task_Handle);
}
void turnLed(uint8_t on_off)
{
if (on_off)
{
GPIO_write(CONFIG_GPIO_LED_1,1);
}
else
{
GPIO_write(CONFIG_GPIO_LED_1,0);
}
}
void button_pressed_cb(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
// check own address
/*(ctx->addr == mesh_device_own_addr)*/
if (ctx->addr == mesh_device_own_addr) {
return;
}
led_state = net_buf_simple_pull_u8(buf);
turnLed(led_state);
}
void start_prov_init(void)
{
GPIO_init();
GPIO_setConfig(CONFIG_GPIO_BTN1,
GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING);
GPIO_setCallback(CONFIG_GPIO_BTN1,btn1Fxn_cbk );
GPIO_enableInt(CONFIG_GPIO_BTN1);
GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
}
static void start_prov_taskFxn(UArg a0, UArg a1)
{
start_prov_init();
bleApp_stackInit();
MeshApp_init(DEVICE_OWN_ADDRESS, UNPROVISIONED_BEACON);
/* MeshApp_static_provisioning(DEVICE_OWN_ADDRESS, BT_MESH_KEY_UNUSED);*/
for (;;)
{
Semaphore_pend(semstart_prov_Task_Handle, BIOS_WAIT_FOREVER);
button_state = 1;
MeshApp_button_pressed(button_state);
}
}
void start_prov_CreateTask(void)
{
bleStack_createTasks();
k_sys_work_q_init(NULL);
Semaphore_Params semParams;
Task_Params taskParams;
Task_Params_init(&taskParams);
taskParams.stack = start_prov_Stack;
taskParams.stackSize = START_PROV_STACK_SIZE;
taskParams.priority = START_PROV_TASK_PRIORITY;
Task_construct(&start_prov_Task, start_prov_taskFxn, &taskParams, NULL);
Semaphore_Params_init(&semParams);
Semaphore_construct(&semstart_prov_Task_Struct, 0, &semParams);
semstart_prov_Task_Handle = Semaphore_handle(
&semstart_prov_Task_Struct);
}
