Wirepas SDK
provisioning_joining_node/app.c
/* Copyright 2019 Wirepas Ltd. All Rights Reserved.
*
* See file LICENSE.txt for full license details.
*
*/
/*
* \file app.c
* \brief This file is an application example to use the provisioning
* library.
*/
#include "api.h"
#include "button.h"
#include "app_scheduler.h"
#include "shared_data.h"
#include "provisioning.h"
#include "storage.h"
#define DEBUG_LOG_MODULE_NAME "PROV APP"
#define DEBUG_LOG_MAX_LEVEL LVL_INFO
#include "debug_log.h"
//#define LOW_LATENCY_NODE 1
const app_lib_joining_received_beacon_t * select_joining_beacon(
const app_lib_joining_received_beacon_t * beacons)
{
const app_lib_joining_received_beacon_t * strongest_beacon = NULL;
int16_t strongest_rssi = INT16_MIN; // RSSI is int8_t, so > INT16_MIN
while (beacons != NULL)
{
if (beacons->rssi > strongest_rssi)
{
strongest_beacon = beacons;
strongest_rssi = beacons->rssi;
}
beacons = beacons->next;
}
return strongest_beacon;
}
void user_data_cb(uint32_t id, CborType type, uint8_t * data, uint8_t len)
{
LOG(LVL_INFO, "User Data, id:%d, type:%d, data:",id, type);
LOG_BUFFER(LVL_DEBUG, data, len);
return;
}
bool end_cb(provisioning_res_e res)
{
LOG(LVL_INFO, "Provisioning ended with result: %d", res);
return true;
}
void button_0_cb(uint8_t button_id, button_event_e event)
{
}
void App_init(const app_global_functions_t * functions)
{
app_addr_t addr;
int8_t uid_len, key_len;
{
.nb_retry = 3,
#ifdef LOW_LATENCY_NODE
.timeout_s = 20,
#else
.timeout_s = 120,
#endif
/* Method, Unique ID and shared key are loaded from storage module.
* .method = ,
* .uid = ,
* .uid_len = ,
* .key = ,
* .key_len = ,
*/
.end_cb = end_cb,
.user_data_cb = user_data_cb,
.beacon_joining_cb = select_joining_beacon
};
LOG(LVL_INFO, "Starting");
/* Basic configuration of the node with a unique node address. */
{
/* Could not configure the node. It should not happen except if one of
* the config value is invalid.
*/
return;
}
/* Configure new node. */
#ifdef LOW_LATENCY_NODE
lib_settings->setNodeRole(APP_LIB_SETTINGS_ROLE_SUBNODE_LL);
#else
lib_settings->setNodeRole(APP_LIB_SETTINGS_ROLE_SUBNODE_LE);
#endif
/* Print actual node config. */
LOG(LVL_DEBUG, "Node network parameters:");
lib_settings->getNodeAddress(&addr);
lib_settings->getNetworkAddress(&net_addr);
lib_settings->getNetworkChannel(&net_channel);
LOG(LVL_DEBUG, " - node addr: %08X", addr);
LOG(LVL_DEBUG, " - net addr: %06X", net_addr);
LOG(LVL_DEBUG, " - net ch: %d", net_channel);
if (!Storage_init())
{
LOG(LVL_ERROR, "Error opening provisioning storage.");
}
else
{
uid_len = Storage_getUID(&conf.uid);
key_len = Storage_getKey(&conf.key);
method = Storage_getMethod();
if (uid_len != -1 && key_len != -1)
{
conf.uid_len = uid_len;
conf.key_len = key_len;
conf.method = method;
}
else
{
LOG(LVL_ERROR, "Can't retrieve node UID or provisioning Key.");
}
}
/* Start the stack */
lib_state->startStack();
}
provisioning_conf_t::uid
const uint8_t * uid
Definition: provisioning.h:142
LVL_INFO
#define LVL_INFO
Definition: debug_log.h:83
provisioning_res_e
provisioning_res_e
Provisioning result.
Definition: provisioning.h:26
app_lib_settings_net_channel_t
uint8_t app_lib_settings_net_channel_t
Network channel type definition.
Definition: wms_settings.h:60
APP_LIB_SETTINGS_ROLE_SUBNODE_LE
@ APP_LIB_SETTINGS_ROLE_SUBNODE_LE
Definition: wms_settings.h:72
LVL_ERROR
#define LVL_ERROR
Definition: debug_log.h:85
provisioning_conf_t::method
provisioning_method_e method
Definition: provisioning.h:136
Provisioning_start
provisioning_ret_e Provisioning_start(void)
Start the provisioning process.
LOG_BUFFER
#define LOG_BUFFER(level, buffer, size)
Print a buffer if its severity is lower or equal to DEBUG_LOG_MAX_LEVEL.
Definition: debug_log.h:193
Provisioning_init
provisioning_ret_e Provisioning_init(provisioning_conf_t *conf)
Initialize the provisioning process.
button.h
Board-independent button functions.
provisioning_conf_t
This structure holds the provisioning parameters.
Definition: provisioning.h:133
node_configuration.h
app_lib_settings_net_addr_t
uint32_t app_lib_settings_net_addr_t
Network address type definition.
Definition: wms_settings.h:53
APP_RES_OK
@ APP_RES_OK
Definition: wms_app.h:204
provisioning_method_e
provisioning_method_e
supported provisioning methods
Definition: provisioning.h:43
provisioning_conf_t::uid_len
uint8_t uid_len
Definition: provisioning.h:144
app_scheduler.h
CborType
CborType
Definition: cbor.h:82
app_global_functions_t
List of global functions, passed to App_entrypoint()
Definition: wms_app.h:157
debug_log.h
Button_register_for_event
button_res_e Button_register_for_event(uint8_t button_id, button_event_e event, on_button_event_cb cb)
Register for a button event.
provisioning_conf_t::key
const uint8_t * key
Definition: provisioning.h:149
configureNodeFromBuildParameters
__STATIC_INLINE app_res_e configureNodeFromBuildParameters()
Wrapper on top of configureNode to get parameters from build system and hardcoded values from chip (f...
Definition: node_configuration.h:233
LVL_DEBUG
#define LVL_DEBUG
Macros to define several log levels: Debug, Info, Warning, Error.
Definition: debug_log.h:82
app_addr_t
uint32_t app_addr_t
Definition: wms_app.h:228
APP_LIB_SETTINGS_ROLE_SUBNODE_LL
@ APP_LIB_SETTINGS_ROLE_SUBNODE_LL
Definition: wms_settings.h:74
LOG_INIT
#define LOG_INIT()
Definition: debug_log.h:66
shared_data.h
LOG
#define LOG(level, fmt,...)
Print a log message if its severity is lower or equal to DEBUG_LOG_MAX_LEVEL.
Definition: debug_log.h:172
provisioning_conf_t::nb_retry
uint8_t nb_retry
Definition: provisioning.h:138
Button_init
void Button_init(void)
Initialize Button module.
BUTTON_PRESSED
@ BUTTON_PRESSED
Definition: button.h:18
provisioning_conf_t::key_len
uint8_t key_len
Definition: provisioning.h:151
provisioning.h
api.h
button_event_e
button_event_e
Different events for a button.
Definition: button.h:17