Test: merge ble mesh node and provioner in console

This commit is contained in:
Lu Chang Jie 2020-08-21 19:59:20 +08:00 committed by He Yin Ling
parent 789119262b
commit 63d2a19925
46 changed files with 785 additions and 2341 deletions

View file

@ -221,7 +221,7 @@ ESP-BLE-MESH Examples
* :example_file:`ESP-BLE-MESH and Wi-Fi Coexistence <bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/tutorial/BLE_Mesh_WiFi_Coexist_Example_Walkthrough.md>` - an example that demonstrates the Wi-Fi and Bluetooth (BLE/BR/EDR) coexistence feature of {IDF_TARGET_NAME}. Simply put, users can use the Wi-Fi while operating Bluetooth, see :example:`example code <bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist>`. * :example_file:`ESP-BLE-MESH and Wi-Fi Coexistence <bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/tutorial/BLE_Mesh_WiFi_Coexist_Example_Walkthrough.md>` - an example that demonstrates the Wi-Fi and Bluetooth (BLE/BR/EDR) coexistence feature of {IDF_TARGET_NAME}. Simply put, users can use the Wi-Fi while operating Bluetooth, see :example:`example code <bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist>`.
* ESP-BLE-MESH Node Console - an example that implements BLE Mesh node basic features. Within this example a node can be scanned and provisioned by Provisioner and reply to get/set message from Provisioner, see :example:`example node code <bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_node>` and :example:`example Provisioner code <bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_provisioner>`. * ESP-BLE-MESH Node Console - an example that implements BLE Mesh node basic features. Within this example a node can be scanned and provisioned by Provisioner and reply to get/set message from Provisioner, see :example:`example node code <bluetooth/esp_ble_mesh/ble_mesh_console>`.
.. _esp-ble-mesh-demo-videos: .. _esp-ble-mesh-demo-videos:

View file

@ -222,7 +222,7 @@ ESP-BLE-MESH 示例
* :example_file:`Wi-Fi 和 ESP-BLE-MESH 共存 <bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/tutorial/BLE_Mesh_WiFi_Coexist_Example_Walkthrough.md>` - 该示例用于演示 Wi-Fi 和 ESP-BLE-MESH 共存的功能。简而言之,用户可在运行 ESP-BLE-MESH 时使用 Wi-Fi示例请见 :example:`example code <bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist>` * :example_file:`Wi-Fi 和 ESP-BLE-MESH 共存 <bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/tutorial/BLE_Mesh_WiFi_Coexist_Example_Walkthrough.md>` - 该示例用于演示 Wi-Fi 和 ESP-BLE-MESH 共存的功能。简而言之,用户可在运行 ESP-BLE-MESH 时使用 Wi-Fi示例请见 :example:`example code <bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist>`
* ESP-BLE-MESH 节点控制台 - 该演示实现 ESP-BLE-MESH 节点的基本功能。在演示中Provisioner 可以扫描、验证节点,节点可以回复 Provisioner 的获取/设置消息,示例请见::example:`example node code <bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_node>` 和 :example:`example provisioner code <bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_provisioner>`。 * ESP-BLE-MESH 节点控制台 - 该演示实现 ESP-BLE-MESH 节点的基本功能。在演示中,node and Provisioner 可以扫描、验证节点,节点可以回复 Provisioner 的获取/设置消息,示例请见::example:`example node code <bluetooth/esp_ble_mesh/ble_mesh_console>`。
.. _esp-ble-mesh-demo-videos: .. _esp-ble-mesh-demo-videos:

View file

@ -3,4 +3,4 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake) include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(ble_mesh_console_node) project(ble_mesh_console)

View file

@ -3,7 +3,7 @@
# project subdirectory. # project subdirectory.
# #
PROJECT_NAME := ble_mesh_console_node PROJECT_NAME := ble_mesh_console
COMPONENT_ADD_INCLUDEDIRS := components/include COMPONENT_ADD_INCLUDEDIRS := components/include

View file

@ -0,0 +1,166 @@
# The Document of ESP32 BLE_MESH Commands
## Overall Command
* `bmreg`: Provisioner/node register callback
* Example: `bmreg`
* Result: `Bm:Reg,OK`
* `bminit`: Provisioner/node initialize
* `-m`: `mesh modle`
* Example: `bminit -m 0x0001`
* Result: `Bm:Init,OK`
* `bmpbind`: Provisioner binds Appkey with local model
* `-a`: `<appkey index>:appkey index`
* `-e`: `<element address>element address`
* `-n`: `<network index>:network index`
* `-m`: `<model id>:model id`
* `-c`: `<model id>:company id`
* Example: `bmpbind -a 0 -e 0x01 -m 0x1001 -n 0x00`
* Result: `provisioning:AppKeyBind,OK`
* `bmpdev`: Provisioner add/delete unprovisioned device
* `-z`: `action type <add/delete>`
* `-d`: `device address`
* `-u`: `device uuid`
* `-a`: `address type`
* `-f`: `address flag`
* `-b`: `used bearer`
* `-o`: `oob information`
* Example: `bmpdev -z add -d bt_mac -b -1 -a 0`
* Result: `provisioner:DevAdd/Del,OK`
* `bmoob`: Provisioner/node config OOB parameters
* `-s`: `Static OOB value`
* `-l`: `Static OOB value length`
* `-x`: `Maximum size of Output OOB`
* `-o`: `Supported Output OOB Actions`
* `-y`: `Maximum size of Input OOB`
* `-i`: `Supported Input OOB Actions`
* `-p`: `start address assigned by provisioner`
* Example: `bmoob -o -0 -x 0`
* Result: `OOB:Load,OK`
* `bmpbearer`: Enable/disable provisioner different bearer
* `-b`: `bearer supported`
* `-e`: `enable or disable bearer`
* Example: `bmpbearer -b 1 -e 1`
* Result: `provisioner:EnBearer,OK`
* `bmnbearer`: Enable/disable node different bearer
* `-b`: `bearer supported`
* `-e`: `enable or disable bearer`
* Example: `bmnbearer -b 1 -e 1`
* Result: `Node:EnBearer,OK`
* `bmpkey`: Add/Delete NetKey and AppKey of Provisioner
* `-z`: `<action type>:add app key or network key`
* `-n`: `<net key index>:network key index`
* `-k`: `<key>:appkey or network`
* `-a`: `<app key index>:appkey index`
* Example: `bmpkey -z netkey -n 1 -k <network_key>`
* Result: `provisioner:NetKeyAdd,OK`
* `bmccm`: BLE Mesh configuration client model operations
* `-z`: `<action>:action type`:add or del client model
* `-x`: `<state>:set state`
* `-o`: `<opcode>:message opcode`
* `-u`: `<address>:unicast address`
* `-n`: `<network>:net work index`
* `-i`: `<index>:appkey index`
* `-r`: `<relay>:relay statue`
* `-t`: `<transmit>:relay transmit`
* `-c`: `<cid>:company id`
* `-v`: `<value>:value`
* `-a`: `<address>:address`
* `-m`: `<mod id>:model id`
* Example: `bmccm -z reg`
* Result: `ConfigClient:OK`
* `bmgocm`: BLE Mesh onoff client model operations
* `-z`: `<action>:action type`: on or off client model
* `-o`: `<opcode>:message opcode`
* `-u`: `<address>:unicast address`
* `-n`: `<netkey index>:network key index`
* `-a`: `<index>:appkey index`
* `-r`: `<role>:role`
* `-t`: `<time>:time to complete state transition`
* `-e`: `<optional>:whether optional parameters included`
* `-s` : `<state>:present onoff state`
* `-a`: `<address>:address`
* `-i`: `<identifier>:transaction identifier`
* `-d`: `<delay>:indicate message execution delay`
* Example: `bmgocm -z reg`
* Result: `GenONOFFClient:Reg,OK`
* `bmnreset`: Reset node to become an unprovisioned device
* Example: `bmnreset`
* Result: `Node:Reset`
* `bmpublish`: BLE Mesh model publication
* `-d`: `<data>:message data`
* `-o`: `<opcode>:operation opcode`
* `-m`: `<module>:module published to`
* `-r`: `<role>:device role`
* `-a`: `<address>:unicast address`
* `-i`: `<app key>:app key index`
* `-p`: `<period>:period`
* Example: `bmpublish -d 1 -o 0x8204 -m 0x1000 -r 0 -a 1 -p 0 -i 0`
* Result: `PublishSend,OK`
* `bmnnwk`: An unprovisioned device enters the mesh network and becomes a node without the provisioning procedure
* `-k`: `<net key>:network key`
* `-n`: `<net index>:network key index`
* `-u`: `<unicast address>:unicast address`
* `-d`: `<device key>:device key`
* `-a`: `<appkey>:app key`
* `-i`: `<app key>:app key index`
* `-g`: `<group address>:group address`
* Example: `bnnnwk -k 0x1000 -n 1 -u 0x0010 -a 0x%s -d0x%s -i 0 -g 0xC000`
* Result: `Provisioning:Success,%d`
* `bmpaddn`: Provisioner add device's information into the mesh database while unprovisioned device enter mesh network automatically
* `-o`: `<oob info>:oob information`
* `-a`: `<unicast address>:unicast address`
* `-e`: `<element num>:element num`
* `-n`: `<net index>:net index`
* `-d`: `<device key>:device key`
* `-u`: `<device uuid>:device uuid`
* Example: `bmpaddn -o -0x0 -a %s -e 1 -n 1 -d 0x%s -u 0x%s`
* Result: `Provisioner:AddNodeInfo,OK`
* `bmcperf`: BLE Mesh client test performance
* `-z`: `<action>:action type`:init/get/destroy/percent
* `-s`: `<test size>:test size`
* `-n`: `<node number>:node number`
* `-l`: `<test number>:ttl`
* Example: `bmcperf -z init -n 1 -s %d -l 7`
* Result: `VendorPerfTest:InitStatistics,OK`
* `bmperf`: BLE Mesh vendor server model performance test
* `-z`: `<action>:action type`:init/get/destroy/percent
* `-p`: `<package>:package number`
* Example: `bmsperf -z init -p %d`
* Result: `Node:InitStatistics,OK`
* `bmtpcvm`: BLE Mesh vendor client model performance test
* `-z`: `<action>:action type`:init or start
* `-p`: `<byte>:playload byte`
* `-n`: `<number>:test number`
* `-o`: `<opcode>:opcode`
* `-u`: `<address>:unicast address`
* `-t`: `<ttl>:ttl`
* `-a`: `<appkey>:appkey index`
* `-i`: `<network key>:network key index`
* `-d`: `<role>:device role`
* Example: `bmtpcvm -z start -p %d -n %d -o 0xC302C4 -u %s -t 7 -a 0 -i 1 -d 1`
* Result: `VendorModel:SendPackage,Finish`
* `bmtxpower`: Provisioner/node set tx power or rx sensitivity"
* `-z`: `<action>:action type`:set tx power or rx sensitivity
* `-t`: `<power>:tx power or sense`
* Example: `bmtxpower -z tx -t %d`
* Result: `Node:SetPower,OK`

View file

@ -1,12 +0,0 @@
set(srcs "ble_mesh_adapter.c"
"ble_mesh_cfg_srv_model.c"
"ble_mesh_console_lib.c"
"ble_mesh_console_main.c"
"ble_mesh_console_system.c"
"ble_mesh_register_node_cmd.c"
"ble_mesh_register_server_cmd.c"
"ble_mesh_reg_gen_onoff_client_cmd.c"
"register_bluetooth.c")
idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS ".")

View file

@ -1,165 +0,0 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "ble_mesh_adapter.h"
esp_ble_mesh_model_t *ble_mesh_get_model(uint16_t model_id)
{
esp_ble_mesh_model_t *model = NULL;
switch (model_id) {
case ESP_BLE_MESH_MODEL_ID_CONFIG_SRV:
model = &config_server_models[0];
break;
case ESP_BLE_MESH_MODEL_ID_CONFIG_CLI:
model = &config_client_models[0];
break;
case ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV:
model = &gen_onoff_srv_models[1];
break;
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
// as server
case ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_CLI:
model = &gen_onoff_cli_models[2];
break;
#endif
case ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_CLI:
model = &test_perf_cli_models[0];
break;
case ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_SRV:
model = &test_perf_srv_models[0];
break;
}
return model;
}
esp_ble_mesh_comp_t *ble_mesh_get_component(uint16_t model_id)
{
esp_ble_mesh_comp_t *comp = NULL;
switch (model_id) {
case ESP_BLE_MESH_MODEL_ID_CONFIG_SRV:
comp = &config_server_comp;
break;
case ESP_BLE_MESH_MODEL_ID_CONFIG_CLI:
comp = &config_client_comp;
break;
case ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV:
comp = &gen_onoff_srv_comp;
break;
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
case ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_CLI:
comp = &gen_onoff_cli_comp;
break;
#endif
case ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_CLI:
comp = &test_perf_cli_comp;
break;
case ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_SRV:
comp = &test_perf_srv_comp;
break;
}
return comp;
}
void ble_mesh_node_init(void)
{
uint16_t i;
for (i = 0; i < NODE_MAX_GROUP_CONFIG; i++) {
ble_mesh_node_prestore_params[i].net_idx = 0xFFFF;
ble_mesh_node_prestore_params[i].unicast_addr = 0xFFFF;
}
ble_mesh_node_sema = xSemaphoreCreateMutex();
if (!ble_mesh_node_sema) {
ESP_LOGE(TAG, "%s init fail, mesh node semaphore create fail", __func__);
}
}
void ble_mesh_set_node_prestore_params(uint16_t netkey_index, uint16_t unicast_addr)
{
uint16_t i;
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY);
for (i = 0; i < NODE_MAX_GROUP_CONFIG; i++) {
if (ble_mesh_node_prestore_params[i].net_idx != 0xFFFF && ble_mesh_node_prestore_params[i].unicast_addr != 0xFFFF) {
ble_mesh_node_prestore_params[i].net_idx = netkey_index;
ble_mesh_node_prestore_params[i].unicast_addr = unicast_addr;
}
}
xSemaphoreGive(ble_mesh_node_sema);
}
void ble_mesh_node_statistics_get(void)
{
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY);
ESP_LOGI(TAG, "statistics:%d,%d\n", ble_mesh_node_statistics.statistics, ble_mesh_node_statistics.package_num);
xSemaphoreGive(ble_mesh_node_sema);
}
int ble_mesh_node_statistics_accumultate(uint8_t *data, uint32_t value, uint16_t type)
{
uint16_t i;
uint16_t sequence_num = (data[0] << 8) | data[1];
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY);
for (i = 0; i < ble_mesh_node_statistics.total_package_num; i++) {
if (ble_mesh_node_statistics.package_index[i] == sequence_num) {
xSemaphoreGive(ble_mesh_node_sema);
return 1;
}
}
// package type wrong
if (data[2] != type) {
xSemaphoreGive(ble_mesh_node_sema);
return 1;
}
for (i = 0; i < ble_mesh_node_statistics.total_package_num; i++) {
if (ble_mesh_node_statistics.package_index[i] == 0) {
ble_mesh_node_statistics.package_index[i] = sequence_num;
ble_mesh_node_statistics.package_num += 1;
ble_mesh_node_statistics.statistics += value;
break;
}
}
xSemaphoreGive(ble_mesh_node_sema);
return 0;
}
int ble_mesh_node_statistics_init(uint16_t package_num)
{
uint16_t i;
ble_mesh_node_statistics.package_index = malloc(sizeof(uint16_t) * package_num);
ble_mesh_node_statistics.total_package_num = package_num;
if (ble_mesh_node_statistics.package_index == NULL) {
ESP_LOGE(TAG, " %s, %d malloc fail\n", __func__, __LINE__);
return 1;
}
ble_mesh_node_statistics.package_num = 0;
for (i = 0; i < package_num; i++) {
ble_mesh_node_statistics.package_index[i] = 0;
}
return 0;
}
void ble_mesh_node_statistics_destroy(void)
{
if (ble_mesh_node_statistics.package_index != NULL) {
free(ble_mesh_node_statistics.package_index);
}
}

View file

@ -1,97 +0,0 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _BLE_MESH_ADAPTER_H_
#define _BLE_MESH_ADAPTER_H_
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "ble_mesh_console_lib.h"
#include "ble_mesh_cfg_srv_model.h"
#define TAG "ble_mesh_node_console"
typedef enum {
VENDOR_MODEL_PERF_OPERATION_TYPE_GET = 1,
VENDOR_MODEL_PERF_OPERATION_TYPE_SET,
VENDOR_MODEL_PERF_OPERATION_TYPE_SET_UNACK
} ble_mesh_perf_operation_type;
typedef struct {
uint8_t current;
uint8_t previous;
char *name;
} ble_mesh_node_status;
typedef struct {
uint32_t statistics;
uint32_t package_num;
uint16_t *package_index;
uint32_t total_package_num;
} ble_mesh_node_statistics_t;
ble_mesh_node_statistics_t ble_mesh_node_statistics;
extern SemaphoreHandle_t ble_mesh_node_sema;
#define arg_int_to_value(src_msg, dst_msg, message) do { \
if (src_msg->count != 0) {\
ESP_LOGD(TAG, "\n%s, %s\n", __func__, message);\
dst_msg = src_msg->ival[0];\
} \
} while(0) \
#define ble_mesh_node_get_value(index, key, value) do { \
uint16_t _index = 0; \
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY); \
for (_index = 0; _index < NODE_MAX_GROUP_CONFIG; _index) { \
if (node_set_prestore_params[_index].key == value) { \
break; \
} \
} \
index = _index; \
xSemaphoreGive(ble_mesh_node_sema); \
} while(0) \
#define ble_mesh_node_set_state(status) do { \
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY); \
node_status.previous = node_status.current; \
node_status.current = status; \
xSemaphoreGive(ble_mesh_node_sema); \
}while(0) \
#define ble_mesh_node_get_state(status) do { \
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY); \
status = node_status.current; \
xSemaphoreGive(ble_mesh_node_sema); \
}while(0) \
#define ble_mesh_callback_check_err_code(err_code, message) do { \
if (err_code == ESP_OK) { \
ESP_LOGI(TAG, "%s,OK\n", message); \
} else { \
ESP_LOGE(TAG, "%s,Fail,%d\n", message, err_code); \
} \
}while(0) \
void ble_mesh_node_init(void);
void ble_mesh_set_node_prestore_params(uint16_t netkey_index, uint16_t unicast_addr);
esp_ble_mesh_model_t *ble_mesh_get_model(uint16_t model_id);
esp_ble_mesh_comp_t *ble_mesh_get_component(uint16_t model_id);
void ble_mesh_node_statistics_get(void);
int ble_mesh_node_statistics_accumultate(uint8_t *data, uint32_t value, uint16_t type);
int ble_mesh_node_statistics_init(uint16_t package_num);
void ble_mesh_node_statistics_destroy(void);
#endif //_BLE_MESH_ADAOTER_H_

View file

@ -1,180 +0,0 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "esp_timer.h"
#include "ble_mesh_adapter.h"
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
typedef struct {
struct arg_str *action_type;
struct arg_int *op_en;
struct arg_int *unicast_address;
struct arg_int *onoff_state;
struct arg_int *trans_id;
struct arg_int *trans_time;
struct arg_int *delay;
struct arg_int *opcode;
struct arg_int *appkey_idx;
struct arg_int *role;
struct arg_int *net_idx;
struct arg_end *end;
} ble_mesh_gen_onoff_state_t;
ble_mesh_gen_onoff_state_t gen_onoff_state;
void ble_mesh_register_gen_onoff_client_command(void);
void ble_mesh_generic_onoff_client_model_cb(esp_ble_mesh_generic_client_cb_event_t event,
esp_ble_mesh_generic_client_cb_param_t *param);
void ble_mesh_register_gen_onoff_client(void)
{
ble_mesh_register_gen_onoff_client_command();
}
void ble_mesh_generic_onoff_client_model_cb(esp_ble_mesh_generic_client_cb_event_t event,
esp_ble_mesh_generic_client_cb_param_t *param)
{
uint32_t opcode = param->params->opcode;
ESP_LOGD(TAG, "enter %s: event is %d, error code is %d, opcode is 0x%x\n",
__func__, event, param->error_code, opcode);
switch (event) {
case ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT: {
switch (opcode) {
case ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_GET:
if (param->error_code == ESP_OK) {
ESP_LOGI(TAG, "GenOnOffClient:GetStatus,OK,%d", param->status_cb.onoff_status.present_onoff);
} else {
ESP_LOGE(TAG, "GenOnOffClient:GetStatus,Fail,%d", param->error_code);
}
break;
default:
break;
}
break;
}
case ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT: {
switch (opcode) {
case ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET:
if (param->error_code == ESP_OK) {
ESP_LOGI(TAG, "GenOnOffClient:SetStatus,OK,%d", param->status_cb.onoff_status.present_onoff);
} else {
ESP_LOGE(TAG, "GenOnOffClient:SetStatus,Fail,%d", param->error_code);
}
break;
case ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK:
if (param->error_code == ESP_OK) {
ESP_LOGI(TAG, "GenOnOffClient:SetUNACK,OK");
} else {
ESP_LOGE(TAG, "GenOnOffClient:SetUNACK,Fail,%d", param->error_code);
}
break;
default:
break;
}
break;
}
case ESP_BLE_MESH_GENERIC_CLIENT_PUBLISH_EVT: {
if (param->error_code == ESP_OK) {
ESP_LOGI(TAG, "GenOnOffClient:Publish,OK");
} else {
ESP_LOGE(TAG, "GenOnOffClient:Publish,Fail,%d", param->error_code);
}
break;
}
case ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT:
ESP_LOGE(TAG, "GenOnOffClient:TimeOut,%d", param->error_code);
break;
case ESP_BLE_MESH_GENERIC_CLIENT_EVT_MAX:
ESP_LOGE(TAG, "GenONOFFClient:InvalidEvt,%d", param->error_code);
break;
default:
break;
}
ESP_LOGD(TAG, "exit %s \n", __func__);
}
int ble_mesh_generic_onoff_client_model(int argc, char **argv)
{
int err = ESP_OK;
esp_ble_mesh_generic_client_set_state_t gen_client_set;
esp_ble_mesh_generic_client_get_state_t gen_client_get;
esp_ble_mesh_client_common_param_t onoff_common = {
.msg_timeout = 0,
.ctx.send_ttl = 7,
};
ESP_LOGD(TAG, "enter %s\n", __func__);
int nerrors = arg_parse(argc, argv, (void **) &gen_onoff_state);
if (nerrors != 0) {
arg_print_errors(stderr, gen_onoff_state.end, argv[0]);
return 1;
}
onoff_common.model = ble_mesh_get_model(ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_CLI);
arg_int_to_value(gen_onoff_state.appkey_idx, onoff_common.ctx.app_idx, "appkey_index");
arg_int_to_value(gen_onoff_state.opcode, onoff_common.opcode, "opcode");
arg_int_to_value(gen_onoff_state.role, onoff_common.msg_role, "role");
arg_int_to_value(gen_onoff_state.unicast_address, onoff_common.ctx.addr, "address");
arg_int_to_value(gen_onoff_state.net_idx, onoff_common.ctx.net_idx, "network key index");
arg_int_to_value(gen_onoff_state.op_en, gen_client_set.onoff_set.op_en, "op_en");
arg_int_to_value(gen_onoff_state.onoff_state, gen_client_set.onoff_set.onoff, "onoff");
arg_int_to_value(gen_onoff_state.trans_id, gen_client_set.onoff_set.tid, "tid");
arg_int_to_value(gen_onoff_state.trans_time, gen_client_set.onoff_set.trans_time, "trans_time");
arg_int_to_value(gen_onoff_state.delay, gen_client_set.onoff_set.delay, "delay");
if (gen_onoff_state.action_type->count != 0) {
if (strcmp(gen_onoff_state.action_type->sval[0], "get") == 0) {
err = esp_ble_mesh_generic_client_get_state(&onoff_common, &gen_client_get);
} else if (strcmp(gen_onoff_state.action_type->sval[0], "set") == 0) {
err = esp_ble_mesh_generic_client_set_state(&onoff_common, &gen_client_set);
} else if (strcmp(gen_onoff_state.action_type->sval[0], "reg") == 0) {
err = esp_ble_mesh_register_generic_client_callback(ble_mesh_generic_onoff_client_model_cb);
if (err == ESP_OK) {
ESP_LOGI(TAG, "GenONOFFClient:Reg,OK");
}
}
}
ESP_LOGD(TAG, "exit %s\n", __func__);
return err;
}
void ble_mesh_register_gen_onoff_client_command(void)
{
gen_onoff_state.action_type = arg_str1("z", NULL, "<action>", "action type");
gen_onoff_state.opcode = arg_int0("o", NULL, "<opcode>", "message opcode");
gen_onoff_state.appkey_idx = arg_int0("a", NULL, "<appkey>", "appkey index");
gen_onoff_state.role = arg_int0("r", NULL, "<role>", "role");
gen_onoff_state.unicast_address = arg_int0("u", NULL, "<address>", "unicast address");
gen_onoff_state.net_idx = arg_int0("n", NULL, "<netkey index>", "network key index");
gen_onoff_state.op_en = arg_int0("e", NULL, "<optional>", "whether optional parameters included");
gen_onoff_state.onoff_state = arg_int0("s", NULL, "<state>", "present onoff state");
gen_onoff_state.trans_id = arg_int0("i", NULL, "<identifier>", "transaction identifier");
gen_onoff_state.trans_time = arg_int0("t", NULL, "<time>", "time to complete state transition");
gen_onoff_state.delay = arg_int0("d", NULL, "<delay>", "indicate message execution delay");
gen_onoff_state.end = arg_end(1);
const esp_console_cmd_t gen_onoff_state_cmd = {
.command = "bmgocm",
.help = "ble mesh generic onoff client model",
.hint = NULL,
.func = &ble_mesh_generic_onoff_client_model,
.argtable = &gen_onoff_state,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&gen_onoff_state_cmd));
}
#endif

View file

@ -1,6 +0,0 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(ble_mesh_console_provisioner)

View file

@ -1,10 +0,0 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#
PROJECT_NAME := ble_mesh_console_provisioner
COMPONENT_ADD_INCLUDEDIRS := components/include
include $(IDF_PATH)/make/project.mk

View file

@ -1,13 +0,0 @@
| Supported Targets | ESP32 |
| ----------------- | ----- |
# ble mesh provisioner demo
## Introduction
This demo implements ble mesh provisioner basic features.Based on this demo, provisioner can scan and prove unprovisioned device, send set/get message. Also can define new model.
Demo steps:
1. Build the ble mesh provisioner demo with sdkconfig.default
2. register provisioner and set oob info, load model to init ble mesh provisioner
3. enable bearer, so that it can scan and prove unprovisioned devices
4. config appkey and other config info use config client model
5. send set/get message to nodes

View file

@ -1,205 +0,0 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "ble_mesh_cfg_srv_model.h"
uint8_t dev_uuid[16] = {0xdd, 0xdd};
#if CONFIG_BLE_MESH_NODE
esp_ble_mesh_prov_t prov = {
.uuid = dev_uuid,
};
#endif //CONFIG_BLE_MESH_NODE
#if CONFIG_BLE_MESH_PROVISIONER
esp_ble_mesh_prov_t prov = {
.prov_uuid = dev_uuid,
.prov_unicast_addr = 0x0001,
.prov_start_address = 0x0005,
.prov_attention = 0x00,
.prov_algorithm = 0x00,
.prov_pub_key_oob = 0x00,
.prov_static_oob_val = NULL,
.prov_static_oob_len = 0x00,
.flags = 0x00,
.iv_index = 0x00,
};
#endif //CONFIG_BLE_MESH_PROVISIONER
ESP_BLE_MESH_MODEL_PUB_DEFINE(model_pub_config, 2 + 1, ROLE_PROVISIONER);
esp_ble_mesh_model_pub_t vendor_model_pub_config;
// configure server module
esp_ble_mesh_cfg_srv_t cfg_srv = {
.relay = ESP_BLE_MESH_RELAY_ENABLED,
.beacon = ESP_BLE_MESH_BEACON_ENABLED,
#if defined(CONFIG_BLE_MESH_FRIEND)
.friend_state = ESP_BLE_MESH_FRIEND_ENABLED,
#else
.friend_state = ESP_BLE_MESH_FRIEND_NOT_SUPPORTED,
#endif
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
.gatt_proxy = ESP_BLE_MESH_GATT_PROXY_ENABLED,
#else
.gatt_proxy = ESP_BLE_MESH_GATT_PROXY_NOT_SUPPORTED,
#endif
.default_ttl = 7,
/* 3 transmissions with 20ms interval */
.net_transmit = ESP_BLE_MESH_TRANSMIT(2, 20),
.relay_retransmit = ESP_BLE_MESH_TRANSMIT(0, 20),
};
esp_ble_mesh_model_t config_server_models[] = {
ESP_BLE_MESH_MODEL_CFG_SRV(&cfg_srv),
};
esp_ble_mesh_elem_t config_server_elements[] = {
ESP_BLE_MESH_ELEMENT(0, config_server_models, ESP_BLE_MESH_MODEL_NONE),
};
esp_ble_mesh_comp_t config_server_comp = {
.cid = CID_ESP,
.elements = config_server_elements,
.element_count = ARRAY_SIZE(config_server_elements),
};
// config client model
esp_ble_mesh_model_t config_client_models[] = {
ESP_BLE_MESH_MODEL_CFG_SRV(&cfg_srv),
ESP_BLE_MESH_MODEL_CFG_CLI(&cfg_cli),
};
esp_ble_mesh_elem_t config_client_elements[] = {
ESP_BLE_MESH_ELEMENT(0, config_client_models, ESP_BLE_MESH_MODEL_NONE),
};
esp_ble_mesh_comp_t config_client_comp = {
.cid = CID_ESP,
.elements = config_client_elements,
.element_count = ARRAY_SIZE(config_client_elements),
};
// configure special module
ESP_BLE_MESH_MODEL_PUB_DEFINE(onoff_pub_0, 2 + 3, ROLE_NODE);
static esp_ble_mesh_gen_onoff_srv_t onoff_server = {
.rsp_ctrl.get_auto_rsp = ESP_BLE_MESH_SERVER_RSP_BY_APP,
.rsp_ctrl.set_auto_rsp = ESP_BLE_MESH_SERVER_RSP_BY_APP,
};
esp_ble_mesh_model_t gen_onoff_srv_models[] = {
ESP_BLE_MESH_MODEL_CFG_SRV(&cfg_srv),
ESP_BLE_MESH_MODEL_GEN_ONOFF_SRV(&onoff_pub_0, &onoff_server),
};
esp_ble_mesh_elem_t gen_onoff_srv_elements[] = {
ESP_BLE_MESH_ELEMENT(0, gen_onoff_srv_models, ESP_BLE_MESH_MODEL_NONE),
};
esp_ble_mesh_comp_t gen_onoff_srv_comp = {
.cid = CID_ESP,
.elements = gen_onoff_srv_elements,
.element_count = ARRAY_SIZE(gen_onoff_srv_elements),
};
// config generic onoff client
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
esp_ble_mesh_client_t gen_onoff_cli;
esp_ble_mesh_model_t gen_onoff_cli_models[] = {
ESP_BLE_MESH_MODEL_CFG_SRV(&cfg_srv),
ESP_BLE_MESH_MODEL_CFG_CLI(&cfg_cli),
ESP_BLE_MESH_MODEL_GEN_ONOFF_CLI(&model_pub_config, &gen_onoff_cli),
};
esp_ble_mesh_elem_t gen_onoff_cli_elements[] = {
ESP_BLE_MESH_ELEMENT(0, gen_onoff_cli_models, ESP_BLE_MESH_MODEL_NONE),
};
esp_ble_mesh_comp_t gen_onoff_cli_comp = {
.cid = CID_ESP,
.elements = gen_onoff_cli_elements,
.element_count = ARRAY_SIZE(gen_onoff_cli_elements),
};
#endif //CONFIG_BLE_MESH_GENERIC_ONOFF_CLI
//CONFIG VENDOR MODEL TEST PERFORMANCE
#define ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_SRV 0x2000
#define ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_CLI 0x2001
#define ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_GET ESP_BLE_MESH_MODEL_OP_3(0x01, CID_ESP)
#define ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET ESP_BLE_MESH_MODEL_OP_3(0x02, CID_ESP)
#define ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET_UNACK ESP_BLE_MESH_MODEL_OP_3(0x03, CID_ESP)
#define ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS ESP_BLE_MESH_MODEL_OP_3(0x04, CID_ESP)
esp_ble_mesh_client_op_pair_t test_perf_cli_op_pair[] = {
{ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_GET, ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS},
{ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET, ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS},
{ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET_UNACK, ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS},
};
esp_ble_mesh_client_t test_perf_cli = {
.op_pair_size = ARRAY_SIZE(test_perf_cli_op_pair),
.op_pair = test_perf_cli_op_pair,
};
esp_ble_mesh_model_op_t test_perf_srv_op[] = {
ESP_BLE_MESH_MODEL_OP(ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_GET, 1),
ESP_BLE_MESH_MODEL_OP(ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET, 1),
ESP_BLE_MESH_MODEL_OP(ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET_UNACK, 1),
ESP_BLE_MESH_MODEL_OP_END,
};
esp_ble_mesh_model_op_t test_perf_cli_op[] = {
ESP_BLE_MESH_MODEL_OP(ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS, 1),
ESP_BLE_MESH_MODEL_OP_END,
};
esp_ble_mesh_model_t config_models[] = {
ESP_BLE_MESH_MODEL_CFG_SRV(&cfg_srv),
ESP_BLE_MESH_MODEL_CFG_CLI(&cfg_cli),
};
esp_ble_mesh_model_t test_perf_cli_models[] = {
ESP_BLE_MESH_VENDOR_MODEL(CID_ESP, ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_CLI,
test_perf_cli_op, &vendor_model_pub_config, &test_perf_cli),
};
esp_ble_mesh_elem_t test_perf_cli_elements[] = {
ESP_BLE_MESH_ELEMENT(0, config_models, test_perf_cli_models),
};
esp_ble_mesh_comp_t test_perf_cli_comp = {
.cid = CID_ESP,
.elements = test_perf_cli_elements,
.element_count = ARRAY_SIZE(test_perf_cli_elements),
};
esp_ble_mesh_model_t test_perf_srv_models[] = {
ESP_BLE_MESH_VENDOR_MODEL(CID_ESP, ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_SRV,
test_perf_srv_op, NULL, NULL),
};
esp_ble_mesh_elem_t test_perf_srv_elements[] = {
ESP_BLE_MESH_ELEMENT(0, config_models, test_perf_srv_models),
};
esp_ble_mesh_comp_t test_perf_srv_comp = {
.cid = CID_ESP,
.elements = test_perf_srv_elements,
.element_count = ARRAY_SIZE(test_perf_srv_elements),
};

View file

@ -1,107 +0,0 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _BLE_MESH_CFG_SRV_MODEL_H_
#define _BLE_MESH_CFG_SRV_MODEL_H_
#include "esp_ble_mesh_defs.h"
#include "esp_ble_mesh_config_model_api.h"
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
#include "esp_ble_mesh_generic_model_api.h"
#endif //CONFIG_BLE_MESH_GENERIC_ONOFF_CLI
#define NODE_MAX_GROUP_CONFIG 3
#define CID_ESP 0x02C4
extern uint8_t dev_uuid[16];
typedef struct {
uint16_t net_idx;
uint16_t unicast_addr;
} ble_mesh_node_config_params;
ble_mesh_node_config_params ble_mesh_node_prestore_params[NODE_MAX_GROUP_CONFIG];
extern esp_ble_mesh_prov_t prov;
extern esp_ble_mesh_model_pub_t vendor_model_pub_config;
// configure server module
extern esp_ble_mesh_cfg_srv_t cfg_srv;
extern esp_ble_mesh_model_t config_server_models[];
extern esp_ble_mesh_elem_t config_server_elements[];
extern esp_ble_mesh_comp_t config_server_comp;
// config client model
esp_ble_mesh_client_t cfg_cli;
extern esp_ble_mesh_model_t config_client_models[];
extern esp_ble_mesh_elem_t config_client_elements[];
extern esp_ble_mesh_comp_t config_client_comp;
// configure special module
extern esp_ble_mesh_model_op_t gen_onoff_srv_model_op_config[];
extern esp_ble_mesh_model_t gen_onoff_srv_models[];
extern esp_ble_mesh_elem_t gen_onoff_srv_elements[];
extern esp_ble_mesh_comp_t gen_onoff_srv_comp;
// config generic onoff client
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
extern esp_ble_mesh_client_t gen_onoff_cli;
extern esp_ble_mesh_model_t gen_onoff_cli_models[];
extern esp_ble_mesh_elem_t gen_onoff_cli_elements[];
extern esp_ble_mesh_comp_t gen_onoff_cli_comp;
#endif //CONFIG_BLE_MESH_GENERIC_ONOFF_CLI
//CONFIG VENDOR MODEL TEST PERFORMANCE
#define ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_SRV 0x2000
#define ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_CLI 0x2001
#define ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_GET ESP_BLE_MESH_MODEL_OP_3(0x01, CID_ESP)
#define ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET ESP_BLE_MESH_MODEL_OP_3(0x02, CID_ESP)
#define ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET_UNACK ESP_BLE_MESH_MODEL_OP_3(0x03, CID_ESP)
#define ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS ESP_BLE_MESH_MODEL_OP_3(0x04, CID_ESP)
extern esp_ble_mesh_client_t test_perf_cli;
extern esp_ble_mesh_model_op_t test_perf_srv_op[];
extern esp_ble_mesh_model_op_t test_perf_cli_op[];
extern esp_ble_mesh_model_t config_models[];
extern esp_ble_mesh_model_t test_perf_cli_models[];
extern esp_ble_mesh_elem_t test_perf_cli_elements[];
extern esp_ble_mesh_comp_t test_perf_cli_comp;
extern esp_ble_mesh_model_t test_perf_srv_models[];
extern esp_ble_mesh_elem_t test_perf_srv_elements[];
extern esp_ble_mesh_comp_t test_perf_srv_comp;
#endif //_BLE_MESH_CFG_SRV_MODEL_H_

View file

@ -1,38 +0,0 @@
/* Console example — declarations of command registration functions.
This example code is in the Public Domain (or CC0 licensed, at your option).
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#pragma once
#include "esp_ble_mesh_defs.h"
// Register system functions
void register_system(void);
// Register bluetooth
void register_bluetooth(void);
// Register mesh node cmd
void ble_mesh_register_mesh_node(void);
// Register Test Perf client cmd
void ble_mesh_register_mesh_test_performance_client(void);
#if (CONFIG_BLE_MESH_CFG_CLI)
// Register mesh config client operation cmd
void ble_mesh_register_configuration_client_model(void);
#endif
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
// Register mesh client operation cmd
void ble_mesh_register_gen_onoff_client(void);
#endif
#if CONFIG_BLE_MESH_PROVISIONER
// Regitster mesh provisioner cmd
void ble_mesh_register_mesh_provisioner(void);
#endif

View file

@ -1,124 +0,0 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "ble_mesh_console_lib.h"
static int hex2num(char c);
static int hex2byte(const char *hex);
static int hex2num(char c)
{
if (c >= '0' && c <= '9') {
return c - '0';
}
if (c >= 'a' && c <= 'f') {
return c - 'a' + 10;
}
if (c >= 'A' && c <= 'F') {
return c - 'A' + 10;
}
return -1;
}
static int hex2byte(const char *hex)
{
int a, b;
a = hex2num(*hex++);
if (a < 0) {
return -1;
}
b = hex2num(*hex++);
if (b < 0) {
return -1;
}
return (a << 4) | b;
}
int hexstr_2_bin(const char *hex, uint8_t *buf, uint32_t len)
{
uint32_t i;
int a;
const char *ipos = hex;
uint8_t *opos = buf;
for (i = 0; i < len; i++) {
a = hex2byte(ipos);
if (a < 0) {
return -1;
}
*opos ++ = a;
ipos += 2;
}
return 0;
}
int get_value_string(char *value_in, char *buf)
{
int result = -1;
uint16_t length = strlen(value_in);
if (length > 2) {
if (value_in[0] == '0' && value_in[1] == 'x') {
buf[(length - 2) / 2] = 0;
result = hexstr_2_bin(&value_in[2], (uint8_t *)buf, (length - 2) / 2);
length = (length - 2) / 2;
} else {
strcpy(buf, value_in);
result = 0;
}
} else {
strcpy(buf, value_in);
result = 0;
}
return result;
}
bool str_2_mac(uint8_t *str, uint8_t *dest)
{
uint8_t loop = 0;
uint8_t tmp = 0;
uint8_t *src_p = str;
if (strlen((char *)src_p) != 17) { // must be like 12:34:56:78:90:AB
return false;
}
for (loop = 0; loop < 17 ; loop++) {
if (loop % 3 == 2) {
if (src_p[loop] != ':') {
return false;
}
continue;
}
if ((src_p[loop] >= '0') && (src_p[loop] <= '9')) {
tmp = tmp * 16 + src_p[loop] - '0';
} else if ((src_p[loop] >= 'A') && (src_p[loop] <= 'F')) {
tmp = tmp * 16 + src_p[loop] - 'A' + 10;
} else if ((src_p[loop] >= 'a') && (src_p[loop] <= 'f')) {
tmp = tmp * 16 + src_p[loop] - 'a' + 10;
} else {
return false;
}
if (loop % 3 == 1) {
*dest++ = tmp;
tmp = 0;
}
}
return true;
}

View file

@ -1,29 +0,0 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _BLE_MESH_CONSOLE_LIB_H_
#define _BLE_MESH_CONSOLE_LIB_H_
#include <stdio.h>
#include <string.h>
#include "esp_system.h"
#include "esp_console.h"
#include "argtable3/argtable3.h"
bool str_2_mac(uint8_t *str, uint8_t *dest);
int hexstr_2_bin(const char *hex, uint8_t *buf, uint32_t len);
int get_value_string(char *value_in, char *buf);
#endif //_BLE_MESH_CONSOLE_LIB_H_

View file

@ -1,126 +0,0 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdio.h>
#include <string.h>
#include "esp_log.h"
#include "esp_console.h"
#include "esp_vfs_dev.h"
#include "esp_vfs_fat.h"
#include "nvs.h"
#include "nvs_flash.h"
#include "esp_bt.h"
#include "esp_bt_main.h"
#include "ble_mesh_console_decl.h"
#define TAG "ble_mesh_test"
#if CONFIG_STORE_HISTORY
#define MOUNT_PATH "/data"
#define HISTORY_PATH MOUNT_PATH "/history.txt"
static void initialize_filesystem(void)
{
static wl_handle_t wl_handle;
const esp_vfs_fat_mount_config_t mount_config = {
.max_files = 4,
.format_if_mount_failed = true
};
esp_err_t err = esp_vfs_fat_spiflash_mount(MOUNT_PATH, "storage", &mount_config, &wl_handle);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to mount FATFS (0x%x)", err);
return;
}
}
#endif // CONFIG_STORE_HISTORY
esp_err_t bluetooth_init(void)
{
esp_err_t ret;
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
ret = esp_bt_controller_init(&bt_cfg);
if (ret) {
ESP_LOGE(TAG, "%s failed to initialize controller\n", __func__);
return ret;
}
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
if (ret) {
ESP_LOGE(TAG, "%s failed to enable controller\n", __func__);
return ret;
}
ret = esp_bluedroid_init();
if (ret) {
ESP_LOGE(TAG, "%s failed to initialize bluetooth\n", __func__);
return ret;
}
ret = esp_bluedroid_enable();
if (ret) {
ESP_LOGE(TAG, "%s failed to enable bluetooth\n", __func__);
return ret;
}
esp_log_level_set("*", ESP_LOG_ERROR);
esp_log_level_set("ble_mesh_prov_console", ESP_LOG_INFO);
return ret;
}
void app_main(void)
{
esp_err_t res;
nvs_flash_init();
// init and enable bluetooth
res = bluetooth_init();
if (res) {
printf("esp32_bluetooth_init failed (ret %d)", res);
}
esp_console_repl_t *repl = NULL;
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
#if CONFIG_STORE_HISTORY
initialize_filesystem();
repl_config.history_save_path = HISTORY_PATH;
#endif
repl_config.prompt = "ble_mesh_prov>";
// init console REPL environment
ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
/* Register commands */
register_system();
register_bluetooth();
ble_mesh_register_mesh_node();
ble_mesh_register_mesh_test_performance_client();
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
ble_mesh_register_gen_onoff_client();
#endif
#if (CONFIG_BLE_MESH_PROVISIONER)
ble_mesh_register_mesh_provisioner();
#endif
#if (CONFIG_BLE_MESH_CFG_CLI)
ble_mesh_register_configuration_client_model();
#endif
// start console REPL
ESP_ERROR_CHECK(esp_console_start_repl(repl));
}

View file

@ -1,179 +0,0 @@
/* Console example — various system commands
This example code is in the Public Domain (or CC0 licensed, at your option).
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "esp_log.h"
#include "esp_console.h"
#include "esp_system.h"
#include "esp_sleep.h"
#include "driver/rtc_io.h"
#include "argtable3/argtable3.h"
#include "ble_mesh_console_decl.h"
#if CONFIG_IDF_CMAKE
#define CONFIG_ESPTOOLPY_PORT "Which is choosen by Users for CMake"
#endif
static void register_free(void);
static void register_restart(void);
static void register_make(void);
void register_system(void)
{
register_free();
register_restart();
register_make();
}
/** 'restart' command restarts the program */
static int restart(int argc, char **argv)
{
printf("%s, %s", __func__, "Restarting");
esp_restart();
}
static void register_restart(void)
{
const esp_console_cmd_t cmd = {
.command = "restart",
.help = "Restart the program",
.hint = NULL,
.func = &restart,
};
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
}
/** 'free' command prints available heap memory */
static int free_mem(int argc, char **argv)
{
printf("%d\n", esp_get_free_heap_size());
return 0;
}
static void register_free(void)
{
const esp_console_cmd_t cmd = {
.command = "free",
.help = "Get the total size of heap memory available",
.hint = NULL,
.func = &free_mem,
};
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
}
static int make(int argc, char **argv)
{
int count = REG_READ(RTC_CNTL_STORE0_REG);
if (++count >= 3) {
printf("This is not the console you are looking for.\n");
return 0;
}
REG_WRITE(RTC_CNTL_STORE0_REG, count);
const char *make_output =
R"(LD build/console.elf
esptool.py v2.1-beta1
)";
const char* flash_output[] = {
R"(Flashing binaries to serial port )" CONFIG_ESPTOOLPY_PORT R"( (app at offset 0x10000)...
esptool.py v2.1-beta1
Connecting....
)",
R"(Chip is ESP32D0WDQ6 (revision 0)
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0220
Compressed 15712 bytes to 9345...
)",
R"(Wrote 15712 bytes (9345 compressed) at 0x00001000 in 0.1 seconds (effective 1126.9 kbit/s)...
Hash of data verified.
Compressed 333776 bytes to 197830...
)",
R"(Wrote 333776 bytes (197830 compressed) at 0x00010000 in 3.3 seconds (effective 810.3 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 82...
)",
R"(Wrote 3072 bytes (82 compressed) at 0x00008000 in 0.0 seconds (effective 1588.4 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting...
)"
};
const char* monitor_output =
R"(MONITOR
)" LOG_COLOR_W R"(--- idf_monitor on )" CONFIG_ESPTOOLPY_PORT R"( 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H --
)" LOG_RESET_COLOR;
bool need_make = false;
bool need_flash = false;
bool need_monitor = false;
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "all") == 0) {
need_make = true;
} else if (strcmp(argv[i], "flash") == 0) {
need_make = true;
need_flash = true;
} else if (strcmp(argv[i], "monitor") == 0) {
need_monitor = true;
} else if (argv[i][0] == '-') {
/* probably -j option */
} else if (isdigit((int) argv[i][0])) {
/* might be an argument to -j */
} else {
printf("make: *** No rule to make target `%s'. Stop.\n", argv[i]);
/* Technically this is an error, but let's not spoil the output */
return 0;
}
}
if (argc == 1) {
need_make = true;
}
if (need_make) {
printf("%s", make_output);
}
if (need_flash) {
size_t n_items = sizeof(flash_output) / sizeof(flash_output[0]);
for (int i = 0; i < n_items; ++i) {
printf("%s", flash_output[i]);
vTaskDelay(200/portTICK_PERIOD_MS);
}
}
if (need_monitor) {
printf("%s", monitor_output);
esp_restart();
}
return 0;
}
static void register_make(void)
{
const esp_console_cmd_t cmd = {
.command = "make",
.help = NULL, /* Do not include in 'help' output */
.hint = "all | flash | monitor",
.func = &make,
};
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
}

View file

@ -1,491 +0,0 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "soc/soc.h"
#include "esp_bt.h"
#include "esp_bt_device.h"
#include "esp_ble_mesh_defs.h"
#include "esp_ble_mesh_common_api.h"
#include "esp_ble_mesh_provisioning_api.h"
#include "esp_ble_mesh_networking_api.h"
#include "esp_ble_mesh_config_model_api.h"
#include "ble_mesh_adapter.h"
#include "transaction.h"
typedef struct {
struct arg_str *static_val;
struct arg_int *static_val_len;
struct arg_int *output_size;
struct arg_int *output_actions;
struct arg_int *input_size;
struct arg_int *input_actions;
struct arg_int *prov_start_address;
struct arg_end *end;
} ble_mesh_prov_t;
static ble_mesh_prov_t oob;
typedef struct {
struct arg_int *model_type;
struct arg_int *config_index;
struct arg_int *pub_config;
struct arg_end *end;
} ble_mesh_comp_t;
static ble_mesh_comp_t component;
typedef struct {
struct arg_int *bearer;
struct arg_int *enable;
struct arg_end *end;
} ble_mesh_bearer_t;
static ble_mesh_bearer_t bearer;
typedef struct {
struct arg_str *action_type;
struct arg_int *tx_sense_power;
struct arg_end *end;
} ble_mesh_tx_sense_power;
static ble_mesh_tx_sense_power power_set;
ble_mesh_node_status node_status = {
.previous = 0x0,
.current = 0x0,
};
void ble_mesh_register_node_cmd(void);
// Register callback function
void ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_param_t *param);
void ble_mesh_model_cb(esp_ble_mesh_model_cb_event_t event, esp_ble_mesh_model_cb_param_t *param);
void ble_mesh_register_mesh_node(void)
{
ble_mesh_register_node_cmd();
}
int ble_mesh_register_node_cb(int argc, char** argv)
{
ESP_LOGD(TAG, "enter %s\n", __func__);
ble_mesh_node_init();
esp_ble_mesh_register_prov_callback(ble_mesh_prov_cb);
esp_ble_mesh_register_custom_model_callback(ble_mesh_model_cb);
ESP_LOGI(TAG, "Node:Reg,OK");
ESP_LOGD(TAG, "exit %s\n", __func__);
return 0;
}
void ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_param_t *param)
{
ESP_LOGD(TAG, "enter %s, event = %d", __func__, event);
switch (event) {
case ESP_BLE_MESH_PROV_REGISTER_COMP_EVT:
ble_mesh_callback_check_err_code(param->prov_register_comp.err_code, "Provisioning:Register");
break;
case ESP_BLE_MESH_NODE_PROV_ENABLE_COMP_EVT:
ble_mesh_callback_check_err_code(param->node_prov_enable_comp.err_code, "Node:EnBearer");
break;
case ESP_BLE_MESH_NODE_PROV_DISABLE_COMP_EVT:
ble_mesh_callback_check_err_code(param->node_prov_disable_comp.err_code, "Node:DisBearer");
break;
case ESP_BLE_MESH_NODE_PROV_LINK_OPEN_EVT:
ESP_LOGI(TAG, "Node:LinkOpen,OK,%d", param->node_prov_link_open.bearer);
break;
case ESP_BLE_MESH_NODE_PROV_LINK_CLOSE_EVT:
ESP_LOGI(TAG, "Node:LinkClose,OK,%d", param->node_prov_link_close.bearer);
break;
case ESP_BLE_MESH_NODE_PROV_OUTPUT_NUMBER_EVT:
ESP_LOGI(TAG, "Node:OutPut,%d,%d", param->node_prov_output_num.action, param->node_prov_output_num.number);
break;
case ESP_BLE_MESH_NODE_PROV_OUTPUT_STRING_EVT:
ESP_LOGI(TAG, "Node:OutPutStr,%s", param->node_prov_output_str.string);
break;
case ESP_BLE_MESH_NODE_PROV_INPUT_EVT:
ESP_LOGI(TAG, "Node:InPut,%d,%d", param->node_prov_input.action, param->node_prov_input.size);
break;
case ESP_BLE_MESH_NODE_PROV_COMPLETE_EVT:
ESP_LOGI(TAG, "Node:OK,%d,%d", param->node_prov_complete.net_idx, param->node_prov_complete.addr);
ble_mesh_set_node_prestore_params(param->node_prov_complete.net_idx, param->node_prov_complete.addr);
break;
case ESP_BLE_MESH_NODE_PROV_RESET_EVT:
ESP_LOGI(TAG, "Node:Reset");
break;
case ESP_BLE_MESH_NODE_PROV_INPUT_NUMBER_COMP_EVT:
ble_mesh_callback_check_err_code(param->node_prov_input_num_comp.err_code, "Node:InputNum");
break;
case ESP_BLE_MESH_NODE_PROV_INPUT_STRING_COMP_EVT:
ble_mesh_callback_check_err_code(param->node_prov_input_str_comp.err_code, "Node:InputStr");
break;
case ESP_BLE_MESH_NODE_SET_UNPROV_DEV_NAME_COMP_EVT:
ble_mesh_callback_check_err_code(param->node_set_unprov_dev_name_comp.err_code, "Node:SetName");
break;
case ESP_BLE_MESH_NODE_PROXY_IDENTITY_ENABLE_COMP_EVT:
ble_mesh_callback_check_err_code(param->node_proxy_identity_enable_comp.err_code, "Node:ProxyIndentity");
break;
case ESP_BLE_MESH_NODE_PROXY_GATT_ENABLE_COMP_EVT:
ble_mesh_callback_check_err_code(param->node_proxy_gatt_enable_comp.err_code, "Node:EnProxyGatt");
break;
case ESP_BLE_MESH_NODE_PROXY_GATT_DISABLE_COMP_EVT:
ble_mesh_callback_check_err_code(param->node_proxy_gatt_disable_comp.err_code, "Node:DisProxyGatt");
break;
#if (CONFIG_BLE_MESH_PROVISIONER)
case ESP_BLE_MESH_PROVISIONER_RECV_UNPROV_ADV_PKT_EVT:
ESP_LOGD(TAG, "Provisioner recv unprovisioned device beacon:");
ESP_LOG_BUFFER_HEX("Device UUID %s", param->provisioner_recv_unprov_adv_pkt.dev_uuid, 16);
ESP_LOG_BUFFER_HEX("Address %s", param->provisioner_recv_unprov_adv_pkt.addr, 6);
ESP_LOGD(TAG, "Address type 0x%x, oob_info 0x%04x, adv_type 0x%x, bearer 0x%x",
param->provisioner_recv_unprov_adv_pkt.addr_type, param->provisioner_recv_unprov_adv_pkt.oob_info,
param->provisioner_recv_unprov_adv_pkt.adv_type, param->provisioner_recv_unprov_adv_pkt.bearer);
break;
case ESP_BLE_MESH_PROVISIONER_PROV_LINK_OPEN_EVT:
ESP_LOGI(TAG, "Provisioner:LinkOpen,OK,%d", param->provisioner_prov_link_open.bearer);
break;
case ESP_BLE_MESH_PROVISIONER_PROV_LINK_CLOSE_EVT:
ESP_LOGI(TAG, "Provisioner:LinkClose,OK,%d,%d",
param->provisioner_prov_link_close.bearer, param->provisioner_prov_link_close.reason);
break;
case ESP_BLE_MESH_PROVISIONER_ADD_UNPROV_DEV_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_add_unprov_dev_comp.err_code, "Provisioner:DevAdd");
break;
case ESP_BLE_MESH_PROVISIONER_DELETE_DEV_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_delete_dev_comp.err_code, "Provisioner:DevDel");
break;
case ESP_BLE_MESH_PROVISIONER_PROV_COMPLETE_EVT:
ESP_LOGI(TAG, "Provisioner:OK,%d,%d", param->provisioner_prov_complete.netkey_idx, param->provisioner_prov_complete.unicast_addr);
break;
case ESP_BLE_MESH_PROVISIONER_PROV_ENABLE_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_prov_enable_comp.err_code, "Provisioner:EnBearer");
break;
case ESP_BLE_MESH_PROVISIONER_PROV_DISABLE_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_prov_disable_comp.err_code, "Provisioner:DisBearer");
break;
case ESP_BLE_MESH_PROVISIONER_SET_DEV_UUID_MATCH_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_set_dev_uuid_match_comp.err_code, "Provisioner:UuidMatch");
break;
case ESP_BLE_MESH_PROVISIONER_SET_PROV_DATA_INFO_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_set_prov_data_info_comp.err_code, "Provisioner:DataInfo");
break;
case ESP_BLE_MESH_PROVISIONER_SET_NODE_NAME_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_set_node_name_comp.err_code, "Provisioner:NodeName");
break;
case ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_APP_KEY_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_add_app_key_comp.err_code, "Provisioner:AppKeyAdd");
break;
case ESP_BLE_MESH_PROVISIONER_BIND_APP_KEY_TO_MODEL_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_bind_app_key_to_model_comp.err_code, "Provisioner:AppKeyBind");
break;
case ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_NET_KEY_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_add_net_key_comp.err_code, "Provisioner:NetKeyAdd");
break;
#endif
default:
break;
}
ESP_LOGD(TAG, "exit %s\n", __func__);
}
void ble_mesh_model_cb(esp_ble_mesh_model_cb_event_t event, esp_ble_mesh_model_cb_param_t *param)
{
esp_err_t result = ESP_OK;
uint8_t status;
uint64_t *start_time = NULL;
transaction_t *trans = NULL;
ESP_LOGD(TAG, "enter %s, event=%x\n", __func__, event);
do {
trans = transaction_get(TRANS_TYPE_MESH_PERF, TRANS_MESH_SEND_MESSAGE, trans);
if (trans) {
start_time = (uint64_t *)trans->input;
break;
}
}while(trans);
switch (event) {
case ESP_BLE_MESH_MODEL_OPERATION_EVT:
if (param->model_operation.model != NULL && param->model_operation.model->op != NULL) {
if (param->model_operation.opcode == ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_GET) {
ESP_LOGI(TAG, "Node:GetStatus,OK");
ble_mesh_node_get_state(status);
result = esp_ble_mesh_server_model_send_msg(param->model_operation.model, param->model_operation.ctx, ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS,
sizeof(status), &status);
if (result != ESP_OK) {
ESP_LOGE(TAG, "Node:SendMsg,Fal");
}
} else if (param->model_operation.opcode == ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET) {
ble_mesh_node_set_state(param->model_operation.msg[0]);
ESP_LOGI(TAG, "Node:SetAck,OK,%d,%d", param->model_operation.msg[0], param->model_operation.ctx->recv_ttl);
result = esp_ble_mesh_server_model_send_msg(param->model_operation.model, param->model_operation.ctx, ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS,
sizeof(status), param->model_operation.msg);
if (result != ESP_OK) {
ESP_LOGE(TAG, "Node:SendMsg,Fal");
}
} else if (param->model_operation.opcode == ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK) {
ble_mesh_node_set_state(param->model_operation.msg[0]);
ESP_LOGI(TAG, "Node:SetUnAck,OK,%d,%d", param->model_operation.msg[0], param->model_operation.ctx->recv_ttl);
} else if (param->model_operation.opcode == ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS) {
ESP_LOGI(TAG, "Node:Status,Success,%d", param->model_operation.length);
} else if (param->model_operation.opcode == ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET) {
ESP_LOGI(TAG, "VendorModel:SetAck,OK,%d", param->model_operation.ctx->recv_ttl);
} else if (param->model_operation.opcode == ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS) {
ESP_LOGI(TAG, "VendorModel:Status,OK,%d", param->model_operation.ctx->recv_ttl);
if (trans) {
uint64_t current_time = esp_timer_get_time();
result = ble_mesh_test_performance_client_model_accumulate_time(((uint32_t)(current_time - *start_time) / 1000), param->model_operation.msg,
param->model_operation.ctx->recv_ttl, param->model_operation.length);
transaction_set_events(trans, TRANS_MESH_SEND_MESSAGE_EVT);
}
}
}
break;
case ESP_BLE_MESH_MODEL_SEND_COMP_EVT:
if (param->model_send_comp.err_code == ESP_OK) {
ESP_LOGI(TAG, "Node:ModelSend,OK");
} else {
ESP_LOGE(TAG, "Node:ModelSend,Fail,%d,0x%X,0x%04X", param->model_send_comp.err_code, param->model_send_comp.model->model_id, param->model_send_comp.model->op->opcode);
}
break;
case ESP_BLE_MESH_MODEL_PUBLISH_COMP_EVT:
ESP_LOGI(TAG, "Node:PublishSend,OK,0x%X,%d", param->model_publish_comp.model->model_id, param->model_publish_comp.model->pub->msg->len);
break;
case ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT:
ESP_LOGI(TAG, "Node:PublishReceive,OK,0x%04X,%d,%d", param->client_recv_publish_msg.opcode, param->client_recv_publish_msg.length, param->client_recv_publish_msg.msg[1]);
if (trans) {
uint64_t current_time = esp_timer_get_time();
result = ble_mesh_test_performance_client_model_accumulate_time(((uint32_t)(current_time - *start_time) / 2000), param->client_recv_publish_msg.msg,
param->client_recv_publish_msg.ctx->recv_ttl, param->client_recv_publish_msg.length);
transaction_set_events(trans, TRANS_MESH_SEND_MESSAGE_EVT);
}
break;
case ESP_BLE_MESH_MODEL_PUBLISH_UPDATE_EVT:
ESP_LOGI(TAG, "Node:PublishUpdate,OK");
break;
case ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT:
ESP_LOGI(TAG, "Node:TimeOut, 0x%04X", param->client_send_timeout.opcode);
if (trans) {
transaction_set_events(trans, TRANS_MESH_SEND_MESSAGE_EVT);
}
break;
case ESP_BLE_MESH_MODEL_EVT_MAX:
ESP_LOGI(TAG, "Node:MaxEvt");
break;
default:
break;
}
ESP_LOGD(TAG, "exit %s\n", __func__);
}
int ble_mesh_power_set(int argc, char **argv)
{
esp_err_t result = ESP_OK;
int nerrors = arg_parse(argc, argv, (void **) &power_set);
ESP_LOGD(TAG, "enter %s\n", __func__);
if (nerrors != 0) {
arg_print_errors(stderr, power_set.end, argv[0]);
return 1;
}
if (strcmp(power_set.action_type->sval[0], "tx") == 0) {
result = esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV, power_set.tx_sense_power->ival[0]);
} else if (strcmp(power_set.action_type->sval[0], "sense") == 0) {
uint32_t *reg = (uint32_t *)(0x6001c07c);
int reg_addr = 0x6001c07c;
uint32_t flag = 0x00FF0000;
uint32_t sense_new = power_set.tx_sense_power->ival[0];
uint32_t reg_to_write = ((*reg) &= ~flag) | ((256 - sense_new) << 16);
REG_WRITE(reg_addr, reg_to_write);
}
if (result == ESP_OK) {
ESP_LOGI(TAG, "Node:SetPower,OK\n");
}
ESP_LOGD(TAG, "exit %s\n", __func__);
return result;
}
static int ble_mesh_load_oob(int argc, char **argv)
{
uint8_t *static_val;
ESP_LOGD(TAG, "enter %s \n", __func__);
int nerrors = arg_parse(argc, argv, (void **) &oob);
if (nerrors != 0) {
arg_print_errors(stderr, oob.end, argv[0]);
return 1;
}
//parsing prov
#if CONFIG_BLE_MESH_NODE
prov.uuid = dev_uuid;
memcpy(dev_uuid, esp_bt_dev_get_address(), BD_ADDR_LEN);
if (oob.static_val->count != 0) {
static_val = malloc(oob.static_val_len->ival[0] + 1);
if (static_val == NULL) {
ESP_LOGE(TAG, "malloc fail,%s,%d\n", __func__, __LINE__);
}
get_value_string((char *)oob.static_val->sval[0], (char *)static_val);
prov.static_val = static_val;
}
arg_int_to_value(oob.static_val_len, prov.static_val_len, "static value length");
arg_int_to_value(oob.output_size, prov.output_size, "output size");
arg_int_to_value(oob.output_actions, prov.output_actions, "output actions");
arg_int_to_value(oob.input_size, prov.input_size, "input size");
arg_int_to_value(oob.input_actions, prov.input_actions, "input actions");
#endif
#if CONFIG_BLE_MESH_PROVISIONER
if (oob.static_val->count != 0) {
static_val = malloc(oob.static_val_len->ival[0] + 1);
if (static_val == NULL) {
ESP_LOGE(TAG, "malloc fail,%s,%d\n", __func__, __LINE__);
}
get_value_string((char *)oob.static_val->sval[0], (char *)static_val);
prov.prov_static_oob_val = static_val;
}
arg_int_to_value(oob.prov_start_address, prov.prov_start_address, "provisioner start address");
arg_int_to_value(oob.static_val_len, prov.prov_static_oob_len, "provisioner static value length");
#endif
ESP_LOGI(TAG, "OOB:Load,OK\n");
ESP_LOGD(TAG, "exit %s\n", __func__);
return 0;
}
int ble_mesh_init(int argc, char **argv)
{
int err;
esp_ble_mesh_comp_t *local_component = NULL;
int nerrors = arg_parse(argc, argv, (void **) &component);
if (nerrors != 0) {
arg_print_errors(stderr, component.end, argv[0]);
return 1;
}
ESP_LOGD(TAG, "enter %s, module %x\n", __func__, component.model_type->ival[0]);
local_component = ble_mesh_get_component(component.model_type->ival[0]);
err = esp_ble_mesh_init(&prov, local_component);
if (err) {
ESP_LOGE(TAG, "Initializing mesh failed (err %d)\n", err);
return err;
}
ESP_LOGD(TAG, "exit %s\n", __func__);
return err;
}
int ble_mesh_provisioner_enable_bearer(int argc, char **argv)
{
esp_err_t err = 0;
ESP_LOGD(TAG, "enter %s \n", __func__);
int nerrors = arg_parse(argc, argv, (void **) &bearer);
if (nerrors != 0) {
arg_print_errors(stderr, bearer.end, argv[0]);
return 1;
}
if (bearer.enable->count != 0) {
if (bearer.enable->ival[0]) {
err = esp_ble_mesh_provisioner_prov_enable(bearer.bearer->ival[0]);
} else {
err = esp_ble_mesh_provisioner_prov_disable(bearer.bearer->ival[0]);
}
} else {
return 1;
}
ESP_LOGD(TAG, "exit %s\n", __func__);
return err;
}
void ble_mesh_register_node_cmd(void)
{
const esp_console_cmd_t register_cmd = {
.command = "bmreg",
.help = "ble mesh: provisioner/node register callback",
.hint = NULL,
.func = &ble_mesh_register_node_cb,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&register_cmd));
oob.static_val = arg_str0("s", NULL, "<value>", "Static OOB value");
oob.static_val_len = arg_int0("l", NULL, "<length>", "Static OOB value length");
oob.output_size = arg_int0("x", NULL, "<size>", "Maximum size of Output OOB");
oob.output_actions = arg_int0("o", NULL, "<actions>", "Supported Output OOB Actions");
oob.input_size = arg_int0("y", NULL, "<size>", "Maximum size of Input OOB");
oob.input_actions = arg_int0("i", NULL, "<actions>", "Supported Input OOB Actions");
oob.prov_start_address = arg_int0("p", NULL, "<address>", "start address assigned by provisioner");
oob.prov_start_address->ival[0] = 0x0005;
oob.end = arg_end(1);
const esp_console_cmd_t oob_cmd = {
.command = "bmoob",
.help = "ble mesh: provisioner/node config OOB parameters",
.hint = NULL,
.func = &ble_mesh_load_oob,
.argtable = &oob,
};
ESP_ERROR_CHECK( esp_console_cmd_register(&oob_cmd) );
component.model_type = arg_int0("m", NULL, "<model>", "mesh model");
component.config_index = arg_int0("c", NULL, "<index>", "mesh model op");
component.config_index->ival[0] = 0; // set default value
component.pub_config = arg_int0("p", NULL, "<publish>", "publish message buffer");
component.end = arg_end(1);
const esp_console_cmd_t model_cmd = {
.command = "bminit",
.help = "ble mesh: provisioner/node init",
.hint = NULL,
.func = &ble_mesh_init,
.argtable = &component,
};
ESP_ERROR_CHECK( esp_console_cmd_register(&model_cmd) );
bearer.bearer = arg_int0("b", NULL, "<bearer>", "supported bearer");
bearer.enable = arg_int0("e", NULL, "<enable/disable>", "bearers node supported");
bearer.end = arg_end(1);
const esp_console_cmd_t bearer_cmd = {
.command = "bmpbearer",
.help = "ble mesh provisioner: enable/disable different bearers",
.hint = NULL,
.func = &ble_mesh_provisioner_enable_bearer,
.argtable = &bearer,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&bearer_cmd));
power_set.tx_sense_power = arg_int0("t", NULL, "<power>", "tx power or sense");
power_set.action_type = arg_str1("z", NULL, "<action>", "action type");
power_set.end = arg_end(1);
const esp_console_cmd_t power_set_cmd = {
.command = "bmtxpower",
.help = "ble mesh: set tx power or sense",
.hint = NULL,
.func = &ble_mesh_power_set,
.argtable = &power_set,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&power_set_cmd));
}

View file

@ -1,391 +0,0 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "esp_bt_defs.h"
#include "provisioner_prov.h"
#include "esp_ble_mesh_defs.h"
#include "esp_ble_mesh_networking_api.h"
#include "esp_ble_mesh_provisioning_api.h"
#include "esp_ble_mesh_config_model_api.h"
#include "ble_mesh_adapter.h"
#include "ble_mesh_console_decl.h"
#if CONFIG_BLE_MESH_PROVISIONER
typedef struct {
struct arg_int *bearer;
struct arg_int *enable;
struct arg_end *end;
} ble_mesh_provisioner_bearer_t;
ble_mesh_provisioner_bearer_t provisioner_bearer;
typedef struct {
struct arg_str *add_del;
struct arg_str *device_addr;
struct arg_str *device_uuid;
struct arg_int *addr_type;
struct arg_int *bearer;
struct arg_int *oob_info;
struct arg_int *flag;
struct arg_end *end;
} ble_mesh_provisioner_addr_t;
ble_mesh_provisioner_addr_t provisioner_addr;
typedef struct {
struct arg_int *unicast_addr;
struct arg_end *end;
} ble_mesh_provisioner_get_node_t;
ble_mesh_provisioner_get_node_t provisioner_get_node;
typedef struct {
struct arg_int *oob_info;
struct arg_int *unicast_addr;
struct arg_int *element_num;
struct arg_int *net_idx;
struct arg_str *dev_key;
struct arg_str *uuid;
struct arg_end *end;
} ble_mesh_provisioner_add_node_t;
ble_mesh_provisioner_add_node_t provisioner_add_node;
typedef struct {
struct arg_int *appkey_index;
struct arg_int *element_address;
struct arg_int *network_index;
struct arg_int *mod_id;
struct arg_int *cid;
struct arg_end *end;
} ble_mesh_provisioner_bind_model_t;
ble_mesh_provisioner_bind_model_t provisioner_local_bind;
typedef struct {
struct arg_str *action_type;
struct arg_int *net_idx;
struct arg_int *app_idx;
struct arg_str *key;
struct arg_end *end;
} ble_mesh_provisioner_add_key_t;
ble_mesh_provisioner_add_key_t provisioner_add_key;
void ble_mesh_regist_provisioner_cmd(void);
void ble_mesh_register_mesh_provisioner(void)
{
ble_mesh_regist_provisioner_cmd();
}
int ble_mesh_provision_address(int argc, char **argv)
{
esp_err_t err = ESP_OK;
esp_ble_mesh_unprov_dev_add_t device_addr = {0};
uint8_t preset_addr_uuid[16] = {0x01, 0x02};
esp_ble_mesh_device_delete_t del_dev = {
.flag = BIT(0),
};
ESP_LOGD(TAG, "enter %s \n", __func__);
int nerrors = arg_parse(argc, argv, (void **) &provisioner_addr);
if (nerrors != 0) {
arg_print_errors(stderr, provisioner_addr.end, argv[0]);
return 1;
}
memcpy(device_addr.uuid, preset_addr_uuid, BD_ADDR_LEN);
if (provisioner_addr.device_addr->count != 0) {
str_2_mac((uint8_t *)provisioner_addr.device_addr->sval[0], device_addr.addr);
str_2_mac((uint8_t *)provisioner_addr.device_addr->sval[0], del_dev.addr);
arg_int_to_value(provisioner_addr.addr_type, device_addr.addr_type, "address type");
arg_int_to_value(provisioner_addr.addr_type, del_dev.addr_type, "address type");
} else if (provisioner_addr.device_uuid->count != 0) {
get_value_string((char *)provisioner_addr.device_uuid->sval[0], (char *)device_addr.uuid);
get_value_string((char *)provisioner_addr.device_uuid->sval[0], (char *)del_dev.uuid);
del_dev.flag = BIT(1);
}
if (strcmp(provisioner_addr.add_del->sval[0], "add") == 0) {
arg_int_to_value(provisioner_addr.bearer, device_addr.bearer, "bearer");
arg_int_to_value(provisioner_addr.oob_info, device_addr.oob_info, "oob information");
err = esp_ble_mesh_provisioner_add_unprov_dev(&device_addr, provisioner_addr.flag->ival[0]);
} else if (strcmp(provisioner_addr.add_del->sval[0], "del") == 0) {
err = esp_ble_mesh_provisioner_delete_dev(&del_dev);
}
if (err != ESP_OK) {
ESP_LOGI(TAG, "Provisioner:AddDelAddr,Fail,%d", err);
} else {
ESP_LOGI(TAG, "Provisioner:AddDelAddr,OK");
}
ESP_LOGD(TAG, "exit %s \n", __func__);
return err;
}
int ble_mesh_provisioner_bearer(int argc, char **argv)
{
esp_err_t err;
ESP_LOGD(TAG, "enter %s \n", __func__);
int nerrors = arg_parse(argc, argv, (void **) &provisioner_bearer);
if (nerrors != 0) {
arg_print_errors(stderr, provisioner_bearer.end, argv[0]);
return 1;
}
if (provisioner_bearer.enable->count != 0) {
if (provisioner_bearer.enable->ival[0]) {
err = esp_ble_mesh_provisioner_prov_enable(provisioner_bearer.bearer->ival[0]);
} else {
err = esp_ble_mesh_provisioner_prov_disable(provisioner_bearer.bearer->ival[0]);
}
} else {
return 1;
}
ESP_LOGD(TAG, "exit %s \n", __func__);
return err;
}
int ble_mesh_provisioner_get_node(int argc, char **argv)
{
uint16_t unicast_addr = 0;
uint16_t i = 0;
esp_ble_mesh_node_t *node_info;
ESP_LOGD(TAG, "enter %s\n", __func__);
int nerrors = arg_parse(argc, argv, (void **) &provisioner_get_node);
if (nerrors != 0) {
arg_print_errors(stderr, provisioner_get_node.end, argv[0]);
return 1;
}
arg_int_to_value(provisioner_get_node.unicast_addr, unicast_addr, "unicast address");
node_info = esp_ble_mesh_provisioner_get_node_with_addr(unicast_addr);
if (node_info == NULL) {
return ESP_FAIL;
} else {
printf("OobInfo:0x%x,Address:0x%x,EleNum:0x%x,NetIdx:0x%x,DevKey:",
node_info->oob_info, node_info->unicast_addr, node_info->element_num, node_info->net_idx);
for (i = 0; i < 16; i++) {
printf("%02x", node_info->dev_key[i]);
}
printf(",DevUuid:");
for (i = 0; i < 16; i++) {
printf("%02x", node_info->dev_uuid[i]);
}
printf("\n");
}
ESP_LOGD(TAG, "exit %s\n", __func__);
return ESP_OK;
}
int ble_mesh_provisioner_add_node(int argc, char **argv)
{
struct bt_mesh_node node_info;
esp_err_t result;
ESP_LOGD(TAG, " enter %s\n", __func__);
int nerrors = arg_parse(argc, argv, (void **) &provisioner_add_node);
if (nerrors != 0) {
arg_print_errors(stderr, provisioner_add_node.end, argv[0]);
return 1;
}
arg_int_to_value(provisioner_add_node.oob_info, node_info.oob_info, "oob information");
arg_int_to_value(provisioner_add_node.unicast_addr, node_info.unicast_addr, "unicast address");
arg_int_to_value(provisioner_add_node.element_num, node_info.element_num, "element number");
arg_int_to_value(provisioner_add_node.net_idx, node_info.net_idx, "network index");
if (provisioner_add_node.dev_key->count != 0) {
get_value_string((char *)provisioner_add_node.dev_key->sval[0], (char *)node_info.dev_key);
}
if (provisioner_add_node.uuid->count != 0) {
get_value_string((char *)provisioner_add_node.uuid->sval[0], (char *)node_info.dev_uuid);
get_value_string((char *)provisioner_add_node.uuid->sval[0], (char *)node_info.dev_uuid);
}
result = bt_mesh_provisioner_store_node_info(&node_info);
if (result == ESP_OK) {
ESP_LOGI(TAG, "Provisioner:AddNodeInfo,OK\n");
} else {
ESP_LOGI(TAG, "Provisioner:AddNodeInfo,ERROR,%d\n", result);
}
ESP_LOGD(TAG, "exit %s\n", __func__);
return result;
}
int ble_mesh_provisioner_add_key(int argc, char **argv)
{
esp_err_t err = ESP_OK;
uint8_t key[16] = {0};
esp_ble_mesh_prov_data_info_t info = {
.net_idx = 1,
.flag = NET_IDX_FLAG,
};
ESP_LOGD(TAG, " enter %s\n", __func__);
int nerrors = arg_parse(argc, argv, (void **) &provisioner_add_key);
if (nerrors != 0) {
arg_print_errors(stderr, provisioner_add_key.end, argv[0]);
return 1;
}
err = get_value_string((char *)provisioner_add_key.key->sval[0], (char *) key);
if (strcmp(provisioner_add_key.action_type->sval[0], "appkey") == 0) {
err = esp_ble_mesh_provisioner_add_local_app_key(key, provisioner_add_key.net_idx->ival[0], provisioner_add_key.app_idx->ival[0]);
} else if (strcmp(provisioner_add_key.action_type->sval[0], "netkey") == 0) {
// choose network key
info.net_idx = provisioner_add_key.net_idx->ival[0];
err = esp_ble_mesh_provisioner_add_local_net_key(key, provisioner_add_key.net_idx->ival[0]);
err = err | esp_ble_mesh_provisioner_set_prov_data_info(&info);
}
if (err != ESP_OK) {
ESP_LOGI(TAG, "Provisioner:KeyAction,Fail,%d", err);
} else {
ESP_LOGI(TAG, "Provisioner:KeyAction,OK");
}
ESP_LOGD(TAG, "exit %s\n", __func__);
return err;
}
int ble_mesh_provision_bind_local_model(int argc, char **argv)
{
esp_err_t err;
uint16_t element_addr = 0;
uint16_t app_idx = 0;
uint16_t model_id = 0;
uint16_t company_id = 0xFFFF;
ESP_LOGD(TAG, " enter %s\n", __func__);
int nerrors = arg_parse(argc, argv, (void **) &provisioner_local_bind);
if (nerrors != 0) {
arg_print_errors(stderr, provisioner_local_bind.end, argv[0]);
return 1;
}
arg_int_to_value(provisioner_local_bind.element_address, element_addr, "element address");
arg_int_to_value(provisioner_local_bind.appkey_index, app_idx, "appkey index");
arg_int_to_value(provisioner_local_bind.mod_id, model_id, "model id");
arg_int_to_value(provisioner_local_bind.cid, company_id, "company id");
err = esp_ble_mesh_provisioner_bind_app_key_to_local_model(element_addr, app_idx, model_id, company_id);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Provisioner:BindModel,Fail,%d\n", err);
} else {
ESP_LOGI(TAG, "Provisioner:BindModel,OK\n");
}
ESP_LOGD(TAG, "exit %s\n", __func__);
return err;
}
void ble_mesh_regist_provisioner_cmd(void)
{
provisioner_addr.add_del = arg_str1("z", NULL, "<add/delete>", "action type");
provisioner_addr.device_addr = arg_str0("d", NULL, "<address>", "device address");
provisioner_addr.device_uuid = arg_str0("u", NULL, "<uuid>", "device uuid");
provisioner_addr.addr_type = arg_int0("a", NULL, "<type>", "address type");
provisioner_addr.flag = arg_int0("f", NULL, "<flag>", "address flag");
provisioner_addr.flag->ival[0] = ADD_DEV_RM_AFTER_PROV_FLAG | ADD_DEV_FLUSHABLE_DEV_FLAG;
provisioner_addr.bearer = arg_int0("b", NULL, "<bearer>", "used bearer");
provisioner_addr.oob_info = arg_int0("o", NULL, "<oob info>", "oob information");
provisioner_addr.end = arg_end(1);
const esp_console_cmd_t provisioner_addr_cmd = {
.command = "bmpdev",
.help = "ble mesh provisioner: add/delete unprovisioned device",
.hint = NULL,
.func = &ble_mesh_provision_address,
.argtable = &provisioner_addr,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_addr_cmd));
provisioner_bearer.bearer = arg_int0("b", NULL, "<bearer>", "bearer supported provisioner");
provisioner_bearer.enable = arg_int0("e", NULL, "<enable/disable>", "enable or disable bearer");
provisioner_bearer.end = arg_end(1);
const esp_console_cmd_t provisioner_bearer_cmd = {
.command = "bmpbearer",
.help = "ble mesh provisioner: enable/disable provisioner different bearer",
.hint = NULL,
.func = &ble_mesh_provisioner_bearer,
.argtable = &provisioner_bearer,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_bearer_cmd));
provisioner_get_node.unicast_addr = arg_int1("u", NULL, "<address>", "get node by unicast address");
provisioner_get_node.end = arg_end(1);
const esp_console_cmd_t provisioner_get_node_cmd = {
.command = "bmpgetn",
.help = "ble mesh provisioner: get node",
.func = &ble_mesh_provisioner_get_node,
.argtable = &provisioner_get_node,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_get_node_cmd));
provisioner_add_node.oob_info = arg_int0("o", NULL, "<oob info>", "oob information");
provisioner_add_node.unicast_addr = arg_int0("a", NULL, "<unicast address>", "unicast address");
provisioner_add_node.element_num = arg_int0("e", NULL, "<element num>", "element num");
provisioner_add_node.net_idx = arg_int0("n", NULL, "<net index>", "net index");
provisioner_add_node.dev_key = arg_str0("d", NULL, "<device key>", "device key");
provisioner_add_node.uuid = arg_str0("u", NULL, "<device uuid>", "device uuid");
provisioner_add_node.end = arg_end(1);
const esp_console_cmd_t provisioner_add_node_cmd = {
.command = "bmpaddn",
.help = "ble mesh provisioner: add node",
.func = &ble_mesh_provisioner_add_node,
.argtable = &provisioner_add_node,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_add_node_cmd));
provisioner_local_bind.appkey_index = arg_int1("a", NULL, "<appkey index>", "appkey index");
provisioner_local_bind.element_address = arg_int1("e", NULL, "<element address>", "element address");
provisioner_local_bind.network_index = arg_int1("n", NULL, "<network index>", "network index");
provisioner_local_bind.mod_id = arg_int1("m", NULL, "<model id>", "model id");
provisioner_local_bind.cid = arg_int0("c", NULL, "<model id>", "company id");
provisioner_local_bind.end = arg_end(1);
const esp_console_cmd_t provisioner_local_bind_cmd = {
.command = "bmpbind",
.help = "ble mesh provisioner: bind local model",
.func = &ble_mesh_provision_bind_local_model,
.argtable = &provisioner_local_bind,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_local_bind_cmd));
provisioner_add_key.action_type = arg_str1("z", NULL, "<action type>", "add appkey or network key");
provisioner_add_key.net_idx = arg_int1("n", NULL, "<net key index>", "network key index");
provisioner_add_key.key = arg_str1("k", NULL, "<key>", "appkey or network");
provisioner_add_key.app_idx = arg_int0("a", NULL, "<app key index>", "appkey index");
provisioner_add_key.end = arg_end(1);
const esp_console_cmd_t provisioner_add_key_cmd = {
.command = "bmpkey",
.help = "ble mesh provisioner: key",
.func = &ble_mesh_provisioner_add_key,
.argtable = &provisioner_add_key,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_add_key_cmd));
}
#endif

View file

@ -1,5 +0,0 @@
#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

View file

@ -1,45 +0,0 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "esp_bt_device.h"
#include "esp_console.h"
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
void register_ble_address(void);
void register_bluetooth(void)
{
register_ble_address();
}
int bt_mac(int argc, char** argv)
{
const uint8_t *mac = esp_bt_dev_get_address();
printf("+BTMAC:"MACSTR"\n", MAC2STR(mac));
return 0;
}
void register_ble_address(void)
{
const esp_console_cmd_t cmd = {
.command = "btmac",
.help = "BLE address",
.hint = NULL,
.func = (esp_console_cmd_func_t)&bt_mac,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
}

View file

@ -1,26 +0,0 @@
# Override some defaults so BT stack is enabled
# by default in this example
CONFIG_BT_ENABLED=y
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
CONFIG_BTDM_CTRL_MODE_BTDM=n
CONFIG_BTDM_MODEM_SLEEP=n
CONFIG_BTDM_SCAN_DUPL_TYPE_DATA_DEVICE=y
CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN=y
CONFIG_BT_BTU_TASK_STACK_SIZE=4512
# Override some defaults of ESP BLE Mesh
CONFIG_BLE_MESH=y
CONFIG_BLE_MESH_PROVISIONER=y
CONFIG_BLE_MESH_MAX_PROV_NODES=40
CONFIG_BLE_MESH_PB_GATT=y
CONFIG_BLE_MESH_PBA_SAME_TIME=10
CONFIG_BLE_MESH_PBG_SAME_TIME=3
CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=3
CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=3
CONFIG_BLE_MESH_CFG_CLI=y
CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y
CONFIG_BLE_MESH_MSG_CACHE_SIZE=60
CONFIG_BLE_MESH_ADV_BUF_COUNT=200
CONFIG_BLE_MESH_CRPL=40
CONFIG_BLE_MESH_SELF_TEST=y

View file

@ -1,14 +1,14 @@
set(srcs "ble_mesh_adapter.c" set(srcs "ble_mesh_adapter.c"
"transaction.c"
"ble_mesh_cfg_srv_model.c" "ble_mesh_cfg_srv_model.c"
"ble_mesh_console_lib.c" "ble_mesh_console_lib.c"
"ble_mesh_console_main.c" "ble_mesh_console_main.c"
"ble_mesh_console_system.c" "ble_mesh_console_system.c"
"ble_mesh_register_cmd.c"
"ble_mesh_reg_cfg_client_cmd.c" "ble_mesh_reg_cfg_client_cmd.c"
"ble_mesh_register_server_cmd.c"
"ble_mesh_reg_gen_onoff_client_cmd.c" "ble_mesh_reg_gen_onoff_client_cmd.c"
"ble_mesh_reg_test_perf_client_cmd.c" "ble_mesh_reg_test_perf_client_cmd.c"
"ble_mesh_register_node_cmd.c" "transaction.c"
"ble_mesh_register_provisioner_cmd.c"
"register_bluetooth.c") "register_bluetooth.c")
idf_component_register(SRCS "${srcs}" idf_component_register(SRCS "${srcs}"

View file

@ -11,7 +11,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "esp_ble_mesh_networking_api.h" #include "esp_ble_mesh_networking_api.h"
#include "ble_mesh_adapter.h" #include "ble_mesh_adapter.h"
@ -21,7 +20,7 @@ esp_ble_mesh_model_t *ble_mesh_get_model(uint16_t model_id)
switch (model_id) { switch (model_id) {
case ESP_BLE_MESH_MODEL_ID_CONFIG_SRV: case ESP_BLE_MESH_MODEL_ID_CONFIG_SRV:
model = config_server_models; model = &config_server_models[0];
break; break;
#if (CONFIG_BLE_MESH_CFG_CLI) #if (CONFIG_BLE_MESH_CFG_CLI)
case ESP_BLE_MESH_MODEL_ID_CONFIG_CLI: case ESP_BLE_MESH_MODEL_ID_CONFIG_CLI:
@ -43,14 +42,12 @@ esp_ble_mesh_model_t *ble_mesh_get_model(uint16_t model_id)
model = &test_perf_srv_models[0]; model = &test_perf_srv_models[0];
break; break;
} }
return model; return model;
} }
esp_ble_mesh_comp_t *ble_mesh_get_component(uint16_t model_id) esp_ble_mesh_comp_t *ble_mesh_get_component(uint16_t model_id)
{ {
esp_ble_mesh_comp_t *comp = NULL; esp_ble_mesh_comp_t *comp = NULL;
switch (model_id) { switch (model_id) {
case ESP_BLE_MESH_MODEL_ID_CONFIG_SRV: case ESP_BLE_MESH_MODEL_ID_CONFIG_SRV:
comp = &config_server_comp; comp = &config_server_comp;
@ -73,7 +70,6 @@ esp_ble_mesh_comp_t *ble_mesh_get_component(uint16_t model_id)
comp = &test_perf_srv_comp; comp = &test_perf_srv_comp;
break; break;
} }
return comp; return comp;
} }
@ -85,18 +81,87 @@ void ble_mesh_node_init(void)
ble_mesh_node_prestore_params[i].net_idx = ESP_BLE_MESH_KEY_UNUSED; ble_mesh_node_prestore_params[i].net_idx = ESP_BLE_MESH_KEY_UNUSED;
ble_mesh_node_prestore_params[i].unicast_addr = ESP_BLE_MESH_ADDR_UNASSIGNED; ble_mesh_node_prestore_params[i].unicast_addr = ESP_BLE_MESH_ADDR_UNASSIGNED;
} }
ble_mesh_node_sema = xSemaphoreCreateMutex();
if (!ble_mesh_node_sema) {
ESP_LOGE(TAG, "%s init fail, mesh node semaphore create fail", __func__);
}
} }
void ble_mesh_set_node_prestore_params(uint16_t netkey_index, uint16_t unicast_addr) void ble_mesh_set_node_prestore_params(uint16_t netkey_index, uint16_t unicast_addr)
{ {
uint16_t i; uint16_t i;
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY);
for (i = 0; i < NODE_MAX_GROUP_CONFIG; i++) { for (i = 0; i < NODE_MAX_GROUP_CONFIG; i++) {
if (ble_mesh_node_prestore_params[i].net_idx != ESP_BLE_MESH_KEY_UNUSED if (ble_mesh_node_prestore_params[i].net_idx != ESP_BLE_MESH_KEY_UNUSED && ble_mesh_node_prestore_params[i].unicast_addr != ESP_BLE_MESH_ADDR_UNASSIGNED) {
&& ble_mesh_node_prestore_params[i].unicast_addr != ESP_BLE_MESH_ADDR_UNASSIGNED) {
ble_mesh_node_prestore_params[i].net_idx = netkey_index; ble_mesh_node_prestore_params[i].net_idx = netkey_index;
ble_mesh_node_prestore_params[i].unicast_addr = unicast_addr; ble_mesh_node_prestore_params[i].unicast_addr = unicast_addr;
} }
} }
xSemaphoreGive(ble_mesh_node_sema);
}
void ble_mesh_node_statistics_get(void)
{
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY);
ESP_LOGI(TAG, "statistics:%d,%d\n", ble_mesh_node_statistics.statistics, ble_mesh_node_statistics.package_num);
xSemaphoreGive(ble_mesh_node_sema);
}
int ble_mesh_node_statistics_accumulate(uint8_t *data, uint32_t value, uint16_t type)
{
uint16_t i;
uint16_t sequence_num = (data[0] << 8) | data[1];
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY);
for (i = 0; i < ble_mesh_node_statistics.total_package_num; i++) {
if (ble_mesh_node_statistics.package_index[i] == sequence_num) {
xSemaphoreGive(ble_mesh_node_sema);
return 1;
}
}
// package type wrong
if (data[2] != type) {
xSemaphoreGive(ble_mesh_node_sema);
return 1;
}
for (i = 0; i < ble_mesh_node_statistics.total_package_num; i++) {
if (ble_mesh_node_statistics.package_index[i] == 0) {
ble_mesh_node_statistics.package_index[i] = sequence_num;
ble_mesh_node_statistics.package_num += 1;
ble_mesh_node_statistics.statistics += value;
break;
}
}
xSemaphoreGive(ble_mesh_node_sema);
return 0;
}
int ble_mesh_node_statistics_init(uint16_t package_num)
{
uint16_t i;
ble_mesh_node_statistics.package_index = malloc(sizeof(uint16_t) * package_num);
ble_mesh_node_statistics.total_package_num = package_num;
if (ble_mesh_node_statistics.package_index == NULL) {
ESP_LOGE(TAG, " %s, %d malloc fail\n", __func__, __LINE__);
return 1;
}
ble_mesh_node_statistics.package_num = 0;
for (i = 0; i < package_num; i++) {
ble_mesh_node_statistics.package_index[i] = 0;
}
return 0;
}
void ble_mesh_node_statistics_destroy(void)
{
if (ble_mesh_node_statistics.package_index != NULL) {
free(ble_mesh_node_statistics.package_index);
}
} }
void ble_mesh_create_send_data(char *data, uint16_t byte_num, uint16_t sequence_num, uint32_t opcode) void ble_mesh_create_send_data(char *data, uint16_t byte_num, uint16_t sequence_num, uint32_t opcode)
@ -159,6 +224,10 @@ void ble_mesh_test_performance_client_model_get_received_percent(void)
time_level_num = ((max_time - min_time) / 50 + 1); time_level_num = ((max_time - min_time) / 50 + 1);
statistics_time_percent = malloc(sizeof(statistics_time_performance) * time_level_num); statistics_time_percent = malloc(sizeof(statistics_time_performance) * time_level_num);
if (statistics_time_percent == NULL) {
ESP_LOGI(TAG, "malloc error");
return;
}
for (j = 0; j < time_level_num; j++) { for (j = 0; j < time_level_num; j++) {
statistics_time_percent[j].time_level = min_time + 50 * j; statistics_time_percent[j].time_level = min_time + 50 * j;
@ -181,11 +250,6 @@ void ble_mesh_test_performance_client_model_get_received_percent(void)
// for script match // for script match
ESP_LOGI(TAG, "VendorModel:Statistics"); ESP_LOGI(TAG, "VendorModel:Statistics");
for (j = 0; j < time_level_num; j++) {
printf(",%d:%d", statistics_time_percent[j].time_level, statistics_time_percent[j].time_num);
}
printf("\n");
free(statistics_time_percent); free(statistics_time_percent);
} }
@ -200,7 +264,7 @@ int ble_mesh_test_performance_client_model_accumulate_time(uint16_t time, uint8_
uint16_t sequence_num = 0; uint16_t sequence_num = 0;
uint16_t node_received_ttl = 0; uint16_t node_received_ttl = 0;
// received fail // receive failed
if (length != test_perf_statistics.test_length) { if (length != test_perf_statistics.test_length) {
return 1; return 1;
} }
@ -241,7 +305,6 @@ int ble_mesh_test_performance_client_model_init(uint16_t node_num, uint32_t test
{ {
uint16_t i; uint16_t i;
// malloc time
test_perf_statistics.time = malloc(test_num * sizeof(uint16_t)); test_perf_statistics.time = malloc(test_num * sizeof(uint16_t));
if (test_perf_statistics.time == NULL) { if (test_perf_statistics.time == NULL) {
ESP_LOGE(TAG, " %s %d, malloc fail\n", __func__, __LINE__); ESP_LOGE(TAG, " %s %d, malloc fail\n", __func__, __LINE__);

View file

@ -21,7 +21,7 @@
#include "ble_mesh_console_lib.h" #include "ble_mesh_console_lib.h"
#include "ble_mesh_cfg_srv_model.h" #include "ble_mesh_cfg_srv_model.h"
#define TAG "ble_mesh_prov_console" #define TAG "ble_mesh_console"
#define TRANS_TYPE_MESH_PERF 0x01 #define TRANS_TYPE_MESH_PERF 0x01
#define TRANS_MESH_SEND_MESSAGE 0x01 #define TRANS_MESH_SEND_MESSAGE 0x01
@ -63,48 +63,67 @@ typedef struct {
} ble_mesh_performance_statistics_t; } ble_mesh_performance_statistics_t;
ble_mesh_performance_statistics_t test_perf_statistics; ble_mesh_performance_statistics_t test_perf_statistics;
typedef struct {
uint32_t statistics;
uint32_t package_num;
uint16_t *package_index;
uint32_t total_package_num;
} ble_mesh_node_statistics_t;
ble_mesh_node_statistics_t ble_mesh_node_statistics;
extern SemaphoreHandle_t ble_mesh_node_sema;
#define SEND_MESSAGE_TIMEOUT (30000/portTICK_RATE_MS) #define SEND_MESSAGE_TIMEOUT (30000/portTICK_RATE_MS)
#define arg_int_to_value(src_msg, dst_msg, message) do { \ #define arg_int_to_value(src_msg, dst_msg, message) do { \
if (src_msg->count != 0) {\ if (src_msg->count != 0) {\
ESP_LOGD(TAG, "\n%s, %s\n", __func__, message);\
dst_msg = src_msg->ival[0];\ dst_msg = src_msg->ival[0];\
} \ } \
} while(0) \ } while(0) \
#define ble_mesh_node_get_value(index, key, value) do { \ #define ble_mesh_node_get_value(index, key, value) do { \
uint16_t _index = 0; \ uint16_t _index = 0; \
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY); \
for (_index = 0; _index < NODE_MAX_GROUP_CONFIG; _index) { \ for (_index = 0; _index < NODE_MAX_GROUP_CONFIG; _index) { \
if (node_set_prestore_params[_index].key == value) { \ if (node_set_prestore_params[_index].key == value) { \
break; \ break; \
} \ } \
} \ } \
index = _index; \ index = _index; \
xSemaphoreGive(ble_mesh_node_sema); \
} while(0) \ } while(0) \
#define ble_mesh_node_set_state(status) do { \ #define ble_mesh_node_set_state(status) do { \
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY); \
node_status.previous = node_status.current; \ node_status.previous = node_status.current; \
node_status.current = status; \ node_status.current = status; \
xSemaphoreGive(ble_mesh_node_sema); \
}while(0) \ }while(0) \
#define ble_mesh_node_get_state(status) do { \ #define ble_mesh_node_get_state(status) do { \
status = node_status.previous; \ xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY); \
status = node_status.current; \
xSemaphoreGive(ble_mesh_node_sema); \
}while(0) \ }while(0) \
#define ble_mesh_callback_check_err_code(err_code, message) do { \ #define ble_mesh_callback_check_err_code(err_code, message) do { \
if (err_code == ESP_OK) { \ if (err_code == ESP_OK) { \
ESP_LOGI(TAG, "%s,OK\n", message); \ ESP_LOGI(TAG, "%s,OK\n", message); \
} else { \ } else { \
ESP_LOGI(TAG, "%s,Fail,%d\n", message, err_code); \ ESP_LOGE(TAG, "%s,Fail,%d\n", message, err_code); \
} \ } \
}while(0) \ }while(0) \
void ble_mesh_node_init(void); void ble_mesh_node_init(void);
void ble_mesh_set_node_prestore_params(uint16_t netkey_index, uint16_t unicast_addr); void ble_mesh_set_node_prestore_params(uint16_t netkey_index, uint16_t unicast_addr);
esp_ble_mesh_model_t *ble_mesh_get_model(uint16_t model_id); esp_ble_mesh_model_t *ble_mesh_get_model(uint16_t model_id);
esp_ble_mesh_comp_t *ble_mesh_get_component(uint16_t model_id); esp_ble_mesh_comp_t *ble_mesh_get_component(uint16_t model_id);
void ble_mesh_node_statistics_get(void);
int ble_mesh_node_statistics_accumulate(uint8_t *data, uint32_t value, uint16_t type);
int ble_mesh_node_statistics_init(uint16_t package_num);
void ble_mesh_node_statistics_destroy(void);
void ble_mesh_create_send_data(char *data, uint16_t byte_num, uint16_t sequence_num, uint32_t opcode); void ble_mesh_create_send_data(char *data, uint16_t byte_num, uint16_t sequence_num, uint32_t opcode);
void ble_mesh_test_performance_client_model_get(void); void ble_mesh_test_performance_client_model_get(void);
void ble_mesh_test_performance_client_model_get_received_percent(void); void ble_mesh_test_performance_client_model_get_received_percent(void);
void ble_mesh_test_performance_client_model_accumulate_statistics(uint32_t value); void ble_mesh_test_performance_client_model_accumulate_statistics(uint32_t value);
@ -112,4 +131,4 @@ int ble_mesh_test_performance_client_model_accumulate_time(uint16_t time, uint8_
int ble_mesh_test_performance_client_model_init(uint16_t node_num, uint32_t test_num, uint8_t ttl); int ble_mesh_test_performance_client_model_init(uint16_t node_num, uint32_t test_num, uint8_t ttl);
void ble_mesh_test_performance_client_model_destroy(void); void ble_mesh_test_performance_client_model_destroy(void);
#endif //_BLE_MESH_ADAPTER_H_ #endif //_BLE_MESH_ADAOTER_H_

View file

@ -16,29 +16,24 @@
#include "esp_ble_mesh_generic_model_api.h" #include "esp_ble_mesh_generic_model_api.h"
uint8_t dev_uuid[16] = {0xdd, 0xdd}; uint8_t dev_uuid[16] = {0xdd, 0xdd};
#if CONFIG_BLE_MESH_NODE
esp_ble_mesh_prov_t prov = {
.uuid = dev_uuid,
};
#endif //CONFIG_BLE_MESH_NODE
#if CONFIG_BLE_MESH_PROVISIONER
esp_ble_mesh_prov_t prov = { esp_ble_mesh_prov_t prov = {
#if CONFIG_BLE_MESH_NODE
.uuid = dev_uuid,
#endif //CONFIG_BLE_MESH_NODE
#if CONFIG_BLE_MESH_PROVISIONER
.prov_uuid = dev_uuid, .prov_uuid = dev_uuid,
.prov_unicast_addr = 0x0001, .prov_unicast_addr = 0x0001,
.prov_start_address = 0x0005, .prov_start_address = 0x0005,
.prov_attention = 0x00, .prov_attention = 0x00,
.prov_algorithm = 0x00, .prov_algorithm = 0x00,
.prov_pub_key_oob = 0x00, .prov_pub_key_oob = 0x00,
.prov_pub_key_oob_cb = NULL,
.prov_static_oob_val = NULL, .prov_static_oob_val = NULL,
.prov_static_oob_len = 0x00, .prov_static_oob_len = 0x00,
.prov_input_num = NULL,
.prov_output_num = NULL,
.flags = 0x00, .flags = 0x00,
.iv_index = 0x00, .iv_index = 0x00,
};
#endif //CONFIG_BLE_MESH_PROVISIONER #endif //CONFIG_BLE_MESH_PROVISIONER
};
esp_ble_mesh_model_pub_t vendor_model_pub_config; esp_ble_mesh_model_pub_t vendor_model_pub_config;
ESP_BLE_MESH_MODEL_PUB_DEFINE(model_pub_config, 2 + 1, ROLE_NODE); ESP_BLE_MESH_MODEL_PUB_DEFINE(model_pub_config, 2 + 1, ROLE_NODE);
@ -61,7 +56,7 @@ esp_ble_mesh_cfg_srv_t cfg_srv = {
/* 3 transmissions with 20ms interval */ /* 3 transmissions with 20ms interval */
.net_transmit = ESP_BLE_MESH_TRANSMIT(2, 20), .net_transmit = ESP_BLE_MESH_TRANSMIT(2, 20),
.relay_retransmit = ESP_BLE_MESH_TRANSMIT(0, 20), .relay_retransmit = ESP_BLE_MESH_TRANSMIT(2, 20),
}; };
esp_ble_mesh_model_t config_server_models[] = { esp_ble_mesh_model_t config_server_models[] = {
@ -94,7 +89,7 @@ esp_ble_mesh_comp_t config_client_comp = {
.element_count = ARRAY_SIZE(config_client_elements), .element_count = ARRAY_SIZE(config_client_elements),
}; };
// configure special module // configure special model
ESP_BLE_MESH_MODEL_PUB_DEFINE(onoff_pub_0, 2 + 3, ROLE_NODE); ESP_BLE_MESH_MODEL_PUB_DEFINE(onoff_pub_0, 2 + 3, ROLE_NODE);
static esp_ble_mesh_gen_onoff_srv_t onoff_server = { static esp_ble_mesh_gen_onoff_srv_t onoff_server = {
.rsp_ctrl.get_auto_rsp = ESP_BLE_MESH_SERVER_RSP_BY_APP, .rsp_ctrl.get_auto_rsp = ESP_BLE_MESH_SERVER_RSP_BY_APP,
@ -124,8 +119,8 @@ esp_ble_mesh_client_t gen_onoff_cli;
esp_ble_mesh_model_t gen_onoff_cli_models[] = { esp_ble_mesh_model_t gen_onoff_cli_models[] = {
ESP_BLE_MESH_MODEL_CFG_SRV(&cfg_srv), ESP_BLE_MESH_MODEL_CFG_SRV(&cfg_srv),
ESP_BLE_MESH_MODEL_CFG_CLI(&cfg_cli), ESP_BLE_MESH_MODEL_CFG_CLI(&cfg_cli),
ESP_BLE_MESH_MODEL_GEN_ONOFF_SRV(&onoff_pub_0, &onoff_server),
ESP_BLE_MESH_MODEL_GEN_ONOFF_CLI(&model_pub_config, &gen_onoff_cli), ESP_BLE_MESH_MODEL_GEN_ONOFF_CLI(&model_pub_config, &gen_onoff_cli),
ESP_BLE_MESH_MODEL_GEN_ONOFF_SRV(&onoff_pub_0, &onoff_server),
}; };
esp_ble_mesh_elem_t gen_onoff_cli_elements[] = { esp_ble_mesh_elem_t gen_onoff_cli_elements[] = {

View file

@ -19,6 +19,14 @@ void register_bluetooth(void);
// Register mesh node cmd // Register mesh node cmd
void ble_mesh_register_mesh_node(void); void ble_mesh_register_mesh_node(void);
// Register Test Perf client cmd
void ble_mesh_register_mesh_test_performance_client(void);
#if (CONFIG_BLE_MESH_CFG_CLI)
// Register mesh config client operation cmd
void ble_mesh_register_configuration_client_model(void);
#endif
// Register mesh config server and generic server operation cmd // Register mesh config server and generic server operation cmd
void ble_mesh_register_server(void); void ble_mesh_register_server(void);

View file

@ -20,6 +20,8 @@
#include "nvs.h" #include "nvs.h"
#include "nvs_flash.h" #include "nvs_flash.h"
#include "esp_vfs_fat.h"
#include "esp_bt.h" #include "esp_bt.h"
#include "esp_bt_main.h" #include "esp_bt_main.h"
@ -27,6 +29,8 @@
#include "ble_mesh_console_decl.h" #include "ble_mesh_console_decl.h"
#define TAG "ble_mesh_test"
#if CONFIG_STORE_HISTORY #if CONFIG_STORE_HISTORY
#define MOUNT_PATH "/data" #define MOUNT_PATH "/data"
@ -41,7 +45,6 @@ static void initialize_filesystem(void)
}; };
esp_err_t err = esp_vfs_fat_spiflash_mount(MOUNT_PATH, "storage", &mount_config, &wl_handle); esp_err_t err = esp_vfs_fat_spiflash_mount(MOUNT_PATH, "storage", &mount_config, &wl_handle);
if (err != ESP_OK) { if (err != ESP_OK) {
printf("Failed to mount FATFS (0x%x)", err);
return; return;
} }
} }
@ -54,28 +57,24 @@ esp_err_t bluetooth_init(void)
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
ret = esp_bt_controller_init(&bt_cfg); ret = esp_bt_controller_init(&bt_cfg);
if (ret) { if (ret) {
printf("%s initialize controller failed\n", __func__);
return ret; return ret;
} }
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE); ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
if (ret) { if (ret) {
printf("%s enable controller failed\n", __func__);
return ret; return ret;
} }
ret = esp_bluedroid_init(); ret = esp_bluedroid_init();
if (ret) { if (ret) {
printf("%s init bluetooth failed\n", __func__);
return ret; return ret;
} }
ret = esp_bluedroid_enable(); ret = esp_bluedroid_enable();
if (ret) { if (ret) {
printf("%s enable bluetooth failed\n", __func__);
return ret; return ret;
} }
esp_log_level_set("*", ESP_LOG_ERROR); esp_log_level_set("*", ESP_LOG_ERROR);
esp_log_level_set("ble_mesh_node_console", ESP_LOG_INFO); esp_log_level_set("ble_mesh_console", ESP_LOG_INFO);
return ret; return ret;
} }
@ -98,7 +97,7 @@ void app_main(void)
initialize_filesystem(); initialize_filesystem();
repl_config.history_save_path = HISTORY_PATH; repl_config.history_save_path = HISTORY_PATH;
#endif #endif
repl_config.prompt = "ble_mesh_node>"; repl_config.prompt = "esp32>";
// init console REPL environment // init console REPL environment
ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl)); ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
@ -106,10 +105,14 @@ void app_main(void)
register_system(); register_system();
register_bluetooth(); register_bluetooth();
ble_mesh_register_mesh_node(); ble_mesh_register_mesh_node();
ble_mesh_register_mesh_test_performance_client();
ble_mesh_register_server(); ble_mesh_register_server();
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI) #if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
ble_mesh_register_gen_onoff_client(); ble_mesh_register_gen_onoff_client();
#endif #endif
#if (CONFIG_BLE_MESH_CFG_CLI)
ble_mesh_register_configuration_client_model();
#endif
// start console REPL // start console REPL
ESP_ERROR_CHECK(esp_console_start_repl(repl)); ESP_ERROR_CHECK(esp_console_start_repl(repl));

View file

@ -363,7 +363,6 @@ int ble_mesh_configuration_client_model_operation(int argc, char **argv)
return err; return err;
} }
void ble_mesh_register_configuration_client_model_command(void) void ble_mesh_register_configuration_client_model_command(void)
{ {
configuration_client_model_operation.action_type = arg_str1("z", NULL, "<action>", "action type"); configuration_client_model_operation.action_type = arg_str1("z", NULL, "<action>", "action type");

View file

@ -142,7 +142,8 @@ int ble_mesh_generic_onoff_client_model(int argc, char **argv)
if (gen_onoff_state.action_type->count != 0) { if (gen_onoff_state.action_type->count != 0) {
if (strcmp(gen_onoff_state.action_type->sval[0], "get") == 0) { if (strcmp(gen_onoff_state.action_type->sval[0], "get") == 0) {
err = esp_ble_mesh_generic_client_get_state(&onoff_common, &gen_client_get); err = esp_ble_mesh_generic_client_get_state(&onoff_common, &gen_client_get);
} else if (strcmp(gen_onoff_state.action_type->sval[0], "set") == 0) { }
else if (strcmp(gen_onoff_state.action_type->sval[0], "set") == 0) {
err = esp_ble_mesh_generic_client_set_state(&onoff_common, &gen_client_set); err = esp_ble_mesh_generic_client_set_state(&onoff_common, &gen_client_set);
} else if (strcmp(gen_onoff_state.action_type->sval[0], "reg") == 0) { } else if (strcmp(gen_onoff_state.action_type->sval[0], "reg") == 0) {
err = esp_ble_mesh_register_generic_client_callback(ble_mesh_generic_onoff_client_model_cb); err = esp_ble_mesh_register_generic_client_callback(ble_mesh_generic_onoff_client_model_cb);

View file

@ -23,10 +23,18 @@
#include "esp_ble_mesh_common_api.h" #include "esp_ble_mesh_common_api.h"
#include "esp_ble_mesh_provisioning_api.h" #include "esp_ble_mesh_provisioning_api.h"
#include "esp_ble_mesh_generic_model_api.h" #include "esp_ble_mesh_generic_model_api.h"
#include "ble_mesh_console_lib.h" #include "ble_mesh_console_lib.h"
#include "ble_mesh_adapter.h" #include "ble_mesh_adapter.h"
#include "esp_bt_defs.h"
#include "provisioner_prov.h"
#include "esp_ble_mesh_config_model_api.h"
#include "ble_mesh_console_decl.h"
typedef struct { typedef struct {
struct arg_str *static_val; struct arg_str *static_val;
struct arg_int *static_val_len; struct arg_int *static_val_len;
@ -34,6 +42,7 @@ typedef struct {
struct arg_int *output_actions; struct arg_int *output_actions;
struct arg_int *input_size; struct arg_int *input_size;
struct arg_int *input_actions; struct arg_int *input_actions;
struct arg_int *prov_start_address;
struct arg_end *end; struct arg_end *end;
} ble_mesh_prov_t; } ble_mesh_prov_t;
static ble_mesh_prov_t oob; static ble_mesh_prov_t oob;
@ -84,10 +93,57 @@ ble_mesh_node_status node_status = {
.previous = 0x0, .previous = 0x0,
.current = 0x0, .current = 0x0,
}; };
SemaphoreHandle_t ble_mesh_node_sema; SemaphoreHandle_t ble_mesh_node_sema;
void ble_mesh_register_node_cmd(void); typedef struct {
struct arg_str *add_del;
struct arg_str *device_addr;
struct arg_str *device_uuid;
struct arg_int *addr_type;
struct arg_int *bearer;
struct arg_int *oob_info;
struct arg_int *flag;
struct arg_end *end;
} ble_mesh_provisioner_addr_t;
ble_mesh_provisioner_addr_t provisioner_addr;
typedef struct {
struct arg_str *action_type;
struct arg_int *net_idx;
struct arg_int *app_idx;
struct arg_str *key;
struct arg_end *end;
} ble_mesh_provisioner_add_key_t;
ble_mesh_provisioner_add_key_t provisioner_add_key;
typedef struct {
struct arg_int *unicast_addr;
struct arg_end *end;
} ble_mesh_provisioner_get_node_t;
ble_mesh_provisioner_get_node_t provisioner_get_node;
typedef struct {
struct arg_int *oob_info;
struct arg_int *unicast_addr;
struct arg_int *element_num;
struct arg_int *net_idx;
struct arg_str *dev_key;
struct arg_str *uuid;
struct arg_end *end;
} ble_mesh_provisioner_add_node_t;
ble_mesh_provisioner_add_node_t provisioner_add_node;
typedef struct {
struct arg_int *appkey_index;
struct arg_int *element_address;
struct arg_int *network_index;
struct arg_int *mod_id;
struct arg_int *cid;
struct arg_end *end;
} ble_mesh_provisioner_bind_model_t;
ble_mesh_provisioner_bind_model_t provisioner_local_bind;
void ble_mesh_register_cmd(void);
// Register callback function // Register callback function
void ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_param_t *param); void ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_param_t *param);
void ble_mesh_model_cb(esp_ble_mesh_model_cb_event_t event, esp_ble_mesh_model_cb_param_t *param); void ble_mesh_model_cb(esp_ble_mesh_model_cb_event_t event, esp_ble_mesh_model_cb_param_t *param);
@ -97,17 +153,17 @@ void ble_mesh_generic_server_model_cb(esp_ble_mesh_generic_server_cb_event_t eve
void ble_mesh_register_mesh_node(void) void ble_mesh_register_mesh_node(void)
{ {
ble_mesh_register_node_cmd(); ble_mesh_register_cmd();
} }
int ble_mesh_register_node_cb(int argc, char** argv) int ble_mesh_register_cb(int argc, char** argv)
{ {
ESP_LOGD(TAG, "enter %s\n", __func__); ESP_LOGE(TAG, "enter %s\n", __func__);
ble_mesh_node_init(); ble_mesh_node_init();
esp_ble_mesh_register_prov_callback(ble_mesh_prov_cb); esp_ble_mesh_register_prov_callback(ble_mesh_prov_cb);
esp_ble_mesh_register_custom_model_callback(ble_mesh_model_cb); esp_ble_mesh_register_custom_model_callback(ble_mesh_model_cb);
esp_ble_mesh_register_generic_server_callback(ble_mesh_generic_server_model_cb); esp_ble_mesh_register_generic_server_callback(ble_mesh_generic_server_model_cb);
ESP_LOGI(TAG, "Node:Reg,OK"); ESP_LOGI(TAG, "Bm:Reg,OK");
ESP_LOGD(TAG, "exit %s\n", __func__); ESP_LOGD(TAG, "exit %s\n", __func__);
return 0; return 0;
} }
@ -183,7 +239,7 @@ void ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_p
switch (event) { switch (event) {
case ESP_BLE_MESH_PROV_REGISTER_COMP_EVT: case ESP_BLE_MESH_PROV_REGISTER_COMP_EVT:
ble_mesh_callback_check_err_code(param->prov_register_comp.err_code, "Provisioning:Register"); ble_mesh_callback_check_err_code(param->prov_register_comp.err_code, "Bm:Init");
break; break;
case ESP_BLE_MESH_NODE_PROV_ENABLE_COMP_EVT: case ESP_BLE_MESH_NODE_PROV_ENABLE_COMP_EVT:
ble_mesh_callback_check_err_code(param->node_prov_enable_comp.err_code, "Node:EnBearer"); ble_mesh_callback_check_err_code(param->node_prov_enable_comp.err_code, "Node:EnBearer");
@ -211,7 +267,7 @@ void ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_p
ble_mesh_set_node_prestore_params(param->node_prov_complete.net_idx, param->node_prov_complete.addr); ble_mesh_set_node_prestore_params(param->node_prov_complete.net_idx, param->node_prov_complete.addr);
break; break;
case ESP_BLE_MESH_NODE_PROV_RESET_EVT: case ESP_BLE_MESH_NODE_PROV_RESET_EVT:
ESP_LOGI(TAG, "Node:Reset"); ESP_LOGI(TAG, "Bm:Reset");
break; break;
case ESP_BLE_MESH_NODE_PROV_INPUT_NUMBER_COMP_EVT: case ESP_BLE_MESH_NODE_PROV_INPUT_NUMBER_COMP_EVT:
ble_mesh_callback_check_err_code(param->node_prov_input_num_comp.err_code, "Node:InputNum"); ble_mesh_callback_check_err_code(param->node_prov_input_num_comp.err_code, "Node:InputNum");
@ -231,6 +287,56 @@ void ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_p
case ESP_BLE_MESH_NODE_PROXY_GATT_DISABLE_COMP_EVT: case ESP_BLE_MESH_NODE_PROXY_GATT_DISABLE_COMP_EVT:
ble_mesh_callback_check_err_code(param->node_proxy_gatt_disable_comp.err_code, "Node:DisProxyGatt"); ble_mesh_callback_check_err_code(param->node_proxy_gatt_disable_comp.err_code, "Node:DisProxyGatt");
break; break;
#if (CONFIG_BLE_MESH_PROVISIONER)
case ESP_BLE_MESH_PROVISIONER_RECV_UNPROV_ADV_PKT_EVT:
ESP_LOGD(TAG, "Provisioner recv unprovisioned device beacon:");
ESP_LOG_BUFFER_HEX("Device UUID %s", param->provisioner_recv_unprov_adv_pkt.dev_uuid, 16);
ESP_LOG_BUFFER_HEX("Address %s", param->provisioner_recv_unprov_adv_pkt.addr, 6);
ESP_LOGD(TAG, "Address type 0x%x, oob_info 0x%04x, adv_type 0x%x, bearer 0x%x",
param->provisioner_recv_unprov_adv_pkt.addr_type, param->provisioner_recv_unprov_adv_pkt.oob_info,
param->provisioner_recv_unprov_adv_pkt.adv_type, param->provisioner_recv_unprov_adv_pkt.bearer);
break;
case ESP_BLE_MESH_PROVISIONER_PROV_LINK_OPEN_EVT:
ESP_LOGI(TAG, "Provisioner:LinkOpen,OK,%d", param->provisioner_prov_link_open.bearer);
break;
case ESP_BLE_MESH_PROVISIONER_PROV_LINK_CLOSE_EVT:
ESP_LOGI(TAG, "Provisioner:LinkClose,OK,%d,%d",
param->provisioner_prov_link_close.bearer, param->provisioner_prov_link_close.reason);
break;
case ESP_BLE_MESH_PROVISIONER_ADD_UNPROV_DEV_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_add_unprov_dev_comp.err_code, "Provisioner:DevAdd");
break;
case ESP_BLE_MESH_PROVISIONER_DELETE_DEV_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_delete_dev_comp.err_code, "Provisioner:DevDel");
break;
case ESP_BLE_MESH_PROVISIONER_PROV_COMPLETE_EVT:
ESP_LOGI(TAG, "Provisioner:OK,%d,%d", param->provisioner_prov_complete.netkey_idx, param->provisioner_prov_complete.unicast_addr);
break;
case ESP_BLE_MESH_PROVISIONER_PROV_ENABLE_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_prov_enable_comp.err_code, "Provisioner:EnBearer");
break;
case ESP_BLE_MESH_PROVISIONER_PROV_DISABLE_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_prov_disable_comp.err_code, "Provisioner:DisBearer");
break;
case ESP_BLE_MESH_PROVISIONER_SET_DEV_UUID_MATCH_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_set_dev_uuid_match_comp.err_code, "Provisioner:UuidMatch");
break;
case ESP_BLE_MESH_PROVISIONER_SET_PROV_DATA_INFO_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_set_prov_data_info_comp.err_code, "Provisioner:DataInfo");
break;
case ESP_BLE_MESH_PROVISIONER_SET_NODE_NAME_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_set_node_name_comp.err_code, "Provisioner:NodeName");
break;
case ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_APP_KEY_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_add_app_key_comp.err_code, "Provisioner:AppKeyAdd");
break;
case ESP_BLE_MESH_PROVISIONER_BIND_APP_KEY_TO_MODEL_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_bind_app_key_to_model_comp.err_code, "Provisioner:AppKeyBind");
break;
case ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_NET_KEY_COMP_EVT:
ble_mesh_callback_check_err_code(param->provisioner_add_net_key_comp.err_code, "Provisioner:NetKeyAdd");
break;
#endif
default: default:
break; break;
} }
@ -253,14 +359,14 @@ void ble_mesh_model_cb(esp_ble_mesh_model_cb_event_t event, esp_ble_mesh_model_c
data[1] = param->model_operation.msg[1]; data[1] = param->model_operation.msg[1];
data[2] = param->model_operation.msg[2]; data[2] = param->model_operation.msg[2];
data[3] = param->model_operation.ctx->recv_ttl; data[3] = param->model_operation.ctx->recv_ttl;
result = ble_mesh_node_statistics_accumultate(param->model_operation.msg, param->model_operation.length, VENDOR_MODEL_PERF_OPERATION_TYPE_SET); result = ble_mesh_node_statistics_accumulate(param->model_operation.msg, param->model_operation.length, VENDOR_MODEL_PERF_OPERATION_TYPE_SET);
if (result == 0) { if (result == 0) {
esp_ble_mesh_server_model_send_msg(param->model_operation.model, param->model_operation.ctx, esp_ble_mesh_server_model_send_msg(param->model_operation.model, param->model_operation.ctx,
ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS, sizeof(data), data); ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS, sizeof(data), data);
} }
} else if (param->model_operation.opcode == ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET_UNACK) { } else if (param->model_operation.opcode == ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET_UNACK) {
ESP_LOGI(TAG, "VendorModel:SetUnAck,Success,%d,%d", param->model_operation.ctx->recv_ttl, param->model_operation.length); ESP_LOGI(TAG, "VendorModel:SetUnAck,Success,%d,%d", param->model_operation.ctx->recv_ttl, param->model_operation.length);
result = ble_mesh_node_statistics_accumultate(param->model_operation.msg, param->model_operation.length, VENDOR_MODEL_PERF_OPERATION_TYPE_SET_UNACK); result = ble_mesh_node_statistics_accumulate(param->model_operation.msg, param->model_operation.length, VENDOR_MODEL_PERF_OPERATION_TYPE_SET_UNACK);
if (result == 0) { if (result == 0) {
esp_ble_mesh_server_model_send_msg(param->model_operation.model, param->model_operation.ctx, esp_ble_mesh_server_model_send_msg(param->model_operation.model, param->model_operation.ctx,
ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS, param->model_operation.length, param->model_operation.msg); ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS, param->model_operation.length, param->model_operation.msg);
@ -326,29 +432,50 @@ int ble_mesh_power_set(int argc, char **argv)
static int ble_mesh_load_oob(int argc, char **argv) static int ble_mesh_load_oob(int argc, char **argv)
{ {
uint8_t *static_val; uint8_t *static_val;
int nerrors = arg_parse(argc, argv, (void **) &oob);
ESP_LOGD(TAG, "enter %s \n", __func__); ESP_LOGD(TAG, "enter %s \n", __func__);
int nerrors = arg_parse(argc, argv, (void **) &oob);
if (nerrors != 0) { if (nerrors != 0) {
arg_print_errors(stderr, oob.end, argv[0]); arg_print_errors(stderr, oob.end, argv[0]);
return 1; return 1;
} }
//parsing prov //parsing prov
#if CONFIG_BLE_MESH_NODE
prov.uuid = dev_uuid;
memcpy(dev_uuid, esp_bt_dev_get_address(), BD_ADDR_LEN);
if (oob.static_val->count != 0) { if (oob.static_val->count != 0) {
static_val = malloc(oob.static_val_len->ival[0] + 1); static_val = malloc(oob.static_val_len->ival[0] + 1);
if (static_val == NULL) {
ESP_LOGE(TAG, "malloc fail,%s,%d\n", __func__, __LINE__);
}
get_value_string((char *)oob.static_val->sval[0], (char *)static_val); get_value_string((char *)oob.static_val->sval[0], (char *)static_val);
prov.static_val = static_val; prov.static_val = static_val;
} }
arg_int_to_value(oob.static_val_len, prov.static_val_len, "static_val_len"); arg_int_to_value(oob.static_val_len, prov.static_val_len, "static value length");
arg_int_to_value(oob.output_size, prov.output_size, "output_size"); arg_int_to_value(oob.output_size, prov.output_size, "output size");
arg_int_to_value(oob.output_actions, prov.output_actions, "output_actions"); arg_int_to_value(oob.output_actions, prov.output_actions, "output actions");
arg_int_to_value(oob.input_size, prov.input_size, "input_size"); arg_int_to_value(oob.input_size, prov.input_size, "input size");
arg_int_to_value(oob.input_actions, prov.input_actions, "input_action"); arg_int_to_value(oob.input_actions, prov.input_actions, "input actions");
#endif
#if CONFIG_BLE_MESH_PROVISIONER
if (oob.static_val->count != 0) {
static_val = malloc(oob.static_val_len->ival[0] + 1);
if (static_val == NULL) {
ESP_LOGE(TAG, "malloc fail,%s,%d\n", __func__, __LINE__);
}
get_value_string((char *)oob.static_val->sval[0], (char *)static_val);
prov.prov_static_oob_val = static_val;
}
arg_int_to_value(oob.prov_start_address, prov.prov_start_address, "provisioner start address");
arg_int_to_value(oob.static_val_len, prov.prov_static_oob_len, "provisioner static value length");
#endif
ESP_LOGI(TAG, "OOB:Load,OK\n"); ESP_LOGI(TAG, "OOB:Load,OK\n");
ESP_LOGD(TAG, "exit %s\n", __func__); ESP_LOGD(TAG, "exit %s\n", __func__);
return 0; return 0;
} }
@ -380,11 +507,13 @@ int ble_mesh_init(int argc, char **argv)
str_2_mac((uint8_t *)component.dev_uuid->sval[0], device_uuid); str_2_mac((uint8_t *)component.dev_uuid->sval[0], device_uuid);
memcpy(dev_uuid, device_uuid, BD_ADDR_LEN); memcpy(dev_uuid, device_uuid, BD_ADDR_LEN);
} }
} else {
memcpy(dev_uuid, esp_bt_dev_get_address(), 6);
} }
err = esp_ble_mesh_init(&prov, local_component); err = esp_ble_mesh_init(&prov, local_component);
if (err) { if (err) {
ESP_LOGE(TAG, "Initializing mesh failed (err %d)\n", err); ESP_LOGI(TAG, "Bm:Init,OK\n");
return err; return err;
} }
@ -402,6 +531,7 @@ int ble_mesh_node_enable_bearer(int argc, char **argv)
int nerrors = arg_parse(argc, argv, (void **) &bearer); int nerrors = arg_parse(argc, argv, (void **) &bearer);
if (nerrors != 0) { if (nerrors != 0) {
arg_print_errors(stderr, bearer.end, argv[0]); arg_print_errors(stderr, bearer.end, argv[0]);
return 1; return 1;
} }
@ -420,6 +550,32 @@ int ble_mesh_node_enable_bearer(int argc, char **argv)
return err; return err;
} }
int ble_mesh_provisioner_enable_bearer(int argc, char **argv)
{
esp_err_t err = 0;
ESP_LOGD(TAG, "enter %s \n", __func__);
int nerrors = arg_parse(argc, argv, (void **) &bearer);
if (nerrors != 0) {
arg_print_errors(stderr, bearer.end, argv[0]);
return 1;
}
if (bearer.enable->count != 0) {
if (bearer.enable->ival[0]) {
err = esp_ble_mesh_provisioner_prov_enable(bearer.bearer->ival[0]);
} else {
err = esp_ble_mesh_provisioner_prov_disable(bearer.bearer->ival[0]);
}
} else {
return 1;
}
ESP_LOGD(TAG, "exit %s\n", __func__);
return err;
}
int ble_mesh_node_reset(int argc, char** argv) int ble_mesh_node_reset(int argc, char** argv)
{ {
esp_err_t err; esp_err_t err;
@ -493,33 +649,201 @@ int ble_mesh_node_enter_network_auto(int argc, char **argv)
return err; return err;
} }
void ble_mesh_register_node_cmd(void) int ble_mesh_provision_address(int argc, char **argv)
{
esp_err_t err = ESP_OK;
esp_ble_mesh_unprov_dev_add_t device_addr = {0};
uint8_t preset_addr_uuid[16] = {0x01, 0x02};
esp_ble_mesh_device_delete_t del_dev = {
.flag = BIT(0),
};
ESP_LOGD(TAG, "enter %s \n", __func__);
int nerrors = arg_parse(argc, argv, (void **) &provisioner_addr);
if (nerrors != 0) {
arg_print_errors(stderr, provisioner_addr.end, argv[0]);
return 1;
}
memcpy(device_addr.uuid, preset_addr_uuid, BD_ADDR_LEN);
if (provisioner_addr.device_addr->count != 0) {
str_2_mac((uint8_t *)provisioner_addr.device_addr->sval[0], device_addr.addr);
str_2_mac((uint8_t *)provisioner_addr.device_addr->sval[0], del_dev.addr);
arg_int_to_value(provisioner_addr.addr_type, device_addr.addr_type, "address type");
arg_int_to_value(provisioner_addr.addr_type, del_dev.addr_type, "address type");
} else if (provisioner_addr.device_uuid->count != 0) {
get_value_string((char *)provisioner_addr.device_uuid->sval[0], (char *)device_addr.uuid);
get_value_string((char *)provisioner_addr.device_uuid->sval[0], (char *)del_dev.uuid);
del_dev.flag = BIT(1);
}
#if CONFIG_BLE_MESH_PROVISIONER
if (strcmp(provisioner_addr.add_del->sval[0], "add") == 0) {
arg_int_to_value(provisioner_addr.bearer, device_addr.bearer, "bearer");
arg_int_to_value(provisioner_addr.oob_info, device_addr.oob_info, "oob information");
err = esp_ble_mesh_provisioner_add_unprov_dev(&device_addr, provisioner_addr.flag->ival[0]);
} else if (strcmp(provisioner_addr.add_del->sval[0], "del") == 0) {
err = esp_ble_mesh_provisioner_delete_dev(&del_dev);
}
#endif
if (err != ESP_OK) {
ESP_LOGI(TAG, "Provisioner:AddDelAddr,Fail,%d", err);
} else {
ESP_LOGI(TAG, "Provisioner:AddDelAddr,OK");
}
ESP_LOGD(TAG, "exit %s \n", __func__);
return err;
}
int ble_mesh_provisioner_add_key(int argc, char **argv)
{
esp_err_t err = ESP_OK;
uint8_t key[16] = {0};
esp_ble_mesh_prov_data_info_t info = {
.net_idx = 1,
.flag = NET_IDX_FLAG,
};
ESP_LOGD(TAG, " enter %s\n", __func__);
int nerrors = arg_parse(argc, argv, (void **) &provisioner_add_key);
if (nerrors != 0) {
arg_print_errors(stderr, provisioner_add_key.end, argv[0]);
return 1;
}
err = get_value_string((char *)provisioner_add_key.key->sval[0], (char *) key);
if (strcmp(provisioner_add_key.action_type->sval[0], "appkey") == 0) {
err = esp_ble_mesh_provisioner_add_local_app_key(key, provisioner_add_key.net_idx->ival[0], provisioner_add_key.app_idx->ival[0]);
} else if (strcmp(provisioner_add_key.action_type->sval[0], "netkey") == 0) {
// choose network key
info.net_idx = provisioner_add_key.net_idx->ival[0];
err = esp_ble_mesh_provisioner_add_local_net_key(key, provisioner_add_key.net_idx->ival[0]);
err = err | esp_ble_mesh_provisioner_set_prov_data_info(&info);
}
if (err != ESP_OK) {
ESP_LOGI(TAG, "Provisioner:KeyAction,Fail,%d", err);
} else {
ESP_LOGI(TAG, "Provisioner:KeyAction,OK");
}
ESP_LOGD(TAG, "exit %s\n", __func__);
return err;
}
int ble_mesh_provisioner_get_node(int argc, char **argv)
{
uint16_t unicast_addr = 0;
uint16_t i = 0;
esp_ble_mesh_node_t *node_info;
ESP_LOGD(TAG, "enter %s\n", __func__);
int nerrors = arg_parse(argc, argv, (void **) &provisioner_get_node);
if (nerrors != 0) {
arg_print_errors(stderr, provisioner_get_node.end, argv[0]);
return 1;
}
arg_int_to_value(provisioner_get_node.unicast_addr, unicast_addr, "unicast address");
node_info = esp_ble_mesh_provisioner_get_node_with_addr(unicast_addr);
if (node_info == NULL) {
return ESP_FAIL;
} else {
printf("OobInfo:0x%x,Address:0x%x,EleNum:0x%x,NetIdx:0x%x,DevKey:",
node_info->oob_info, node_info->unicast_addr, node_info->element_num, node_info->net_idx);
for (i = 0; i < 16; i++) {
printf("%02x", node_info->dev_key[i]);
}
printf(",DevUuid:");
for (i = 0; i < 16; i++) {
printf("%02x", node_info->dev_uuid[i]);
}
printf("\n");
}
ESP_LOGD(TAG, "exit %s\n", __func__);
return ESP_OK;
}
int ble_mesh_provisioner_add_node(int argc, char **argv)
{
struct bt_mesh_node node_info;
esp_err_t result;
ESP_LOGD(TAG, " enter %s\n", __func__);
int nerrors = arg_parse(argc, argv, (void **) &provisioner_add_node);
if (nerrors != 0) {
arg_print_errors(stderr, provisioner_add_node.end, argv[0]);
return 1;
}
arg_int_to_value(provisioner_add_node.oob_info, node_info.oob_info, "oob information");
arg_int_to_value(provisioner_add_node.unicast_addr, node_info.unicast_addr, "unicast address");
arg_int_to_value(provisioner_add_node.element_num, node_info.element_num, "element number");
arg_int_to_value(provisioner_add_node.net_idx, node_info.net_idx, "network index");
if (provisioner_add_node.dev_key->count != 0) {
get_value_string((char *)provisioner_add_node.dev_key->sval[0], (char *)node_info.dev_key);
}
if (provisioner_add_node.uuid->count != 0) {
get_value_string((char *)provisioner_add_node.uuid->sval[0], (char *)node_info.dev_uuid);
get_value_string((char *)provisioner_add_node.uuid->sval[0], (char *)node_info.dev_uuid);
}
result = bt_mesh_provisioner_store_node_info(&node_info);
if (result == ESP_OK) {
ESP_LOGI(TAG, "Provisioner:AddNodeInfo,OK\n");
} else {
ESP_LOGI(TAG, "Provisioner:AddNodeInfo,ERROR,%d\n", result);
}
ESP_LOGD(TAG, "exit %s\n", __func__);
return result;
}
int ble_mesh_provision_bind_local_model(int argc, char **argv)
{
esp_err_t err;
uint16_t element_addr = 0;
uint16_t app_idx = 0;
uint16_t model_id = 0;
uint16_t company_id = 0xFFFF;
ESP_LOGD(TAG, " enter %s\n", __func__);
int nerrors = arg_parse(argc, argv, (void **) &provisioner_local_bind);
if (nerrors != 0) {
arg_print_errors(stderr, provisioner_local_bind.end, argv[0]);
return 1;
}
arg_int_to_value(provisioner_local_bind.element_address, element_addr, "element address");
arg_int_to_value(provisioner_local_bind.appkey_index, app_idx, "appkey index");
arg_int_to_value(provisioner_local_bind.mod_id, model_id, "model id");
arg_int_to_value(provisioner_local_bind.cid, company_id, "company id");
err = esp_ble_mesh_provisioner_bind_app_key_to_local_model(element_addr, app_idx, model_id, company_id);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Provisioner:BindModel,Fail,%d\n", err);
} else {
ESP_LOGI(TAG, "Provisioner:BindModel,OK\n");
}
ESP_LOGD(TAG, "exit %s\n", __func__);
return err;
}
void ble_mesh_register_cmd(void)
{ {
const esp_console_cmd_t register_cmd = { const esp_console_cmd_t register_cmd = {
.command = "bmreg", .command = "bmreg",
.help = "ble mesh: provisioner/node register callback", .help = "ble mesh: provisioner/node register callback",
.hint = NULL, .hint = NULL,
.func = &ble_mesh_register_node_cb, .func = &ble_mesh_register_cb,
}; };
ESP_ERROR_CHECK(esp_console_cmd_register(&register_cmd)); ESP_ERROR_CHECK(esp_console_cmd_register(&register_cmd));
oob.static_val = arg_str0("s", NULL, "<value>", "Static OOB value");
oob.static_val_len = arg_int0("l", NULL, "<length>", "Static OOB value length");
oob.output_size = arg_int0("x", NULL, "<size>", "Maximum size of Output OOB");
oob.output_actions = arg_int0("o", NULL, "<actions>", "Supported Output OOB Actions");
oob.input_size = arg_int0("y", NULL, "<size>", "Maximum size of Input OOB");
oob.input_actions = arg_int0("i", NULL, "<actions>", "Supported Input OOB Actions");
oob.end = arg_end(1);
const esp_console_cmd_t oob_cmd = {
.command = "bmoob",
.help = "ble mesh: provisioner/node config OOB parameters",
.hint = NULL,
.func = &ble_mesh_load_oob,
.argtable = &oob,
};
ESP_ERROR_CHECK( esp_console_cmd_register(&oob_cmd) );
component.model_type = arg_int0("m", NULL, "<model>", "mesh model"); component.model_type = arg_int0("m", NULL, "<model>", "mesh model");
component.config_index = arg_int0("c", NULL, "<index>", "mesh model op"); component.config_index = arg_int0("c", NULL, "<index>", "mesh model op");
component.config_index->ival[0] = 0; // set default value component.config_index->ival[0] = 0; // set default value
@ -536,18 +860,79 @@ void ble_mesh_register_node_cmd(void)
}; };
ESP_ERROR_CHECK( esp_console_cmd_register(&model_cmd) ); ESP_ERROR_CHECK( esp_console_cmd_register(&model_cmd) );
provisioner_addr.add_del = arg_str1("z", NULL, "<add/delete>", "action type");
provisioner_addr.device_addr = arg_str0("d", NULL, "<address>", "device address");
provisioner_addr.device_uuid = arg_str0("u", NULL, "<uuid>", "device uuid");
provisioner_addr.addr_type = arg_int0("a", NULL, "<type>", "address type");
provisioner_addr.flag = arg_int0("f", NULL, "<flag>", "address flag");
provisioner_addr.flag->ival[0] = ADD_DEV_RM_AFTER_PROV_FLAG | ADD_DEV_FLUSHABLE_DEV_FLAG;
provisioner_addr.bearer = arg_int0("b", NULL, "<bearer>", "used bearer");
provisioner_addr.oob_info = arg_int0("o", NULL, "<oob info>", "oob information");
provisioner_addr.end = arg_end(1);
const esp_console_cmd_t provisioner_addr_cmd = {
.command = "bmpdev",
.help = "ble mesh provisioner: add/delete unprovisioned device",
.hint = NULL,
.func = &ble_mesh_provision_address,
.argtable = &provisioner_addr,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_addr_cmd));
oob.static_val = arg_str0("s", NULL, "<value>", "Static OOB value");
oob.static_val_len = arg_int0("l", NULL, "<length>", "Static OOB value length");
oob.output_size = arg_int0("x", NULL, "<size>", "Maximum size of Output OOB");
oob.output_actions = arg_int0("o", NULL, "<actions>", "Supported Output OOB Actions");
oob.input_size = arg_int0("y", NULL, "<size>", "Maximum size of Input OOB");
oob.input_actions = arg_int0("i", NULL, "<actions>", "Supported Input OOB Actions");
oob.prov_start_address = arg_int0("p", NULL, "<address>", "start address assigned by provisioner");
oob.prov_start_address->ival[0] = 0x0005;
oob.end = arg_end(1);
const esp_console_cmd_t oob_cmd = {
.command = "bmoob",
.help = "ble mesh: provisioner/node config OOB parameters",
.hint = NULL,
.func = &ble_mesh_load_oob,
.argtable = &oob,
};
ESP_ERROR_CHECK( esp_console_cmd_register(&oob_cmd) );
bearer.bearer = arg_int0("b", NULL, "<bearer>", "supported bearer"); bearer.bearer = arg_int0("b", NULL, "<bearer>", "supported bearer");
bearer.enable = arg_int0("e", NULL, "<enable/disable>", "bearers node supported"); bearer.enable = arg_int0("e", NULL, "<enable/disable>", "bearers node supported");
bearer.end = arg_end(1); bearer.end = arg_end(1);
const esp_console_cmd_t bearer_cmd = { const esp_console_cmd_t bearer_node_cmd = {
.command = "bmnbearer", .command = "bmnbearer",
.help = "ble mesh node: enable/disable different bearer", .help = "ble mesh node/porvisioner: enable/disable different bearer",
.hint = NULL, .hint = NULL,
.func = &ble_mesh_node_enable_bearer, .func = &ble_mesh_node_enable_bearer,
.argtable = &bearer, .argtable = &bearer,
}; };
ESP_ERROR_CHECK(esp_console_cmd_register(&bearer_cmd)); ESP_ERROR_CHECK(esp_console_cmd_register(&bearer_node_cmd));
const esp_console_cmd_t bearer_provisioner_cmd = {
.command = "bmpbearer",
.help = "ble mesh provisioner: enable/disable different bearers",
.hint = NULL,
.func = &ble_mesh_provisioner_enable_bearer,
.argtable = &bearer,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&bearer_provisioner_cmd));
provisioner_add_key.action_type = arg_str1("z", NULL, "<action type>", "add appkey or network key");
provisioner_add_key.net_idx = arg_int1("n", NULL, "<net key index>", "network key index");
provisioner_add_key.key = arg_str1("k", NULL, "<key>", "appkey or network");
provisioner_add_key.app_idx = arg_int0("a", NULL, "<app key index>", "appkey index");
provisioner_add_key.end = arg_end(1);
const esp_console_cmd_t provisioner_add_key_cmd = {
.command = "bmpkey",
.help = "ble mesh provisioner: key",
.func = &ble_mesh_provisioner_add_key,
.argtable = &provisioner_add_key,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_add_key_cmd));
const esp_console_cmd_t reset_cmd = { const esp_console_cmd_t reset_cmd = {
.command = "bmnreset", .command = "bmnreset",
@ -583,6 +968,48 @@ void ble_mesh_register_node_cmd(void)
}; };
ESP_ERROR_CHECK(esp_console_cmd_register(&power_set_cmd)); ESP_ERROR_CHECK(esp_console_cmd_register(&power_set_cmd));
provisioner_get_node.unicast_addr = arg_int1("u", NULL, "<address>", "get node by unicast address");
provisioner_get_node.end = arg_end(1);
const esp_console_cmd_t provisioner_get_node_cmd = {
.command = "bmpgetn",
.help = "ble mesh provisioner: get node",
.func = &ble_mesh_provisioner_get_node,
.argtable = &provisioner_get_node,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_get_node_cmd));
provisioner_add_node.oob_info = arg_int0("o", NULL, "<oob info>", "oob information");
provisioner_add_node.unicast_addr = arg_int0("a", NULL, "<unicast address>", "unicast address");
provisioner_add_node.element_num = arg_int0("e", NULL, "<element num>", "element num");
provisioner_add_node.net_idx = arg_int0("n", NULL, "<net index>", "net index");
provisioner_add_node.dev_key = arg_str0("d", NULL, "<device key>", "device key");
provisioner_add_node.uuid = arg_str0("u", NULL, "<device uuid>", "device uuid");
provisioner_add_node.end = arg_end(1);
const esp_console_cmd_t provisioner_add_node_cmd = {
.command = "bmpaddn",
.help = "ble mesh provisioner: add node",
.func = &ble_mesh_provisioner_add_node,
.argtable = &provisioner_add_node,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_add_node_cmd));
provisioner_local_bind.appkey_index = arg_int1("a", NULL, "<appkey index>", "appkey index");
provisioner_local_bind.element_address = arg_int1("e", NULL, "<element address>", "element address");
provisioner_local_bind.network_index = arg_int1("n", NULL, "<network index>", "network index");
provisioner_local_bind.mod_id = arg_int1("m", NULL, "<model id>", "model id");
provisioner_local_bind.cid = arg_int0("c", NULL, "<model id>", "company id");
provisioner_local_bind.end = arg_end(1);
const esp_console_cmd_t provisioner_local_bind_cmd = {
.command = "bmpbind",
.help = "ble mesh provisioner: bind local model",
.func = &ble_mesh_provision_bind_local_model,
.argtable = &provisioner_local_bind,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_local_bind_cmd));
node_network_info.net_key = arg_str1("k", NULL, "<net key>", "network key"); node_network_info.net_key = arg_str1("k", NULL, "<net key>", "network key");
node_network_info.net_idx = arg_int1("n", NULL, "<net index>", "network key index"); node_network_info.net_idx = arg_int1("n", NULL, "<net index>", "network key index");
node_network_info.unicast_addr = arg_int1("u", NULL, "<unicast address>", "unicast address"); node_network_info.unicast_addr = arg_int1("u", NULL, "<unicast address>", "unicast address");

View file

@ -0,0 +1,4 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 2M,
1 # Name Type SubType Offset Size Flags
2 nvs data nvs 0x9000 0x6000
3 phy_init data phy 0xf000 0x1000
4 factory app factory 0x10000 2M

View file

@ -18,4 +18,12 @@ CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=3
CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=3 CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=3
CONFIG_BLE_MESH_CFG_CLI=y CONFIG_BLE_MESH_CFG_CLI=y
CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y
CONFIG_BLE_MESH_PROVISIONER=y
CONFIG_BLE_MESH_SELF_TEST=y CONFIG_BLE_MESH_SELF_TEST=y
CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK=y
# partitions
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"