GrowNode
gn_mqtt_protocol.c File Reference

Data Structures

struct  gn_mqtt_startup_message_t
 
struct  gn_mqtt_node_config_message_t
 

Macros

#define TAG   "gn_mqtt_protocol"
 

Typedefs

typedef gn_mqtt_startup_message_tgn_mqtt_startup_message_handle_t
 
typedef gn_mqtt_node_config_message_tgn_mqtt_node_config_message_handle_t
 

Functions

char * _gn_mqtt_build_node_name (gn_config_handle_intl_t config)
 
void _gn_mqtt_build_leaf_command_topic (gn_leaf_handle_t _leaf_config, char *buf)
 
void _gn_mqtt_build_leaf_parameter_command_topic (const gn_leaf_handle_t _leaf_config, const char *param_name, char *buf)
 
void _gn_mqtt_build_leaf_parameter_status_topic (gn_leaf_handle_t _leaf_config, char *param_name, char *buf)
 
void _gn_mqtt_build_leaf_status_topic (gn_leaf_handle_t _leaf_config, char *buf)
 
void _gn_mqtt_build_status_topic (gn_config_handle_intl_t config, char *buf)
 
void _gn_mqtt_build_log_topic (gn_config_handle_intl_t config, char *buf)
 
void _gn_mqtt_build_command_topic (gn_config_handle_intl_t config, char *buf)
 
gn_err_t gn_mqtt_publish_leaf (gn_leaf_handle_t _leaf_config)
 subscribe leaf to the MQTT server in order to receive messages More...
 
gn_err_t gn_mqtt_subscribe_leaf_param (gn_leaf_param_handle_t _param)
 
gn_err_t gn_mqtt_send_node_config (gn_node_handle_t _node_config)
 send node parameters via JSON message to the server More...
 
gn_err_t gn_mqtt_send_leaf_param (gn_leaf_param_handle_t _param)
 
gn_err_t gn_mqtt_send_log_message (gn_config_handle_t _config, char *log_tag, gn_log_level_t level, char *message)
 sends log message via MQTT More...
 
gn_err_t gn_mqtt_send_startup_message (gn_config_handle_t _config)
 
gn_err_t gn_mqtt_send_reboot_message (gn_config_handle_t _config)
 
gn_err_t gn_mqtt_send_reset_message (gn_config_handle_t _config)
 
gn_err_t gn_mqtt_send_ota_message (gn_config_handle_t _config)
 
gn_err_t gn_mqtt_send_leaf_message (gn_leaf_handle_t _leaf, const char *msg)
 
esp_err_t _gn_mqtt_on_connected (gn_config_handle_t config)
 
esp_err_t _gn_mqtt_on_disconnected (gn_config_handle_t config)
 
void log_error_if_nonzero (const char *message, int error_code)
 
void _gn_mqtt_event_handler (void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
 
gn_err_t gn_mqtt_init (gn_config_handle_t config)
 inits the MQTT subsystem More...
 

Variables

EventGroupHandle_t _gn_event_group_mqtt
 
const int _GN_MQTT_CONNECTED_OK_EVENT_BIT = BIT0
 
const int _GN_MQTT_CONNECTED_KO_EVENT_BIT = BIT1
 
char _gn_cmd_topic [_GN_MQTT_MAX_TOPIC_LENGTH]
 
char _gn_sts_topic [_GN_MQTT_MAX_TOPIC_LENGTH]
 
char _gn_log_topic [_GN_MQTT_MAX_TOPIC_LENGTH]
 
char __nodename [13] = ""
 

Macro Definition Documentation

◆ TAG

#define TAG   "gn_mqtt_protocol"

Typedef Documentation

◆ gn_mqtt_node_config_message_handle_t

◆ gn_mqtt_startup_message_handle_t

Function Documentation

◆ _gn_mqtt_build_command_topic()

void _gn_mqtt_build_command_topic ( gn_config_handle_intl_t  config,
char *  buf 
)

◆ _gn_mqtt_build_leaf_command_topic()

void _gn_mqtt_build_leaf_command_topic ( gn_leaf_handle_t  _leaf_config,
char *  buf 
)

◆ _gn_mqtt_build_leaf_parameter_command_topic()

void _gn_mqtt_build_leaf_parameter_command_topic ( const gn_leaf_handle_t  _leaf_config,
const char *  param_name,
char *  buf 
)

◆ _gn_mqtt_build_leaf_parameter_status_topic()

void _gn_mqtt_build_leaf_parameter_status_topic ( gn_leaf_handle_t  _leaf_config,
char *  param_name,
char *  buf 
)

◆ _gn_mqtt_build_leaf_status_topic()

void _gn_mqtt_build_leaf_status_topic ( gn_leaf_handle_t  _leaf_config,
char *  buf 
)

◆ _gn_mqtt_build_log_topic()

void _gn_mqtt_build_log_topic ( gn_config_handle_intl_t  config,
char *  buf 
)

◆ _gn_mqtt_build_node_name()

char* _gn_mqtt_build_node_name ( gn_config_handle_intl_t  config)
inline

◆ _gn_mqtt_build_status_topic()

void _gn_mqtt_build_status_topic ( gn_config_handle_intl_t  config,
char *  buf 
)

◆ _gn_mqtt_event_handler()

void _gn_mqtt_event_handler ( void *  handler_args,
esp_event_base_t  base,
int32_t  event_id,
void *  event_data 
)

◆ _gn_mqtt_on_connected()

esp_err_t _gn_mqtt_on_connected ( gn_config_handle_t  config)

◆ _gn_mqtt_on_disconnected()

esp_err_t _gn_mqtt_on_disconnected ( gn_config_handle_t  config)

◆ gn_mqtt_init()

gn_err_t gn_mqtt_init ( gn_config_handle_t  config)

inits the MQTT subsystem

Parameters
configthe configuration to use
Returns
GN_RET_ERR_INVALID_ARG in case of null _conf
GN_RET_ERR_MQTT_ERROR in case of MQTT errors
GN_RET_ERR in case of general errors

◆ gn_mqtt_publish_leaf()

gn_err_t gn_mqtt_publish_leaf ( gn_leaf_handle_t  _leaf_config)

subscribe leaf to the MQTT server in order to receive messages

Parameters
leaf_configthe leaf to start
Returns
status of the operation

◆ gn_mqtt_send_leaf_message()

gn_err_t gn_mqtt_send_leaf_message ( gn_leaf_handle_t  _leaf,
const char *  msg 
)

@sends a command message to the specific leaf

Parameters
_leafthe recipient leaf
msgpayload
Returns
GN_RET_OK if successful
GN_RET_ERR_INVALID_ARG if _config is null
GN_RET_ERR_MQTT_ERROR if not possible to send message

◆ gn_mqtt_send_leaf_param()

gn_err_t gn_mqtt_send_leaf_param ( gn_leaf_param_handle_t  _param)

◆ gn_mqtt_send_log_message()

gn_err_t gn_mqtt_send_log_message ( gn_config_handle_t  _config,
char *  log_tag,
gn_log_level_t  level,
char *  message 
)

sends log message via MQTT

this uses the log level of the tag in understanding if the message has to be sent, in a similar way to ESP_LOGX

Parameters
_configthe configuration to use
log_tagthe tag to be checked against
levelthe log level to be checked
messagethe payload
Returns
GN_RET_OK in case of successful sent
GN_RET_ERR general error
GN_RET_MQTT_ERROR on server error
GN_RET_ERR_INVALID_ARG in case of arguments null

◆ gn_mqtt_send_node_config()

gn_err_t gn_mqtt_send_node_config ( gn_node_handle_t  _node_config)

send node parameters via JSON message to the server

this sends only if the node has already been started (status = GN_CONFIG_STATUS_STARTED)

Parameters
_node_configthe node to publish
Returns
GN_RET_ERR_INVALID_ARG if node config is null

◆ gn_mqtt_send_ota_message()

gn_err_t gn_mqtt_send_ota_message ( gn_config_handle_t  _config)

@sends a JSON message saying the board is going to download the firmware

payload is {"msgtype":"OTA"}

Parameters
_configthe configuration to use
Returns
GN_RET_OK if successful
GN_RET_ERR_INVALID_ARG if _config is null
GN_RET_ERR_MQTT_ERROR if not possible to send message

◆ gn_mqtt_send_reboot_message()

gn_err_t gn_mqtt_send_reboot_message ( gn_config_handle_t  _config)

@sends a JSON message saying the board is rebooted

payload is {"msgtype":"RBT"}

Parameters
_configthe configuration to use
Returns
GN_RET_OK if successful
GN_RET_ERR_INVALID_ARG if _config is null
GN_RET_ERR_MQTT_ERROR if not possible to send message

◆ gn_mqtt_send_reset_message()

gn_err_t gn_mqtt_send_reset_message ( gn_config_handle_t  _config)

@sends a JSON message saying the board is going to reset

payload is {"msgtype":"RST"}

Parameters
_configthe configuration to use
Returns
GN_RET_OK if successful
GN_RET_ERR_INVALID_ARG if _config is null
GN_RET_ERR_MQTT_ERROR if not possible to send message

◆ gn_mqtt_send_startup_message()

gn_err_t gn_mqtt_send_startup_message ( gn_config_handle_t  _config)

@sends a JSON message saying the board is online

payload is {"msgtype":"online"}

Parameters
_configthe configuration to use
Returns
GN_RET_OK if successful
GN_RET_ERR_INVALID_ARG if _config is null
GN_RET_ERR_MQTT_ERROR if not possible to send message

◆ gn_mqtt_subscribe_leaf_param()

gn_err_t gn_mqtt_subscribe_leaf_param ( gn_leaf_param_handle_t  _param)

◆ log_error_if_nonzero()

void log_error_if_nonzero ( const char *  message,
int  error_code 
)

Variable Documentation

◆ __nodename

char __nodename[13] = ""

◆ _gn_cmd_topic

char _gn_cmd_topic[_GN_MQTT_MAX_TOPIC_LENGTH]

◆ _gn_event_group_mqtt

EventGroupHandle_t _gn_event_group_mqtt

◆ _gn_log_topic

char _gn_log_topic[_GN_MQTT_MAX_TOPIC_LENGTH]

◆ _GN_MQTT_CONNECTED_KO_EVENT_BIT

const int _GN_MQTT_CONNECTED_KO_EVENT_BIT = BIT1

◆ _GN_MQTT_CONNECTED_OK_EVENT_BIT

const int _GN_MQTT_CONNECTED_OK_EVENT_BIT = BIT0

◆ _gn_sts_topic

char _gn_sts_topic[_GN_MQTT_MAX_TOPIC_LENGTH]