GrowNode
grownode.c File Reference

Macros

#define TAG   "grownode"
 
#define TAG_EVENT   "gn_event"
 
#define TAG_NVS   "gn_nvs"
 
#define TIMER_DIVIDER   (16)
 
#define TIMER_SCALE   (TIMER_BASE_CLK / TIMER_DIVIDER)
 
#define STORAGE_NAMESPACE   "grownode"
 

Functions

 ESP_EVENT_DEFINE_BASE (GN_BASE_EVENT)
 
 ESP_EVENT_DEFINE_BASE (GN_LEAF_EVENT)
 
gn_err_t _gn_leaf_start (gn_leaf_config_handle_intl_t leaf_config)
 start the leaf by starting a new task and subscribing to network messages More...
 
gn_err_t _gn_init_flash (gn_config_handle_t conf)
 
esp_err_t _gn_init_spiffs (gn_config_handle_intl_t conf)
 
static bool IRAM_ATTR _gn_timer_callback_isr (void *args)
 
void _gn_keepalive_start ()
 
void _gn_keepalive_stop ()
 
gn_leaf_config_handle_intl_t _gn_leaf_get_by_name (char *leaf_name)
 
gn_err_t _gn_send_event_to_leaf (gn_leaf_config_handle_intl_t leaf_config, gn_leaf_parameter_event_handle_t evt)
 send event to leaf using xQueueSend. the data will be null terminated. More...
 
void _gn_evt_handler (void *handler_args, esp_event_base_t base, int32_t id, void *event_data)
 
esp_err_t _gn_evt_handlers_register (gn_config_handle_intl_t conf)
 
esp_err_t _gn_init_keepalive_timer (gn_config_handle_intl_t conf)
 
gn_config_handle_intl_t _gn_config_create (gn_config_init_param_t *config_init)
 initialize config More...
 
esp_err_t _gn_init_event_loop (gn_config_handle_intl_t config)
 
gn_node_handle_intl_t _gn_node_config_create ()
 
gn_node_status_t gn_get_status (gn_config_handle_t config)
 retrieves the configuration status More...
 
const char * gn_get_status_description (gn_config_handle_t config)
 retrieves the configuration status description More...
 
esp_event_loop_handle_t gn_get_event_loop (gn_config_handle_t config)
 retrieves the event loop starting from the config handle More...
 
esp_event_loop_handle_t gn_leaf_get_event_loop (gn_leaf_handle_t leaf_config)
 retrieves the event loop starting from the leaf config handle More...
 
esp_event_loop_handle_t gn_node_get_event_loop (gn_node_handle_t node)
 retrieves the event loop from the node More...
 
gn_node_handle_t gn_node_create (gn_config_handle_t config, const char *name)
 create a new node with specified configuration and name More...
 
size_t gn_node_get_size (gn_node_handle_t node_config)
 number of leaves into the node More...
 
gn_err_t gn_node_destroy (gn_node_handle_t node)
 removes the node from the config More...
 
gn_err_t gn_node_start (gn_node_handle_t node)
 starts the node by starting the leaves tasks More...
 
gn_leaf_config_handle_intl_t _gn_leaf_config_create ()
 
gn_err_t gn_node_get_name (gn_node_handle_t node_config, char *name)
 gets the name of the node referenced by the handle More...
 
gn_leaf_handle_t gn_leaf_create (gn_node_handle_t node_config, const char *name, gn_leaf_config_callback callback, size_t task_size)
 creates the leaf More...
 
gn_leaf_descriptor_handle_t gn_leaf_get_descriptor (gn_leaf_handle_t leaf_config)
 
gn_err_t _gn_leaf_destroy (gn_leaf_handle_t leaf_config)
 
gn_err_t gn_leaf_get_name (gn_leaf_handle_t leaf_config, char *name)
 gets the name of the leaf referenced by the handle More...
 
gn_leaf_handle_t gn_leaf_get_config_handle (gn_node_handle_t node, const char *name)
 
gn_node_handle_t gn_leaf_get_node (gn_leaf_handle_t leaf_config)
 
QueueHandle_t gn_leaf_get_event_queue (gn_leaf_handle_t leaf_config)
 gets the leaf queue handle More...
 
void _gn_leaf_evt_handler (void *handler_args, esp_event_base_t base, int32_t id, void *event_data)
 
gn_err_t gn_leaf_event_subscribe (gn_leaf_handle_t leaf_config, gn_event_id_t event_id)
 subscribe the leaf to the event id. More...
 
gn_err_t gn_leaf_event_unsubscribe (gn_leaf_handle_t leaf_config, gn_event_id_t event_id)
 unsubscribe the leaf to the event id. More...
 
gn_leaf_param_handle_t gn_leaf_param_create (gn_leaf_handle_t leaf_config, const char *name, const gn_val_type_t type, gn_val_t val, gn_leaf_param_access_type_t access, gn_leaf_param_storage_t storage, gn_validator_callback_t validator)
 
gn_err_t gn_leaf_param_init_string (const gn_leaf_handle_t leaf_config, const char *name, const char *val)
 init the parameter with new value and stores in NVS flash, overwriting previous values More...
 
gn_err_t gn_leaf_param_write_string (const gn_leaf_handle_t leaf_config, const char *name, char *val)
 updates the parameter with new value More...
 
gn_err_t gn_leaf_param_get_string (const gn_leaf_handle_t leaf_config, const char *name, char *val, size_t max_lenght)
 gets the parameter value More...
 
gn_err_t gn_leaf_param_init_bool (const gn_leaf_handle_t leaf_config, const char *name, bool val)
 init the parameter with new value and stores in NVS flash, overwriting previous values More...
 
gn_err_t gn_leaf_param_write_bool (const gn_leaf_handle_t leaf_config, const char *name, bool val)
 updates the parameter with new value More...
 
gn_err_t gn_leaf_param_write (const gn_leaf_param_handle_t param_handle, const void *value)
 
gn_err_t gn_leaf_param_get_bool (const gn_leaf_handle_t leaf_config, const char *name, bool *val)
 
gn_err_t gn_leaf_param_init_double (const gn_leaf_handle_t leaf_config, const char *name, double val)
 init the parameter with new value and stores in NVS flash, overwriting previous values More...
 
gn_err_t gn_leaf_param_write_double (const gn_leaf_handle_t leaf_config, const char *name, double val)
 updates the parameter with new value More...
 
gn_err_t gn_leaf_param_get_value (const gn_leaf_param_handle_t param, void *val)
 gets the value pointed by the parameter More...
 
gn_err_t gn_leaf_param_get_double (const gn_leaf_handle_t leaf_config, const char *name, double *val)
 
gn_err_t _gn_leaf_parameter_update (const gn_leaf_handle_t leaf_config, const char *param, const void *data, const int data_len)
 
gn_err_t _gn_leaf_param_destroy (gn_leaf_param_handle_t param)
 
gn_err_t gn_leaf_param_add_to_leaf (const gn_leaf_handle_t leaf, const gn_leaf_param_handle_t param)
 add a parameter to the leaf. More...
 
gn_err_t gn_send_node_leaf_param_status (const gn_node_handle_t _node_config)
 send parameter status per each parameter More...
 
gn_err_t gn_send_leaf_param_change_message (const char *leaf_name, const char *param_name, const void *message, size_t message_len)
 send a request to change a parameter name More...
 
gn_err_t gn_leaf_param_set_bool (const gn_leaf_handle_t leaf_config, const char *name, bool val)
 generate a request to update the parameter to the leaf. More...
 
gn_err_t gn_leaf_param_set_double (const gn_leaf_handle_t leaf_config, const char *name, double val)
 generate a request to update the parameter to the leaf. More...
 
gn_err_t gn_leaf_param_set_string (const gn_leaf_handle_t leaf_config, const char *name, char *val)
 generate a request to update the parameter to the leaf. More...
 
gn_leaf_param_handle_t gn_leaf_get_params (gn_leaf_handle_t leaf_config)
 returns the first parameter associated to the leaf More...
 
gn_leaf_param_handle_t gn_leaf_param_get_param_handle (const gn_leaf_handle_t leaf_config, const char *param_name)
 returns the specific parameter associated to the leaf More...
 
void * _gn_leaf_context_add_to_leaf (const gn_leaf_handle_t leaf, char *key, void *value)
 
void * _gn_leaf_context_remove_to_leaf (const gn_leaf_handle_t leaf, char *key)
 
void * _gn_leaf_context_get_key_to_leaf (const gn_leaf_handle_t leaf, char *key)
 
gn_err_t gn_firmware_update ()
 send a message to the display More...
 
gn_err_t gn_reset ()
 reset the flash content and restart the board immediately More...
 
gn_err_t gn_log (char *log_tag, gn_log_level_t level, const char *message,...)
 write ESP log, send log in the event queue and publish in network More...
 
gn_err_t gn_reboot ()
 reboot the board More...
 
gn_config_handle_t gn_init (gn_config_init_param_t *config_init)
 performs the initialization workflow More...
 
gn_err_t gn_storage_set (const char *key, const void *value, size_t required_size)
 stores the key into the NVS flash More...
 
gn_err_t gn_storage_get (const char *key, void **value)
 retrieves the key from the NVS flash More...
 

Variables

esp_event_loop_handle_t gn_event_loop = NULL
 
gn_config_handle_intl_t _gn_default_conf = NULL
 

Macro Definition Documentation

◆ STORAGE_NAMESPACE

#define STORAGE_NAMESPACE   "grownode"

◆ TAG

#define TAG   "grownode"

◆ TAG_EVENT

#define TAG_EVENT   "gn_event"

◆ TAG_NVS

#define TAG_NVS   "gn_nvs"

◆ TIMER_DIVIDER

#define TIMER_DIVIDER   (16)

◆ TIMER_SCALE

#define TIMER_SCALE   (TIMER_BASE_CLK / TIMER_DIVIDER)

Function Documentation

◆ _gn_config_create()

gn_config_handle_intl_t _gn_config_create ( gn_config_init_param_t config_init)

initialize config

Returns
the configuration with its state (GN_CONFIG_STATUS_NOT_INITIALIZED as default)

◆ _gn_evt_handler()

void _gn_evt_handler ( void *  handler_args,
esp_event_base_t  base,
int32_t  id,
void *  event_data 
)

◆ _gn_evt_handlers_register()

esp_err_t _gn_evt_handlers_register ( gn_config_handle_intl_t  conf)

◆ _gn_init_event_loop()

esp_err_t _gn_init_event_loop ( gn_config_handle_intl_t  config)

◆ _gn_init_flash()

gn_err_t _gn_init_flash ( gn_config_handle_t  conf)

◆ _gn_init_keepalive_timer()

esp_err_t _gn_init_keepalive_timer ( gn_config_handle_intl_t  conf)

◆ _gn_init_spiffs()

esp_err_t _gn_init_spiffs ( gn_config_handle_intl_t  conf)

◆ _gn_keepalive_start()

void _gn_keepalive_start ( )

◆ _gn_keepalive_stop()

void _gn_keepalive_stop ( )

◆ _gn_leaf_config_create()

gn_leaf_config_handle_intl_t _gn_leaf_config_create ( )

◆ _gn_leaf_context_add_to_leaf()

void* _gn_leaf_context_add_to_leaf ( const gn_leaf_handle_t  leaf,
char *  key,
void *  value 
)

◆ _gn_leaf_context_get_key_to_leaf()

void* _gn_leaf_context_get_key_to_leaf ( const gn_leaf_handle_t  leaf,
char *  key 
)

◆ _gn_leaf_context_remove_to_leaf()

void* _gn_leaf_context_remove_to_leaf ( const gn_leaf_handle_t  leaf,
char *  key 
)

◆ _gn_leaf_destroy()

gn_err_t _gn_leaf_destroy ( gn_leaf_handle_t  leaf_config)

◆ _gn_leaf_evt_handler()

void _gn_leaf_evt_handler ( void *  handler_args,
esp_event_base_t  base,
int32_t  id,
void *  event_data 
)

send event to leaf, by converting the event to gn_leaf_parameter_event_handle_t struct and pass in leaf event queue. if the event is a leaf parameter event, event_data will be passed in the queue. if the event is different, event_data will be copied and null terminated in the character array data.

◆ _gn_leaf_get_by_name()

gn_leaf_config_handle_intl_t _gn_leaf_get_by_name ( char *  leaf_name)

◆ _gn_leaf_param_destroy()

gn_err_t _gn_leaf_param_destroy ( gn_leaf_param_handle_t  param)

◆ _gn_leaf_parameter_update()

gn_err_t _gn_leaf_parameter_update ( const gn_leaf_handle_t  leaf_config,
const char *  param,
const void *  data,
const int  data_len 
)

update the parameter value from the event supplied. this is called from event handling system. hence, the parameter value can be changed here only if it has WRITE access

Returns
ESP_OK if parameter is changed,

◆ _gn_leaf_start()

gn_err_t _gn_leaf_start ( gn_leaf_config_handle_intl_t  leaf_config)

start the leaf by starting a new task and subscribing to network messages

Parameters
leaf_configthe leaf to start
Returns
status of the operation

◆ _gn_node_config_create()

gn_node_handle_intl_t _gn_node_config_create ( )

◆ _gn_send_event_to_leaf()

gn_err_t _gn_send_event_to_leaf ( gn_leaf_config_handle_intl_t  leaf_config,
gn_leaf_parameter_event_handle_t  evt 
)

send event to leaf using xQueueSend. the data will be null terminated.

Parameters
leaf_configthe leaf from where the event is sent
evtthe event to send
Returns
GN_ERR_EVENT_NOT_SENT if not possible to send event

◆ _gn_timer_callback_isr()

static bool IRAM_ATTR _gn_timer_callback_isr ( void *  args)
static

◆ ESP_EVENT_DEFINE_BASE() [1/2]

ESP_EVENT_DEFINE_BASE ( GN_BASE_EVENT  )

◆ ESP_EVENT_DEFINE_BASE() [2/2]

ESP_EVENT_DEFINE_BASE ( GN_LEAF_EVENT  )

◆ gn_firmware_update()

gn_err_t gn_firmware_update ( )

send a message to the display

implemented by sending an internal GN_DISPLAY_LOG_EVENT event NOTE: data will be truncated depending on display size

Parameters
messagethe message to send (null terminated)
Returns
GN_RET_OK if event is dispatched
GN_RET_ERR if the event dispatch encounters a problem
GN_RET_ERR_INVALID_ARG if message is NULL or zero length

starts the OTA firmware upgrade

it starts the OTA tasks so it returns immediately

Returns
GN_RET_OK

◆ gn_get_event_loop()

esp_event_loop_handle_t gn_get_event_loop ( gn_config_handle_t  config)

retrieves the event loop starting from the config handle

Parameters
configthe config handle
Returns
the event loop
NULL if config not valid

◆ gn_get_status()

gn_node_status_t gn_get_status ( gn_config_handle_t  config)
inline

retrieves the configuration status

Parameters
configthe configuration handle to check
Returns
GN_CONFIG_STATUS_ERROR if config is NULL
the configuration status

◆ gn_get_status_description()

const char* gn_get_status_description ( gn_config_handle_t  config)
inline

retrieves the configuration status description

Parameters
configthe configuration handle to check
Returns
GN_CONFIG_STATUS_ERROR if config is NULL
the configuration status

◆ gn_init()

gn_config_handle_t gn_init ( gn_config_init_param_t config_init)

performs the initialization workflow

  • creates the configuration handle
  • initializes hardware (flash, storage)
  • initializes event loop and handlers
  • initializes display if configured
  • initializes network if configured (starting provisioning is not set)
  • initializes server connection

this is a process that will continue even after the function returns, eg for network/server connection

when everything is OK it sets the status of the config handle to GN_CONFIG_STATUS_ERROR

NOTE: if called several times, it returns always the same handle

Returns
an handle to the config data structure

◆ gn_leaf_create()

gn_leaf_handle_t gn_leaf_create ( gn_node_handle_t  node_config,
const char *  name,
gn_leaf_config_callback  callback,
size_t  task_size 
)

creates the leaf

initializes the leaf structure. the returned handle is not active and need to be started by the gn_node_start() function

See also
gn_node_start()
Parameters
node_configthe configuration handle to create the leaf to
namethe name of the leaf to be created
callbackthe callback to be called to configure the leaf
taskcallback function of the leaf task
task_sizethe size of the task to be memory allocated
Returns
an handle to the leaf config
NULL if the handle cannot be created

◆ gn_leaf_event_subscribe()

gn_err_t gn_leaf_event_subscribe ( gn_leaf_handle_t  leaf_config,
gn_event_id_t  event_id 
)

subscribe the leaf to the event id.

Returns
GN_RET_OK if successful

◆ gn_leaf_event_unsubscribe()

gn_err_t gn_leaf_event_unsubscribe ( gn_leaf_handle_t  leaf_config,
gn_event_id_t  event_id 
)

unsubscribe the leaf to the event id.

Returns
GN_RET_OK if successful

◆ gn_leaf_get_config_handle()

gn_leaf_handle_t gn_leaf_get_config_handle ( gn_node_handle_t  node,
const char *  name 
)

◆ gn_leaf_get_descriptor()

gn_leaf_descriptor_handle_t gn_leaf_get_descriptor ( gn_leaf_handle_t  leaf_config)

returns the descriptor handle for the corresponding leaf

◆ gn_leaf_get_event_loop()

esp_event_loop_handle_t gn_leaf_get_event_loop ( gn_leaf_handle_t  leaf_config)

retrieves the event loop starting from the leaf config handle

Parameters
leaf_configthe leaf config handle
Returns
the event loop
NULL if leaf config not valid

◆ gn_leaf_get_event_queue()

QueueHandle_t gn_leaf_get_event_queue ( gn_leaf_handle_t  leaf_config)

gets the leaf queue handle

Parameters
leaf_configthe leaf to be queried
Returns
the queue handle
NULL if leaf not found

◆ gn_leaf_get_name()

gn_err_t gn_leaf_get_name ( gn_leaf_handle_t  leaf_config,
char *  name 
)

gets the name of the leaf referenced by the handle

Parameters
leaf_configthe handle to be queried
namethe pointer where the name will be set. set lenght to GN_LEAF_NAME_SIZE
Returns
GN_RET_ERR_INVALID_ARG if the handle is not valid
GN_RET_OK if everything OK

◆ gn_leaf_get_node()

gn_node_handle_t gn_leaf_get_node ( gn_leaf_handle_t  leaf_config)

◆ gn_leaf_get_params()

gn_leaf_param_handle_t gn_leaf_get_params ( gn_leaf_handle_t  leaf_config)

returns the first parameter associated to the leaf

Parameters
leaf_configthe leaf handle to search within
Returns
NULL if leaf_config is not found
the first parameter handle

◆ gn_leaf_param_add_to_leaf()

gn_err_t gn_leaf_param_add_to_leaf ( const gn_leaf_handle_t  leaf,
const gn_leaf_param_handle_t  param 
)

add a parameter to the leaf.

the parameter will then listen to server changes

Parameters
leafthe leaf handle
paramthe param to add to the leaf. the leaf will point at it upon method return
Returns
GN_RET_ERR_INVALID_ARG in case of parameter errors
GN_RET_OK upon success

◆ gn_leaf_param_create()

gn_leaf_param_handle_t gn_leaf_param_create ( gn_leaf_handle_t  leaf_config,
const char *  name,
const gn_val_type_t  type,
gn_val_t  val,
gn_leaf_param_access_type_t  access,
gn_leaf_param_storage_t  storage,
gn_validator_callback_t  validator 
)
@brief  creates a parameter on the leaf

NOTE: if parameter is stored, the value is overridden
Parameters
leaf_configthe leaf to be queried
namethe name of the parameter (null terminated char array)
typethe type of parameter
valthe value of parameter
accessaccess type of parameter
storagestorage type of parameter
validatorcallback to validate
Returns
the new parameter handle
NULL in case of errors

◆ gn_leaf_param_get_bool()

gn_err_t gn_leaf_param_get_bool ( const gn_leaf_handle_t  leaf_config,
const char *  name,
bool *  val 
)

◆ gn_leaf_param_get_double()

gn_err_t gn_leaf_param_get_double ( const gn_leaf_handle_t  leaf_config,
const char *  name,
double *  val 
)

◆ gn_leaf_param_get_param_handle()

gn_leaf_param_handle_t gn_leaf_param_get_param_handle ( const gn_leaf_handle_t  leaf_config,
const char *  param_name 
)

returns the specific parameter associated to the leaf

Parameters
leaf_configthe leaf handle to search within
param_namethe name of the parameter (null terminated)
Returns
NULL if leaf_config or the parameter is not found
the found parameter handle

◆ gn_leaf_param_get_string()

gn_err_t gn_leaf_param_get_string ( const gn_leaf_handle_t  leaf_config,
const char *  name,
char *  val,
size_t  max_lenght 
)

gets the parameter value

Parameters
leaf_configthe leaf to get the parameter from
namethe name of the parameter, null terminated
valpointer where the parameter is put
max_lenghtthe maximum lenght of the parameter value to be copied
@return GN_RET_OK if the parameter is set
@return GN_RET_ERR_INVALID_ARG if the parameter is not found

◆ gn_leaf_param_get_value()

gn_err_t gn_leaf_param_get_value ( const gn_leaf_param_handle_t  param,
void *  val 
)

gets the value pointed by the parameter

Parameters
paramthe parameter handle to look at
valthe value returned
@return GN_RET_OK if the parameter is set
@return GN_RET_ERR_INVALID_ARG in case of input errors

◆ gn_leaf_param_init_bool()

gn_err_t gn_leaf_param_init_bool ( const gn_leaf_handle_t  leaf_config,
const char *  name,
bool  val 
)

init the parameter with new value and stores in NVS flash, overwriting previous values

the leaf must be not initialized to have an effect. the parameter value will be copied to the corresponding handle.

Parameters
leaf_configthe leaf handle to be queried
namethe name of the parameter (null terminated)
valthe value to set
Returns
GN_RET_OK if the parameter is set
GN_RET_ERR_INVALID_ARG in case of input errors

◆ gn_leaf_param_init_double()

gn_err_t gn_leaf_param_init_double ( const gn_leaf_handle_t  leaf_config,
const char *  name,
double  val 
)

init the parameter with new value and stores in NVS flash, overwriting previous values

the leaf must be not initialized to have an effect. the parameter value will be copied to the corresponding handle.

Parameters
leaf_configthe leaf handle to be queried
namethe name of the parameter (null terminated)
valthe value to set
Returns
GN_RET_OK if the parameter is set
GN_RET_ERR_INVALID_ARG in case of input errors

◆ gn_leaf_param_init_string()

gn_err_t gn_leaf_param_init_string ( const gn_leaf_handle_t  leaf_config,
const char *  name,
const char *  val 
)

init the parameter with new value and stores in NVS flash, overwriting previous values

the leaf must be not initialized to have an effect. the parameter value will be copied to the corresponding handle.

Parameters
leaf_configthe leaf handle to be queried
namethe name of the parameter (null terminated)
valthe value to set
Returns
GN_RET_OK if the parameter is set
GN_RET_ERR_INVALID_ARG in case of input errors

◆ gn_leaf_param_set_bool()

gn_err_t gn_leaf_param_set_bool ( const gn_leaf_handle_t  leaf_config,
const char *  name,
bool  val 
)

generate a request to update the parameter to the leaf.

It inform the leaf that a parameter should be changed. Think of it as it would be requested by the network. It is the basis of inter-leaves messaging.

Parameters
leaf_configthe leaf to ask
namethe parameter name to change
valthe value to change
@return GN_RET_ERR_LEAF_NOT_FOUND if the leaf is not found
@return GN_RET_ERR_INVALID_ARG in case of input parameter error
@return GN_RET_ERR_LEAF_PARAM_ACCESS_VIOLATION in case the parameter access is not write enable

◆ gn_leaf_param_set_double()

gn_err_t gn_leaf_param_set_double ( const gn_leaf_handle_t  leaf_config,
const char *  name,
double  val 
)

generate a request to update the parameter to the leaf.

It inform the leaf that a parameter should be changed. Think of it as it would be requested by the network. It is the basis of inter-leaves messaging.

Parameters
leaf_configthe leaf to ask
namethe parameter name to change
valthe value to change
@return GN_RET_ERR_LEAF_NOT_FOUND if the leaf is not found
@return GN_RET_ERR_INVALID_ARG in case of input parameter error
@return GN_RET_ERR_LEAF_PARAM_ACCESS_VIOLATION in case the parameter access is not write enable

◆ gn_leaf_param_set_string()

gn_err_t gn_leaf_param_set_string ( const gn_leaf_handle_t  leaf_config,
const char *  name,
char *  val 
)

generate a request to update the parameter to the leaf.

It inform the leaf that a parameter should be changed. Think of it as it would be requested by the network. It is the basis of inter-leaves messaging.

Parameters
leaf_configthe leaf to ask
namethe parameter name to change
valthe value to change
@return GN_RET_ERR_LEAF_NOT_FOUND if the leaf is not found
@return GN_RET_ERR_INVALID_ARG in case of input parameter error
@return GN_RET_ERR_LEAF_PARAM_ACCESS_VIOLATION in case the parameter access is not write enable

◆ gn_leaf_param_write()

gn_err_t gn_leaf_param_write ( const gn_leaf_param_handle_t  param_handle,
const void *  value 
)
@brief  updates the parameter with new value

this is calling the gn_leaf_parameter_write_XXX depending on the param handle type, so be careful in order to avoid memory leaks

@param leaf_config  the leaf handle to be queried
@param value        the pointer to value to set ( in case of string, null terminated)

@return GN_RET_OK if the parameter is set
@return GN_RET_ERR_INVALID_ARG in case of input errors

◆ gn_leaf_param_write_bool()

gn_err_t gn_leaf_param_write_bool ( const gn_leaf_handle_t  leaf_config,
const char *  name,
bool  val 
)

updates the parameter with new value

the parameter value will be copied to the corresponding handle. after the change the parameter change will be propagated to the event system through a GN_LEAF_PARAM_CHANGED_EVENT and to the server.

Parameters
leaf_configthe leaf handle to be queried
namethe name of the parameter (null terminated)
valthe value to set (null terminated)
Returns
GN_RET_OK if the parameter is set
GN_RET_ERR_INVALID_ARG in case of input errors

◆ gn_leaf_param_write_double()

gn_err_t gn_leaf_param_write_double ( const gn_leaf_handle_t  leaf_config,
const char *  name,
double  val 
)

updates the parameter with new value

the leaf must be already initialized to have an effect. the parameter value will be copied to the corresponding handle. after the change the parameter change will be propagated to the event system through a GN_LEAF_PARAM_CHANGED_EVENT and to the server.

Parameters
leaf_configthe leaf handle to be queried
namethe name of the parameter (null terminated)
valthe value to set
Returns
GN_RET_OK if the parameter is set
GN_RET_ERR_INVALID_ARG in case of input errors

◆ gn_leaf_param_write_string()

gn_err_t gn_leaf_param_write_string ( const gn_leaf_handle_t  leaf_config,
const char *  name,
char *  val 
)

updates the parameter with new value

the parameter value will be copied to the corresponding handle. after the change the parameter change will be propagated to the event system through a GN_LEAF_PARAM_CHANGED_EVENT and to the server.

Parameters
leaf_configthe leaf handle to be queried
namethe name of the parameter (null terminated)
valthe value to set (null terminated)
Returns
GN_RET_OK if the parameter is set
GN_RET_ERR_INVALID_ARG in case of input errors
GN_RET_ERR in case of messaging error

◆ gn_log()

gn_err_t gn_log ( char *  log_tag,
gn_log_level_t  level,
const char *  message,
  ... 
)

write ESP log, send log in the event queue and publish in network

Parameters
log_taglog level, will be the TAG in ESP logging framework
levelgrownode log level
messagethe null terminated message to log
@return GN_RET_OK if event is dispatched
@return GN_RET_ERR if the event dispatch encounters a problem
@return GN_RET_ERR_INVALID_ARG if message is NULL or zero length

◆ gn_node_create()

gn_node_handle_t gn_node_create ( gn_config_handle_t  config,
const char *  name 
)

create a new node with specified configuration and name

Parameters
configthe config handle to use
namename of the node. MUST BE null terminated
Returns
the node handle created.

◆ gn_node_destroy()

gn_err_t gn_node_destroy ( gn_node_handle_t  node)

removes the node from the config

Parameters
nodethe node to be removed
Returns
GN_RET_OK if operation had succeded

◆ gn_node_get_event_loop()

esp_event_loop_handle_t gn_node_get_event_loop ( gn_node_handle_t  node)

retrieves the event loop from the node

Parameters
nodethe node handle
Returns
the event loop
NULL if leaf config not valid

◆ gn_node_get_name()

gn_err_t gn_node_get_name ( gn_node_handle_t  node_config,
char *  name 
)

gets the name of the node referenced by the handle

Parameters
node_configthe handle to be queried
namethe pointer where the name will be set. set lenght to GN_LEAF_NAME_SIZE
Returns
GN_RET_ERR_INVALID_ARG if the handle is not valid
GN_RET_OK if everything OK

◆ gn_node_get_size()

size_t gn_node_get_size ( gn_node_handle_t  node_config)

number of leaves into the node

Parameters
node_configthe node to be inspected
Returns
number of leaves into the node, -1 in case node_config is NULL

◆ gn_node_start()

gn_err_t gn_node_start ( gn_node_handle_t  node)

starts the node by starting the leaves tasks

At the end of the process, it sets the node status to GN_CONFIG_STATUS_STARTED and sends a GN_NODE_STARTED_EVENT event

Parameters
nodethe node to be started
Returns
GN_RET_OK if operation had succeded, GN_RET_ERR_NODE_NOT_STARTED in case of issues

◆ gn_reboot()

gn_err_t gn_reboot ( )

reboot the board

Returns
GN_RET_OK

◆ gn_reset()

gn_err_t gn_reset ( )

reset the flash content and restart the board immediately

Returns
GN_RET_OK

◆ gn_send_leaf_param_change_message()

gn_err_t gn_send_leaf_param_change_message ( const char *  leaf_name,
const char *  param_name,
const void *  message,
size_t  message_len 
)

send a request to change a parameter name

It sends a GN_LEAF_PARAM_CHANGE_REQUEST_EVENT to the leaf parameter, if the parameter is modifiable

Parameters
leaf_namethe leaf name (null terminated) to send the request to
param_namethe parameter name to change (null terminated)
messagea pointer to the payload
message_lensize of the payload
Returns
GN_RET_ERR_LEAF_NOT_FOUND if the leaf is not found
GN_RET_ERR_INVALID_ARG in case of input parameter error
GN_RET_ERR_LEAF_PARAM_ACCESS_VIOLATION in case the parameter access is not write enable

◆ gn_send_node_leaf_param_status()

gn_err_t gn_send_node_leaf_param_status ( const gn_node_handle_t  _node_config)

send parameter status per each parameter

Parameters
_node_configthe config
Returns
GN_RET_OK upon success

◆ gn_storage_get()

gn_err_t gn_storage_get ( const char *  key,
void **  value 
)

retrieves the key from the NVS flash

internally, this is implemented by retrieving raw bytes to the flash storage

Parameters
keyname (null terminated)
valuepointer where the pointer of the data acquired will be stored
Returns
GN_RET_ERR_INVALID_ARG if input params are not valid
GN_RET_OK if key is stored successfully

◆ gn_storage_set()

gn_err_t gn_storage_set ( const char *  key,
const void *  value,
size_t  required_size 
)

stores the key into the NVS flash

internally, this is implemented by copying raw bytes to the flash storage

Parameters
keyname (null terminated)
valuepointer to data
required_sizebytes to write
Returns
GN_RET_ERR_INVALID_ARG if input params are not valid
GN_RET_OK if key is stored successfully

Variable Documentation

◆ _gn_default_conf

gn_config_handle_intl_t _gn_default_conf = NULL

◆ gn_event_loop

esp_event_loop_handle_t gn_event_loop = NULL