GrowNode
gn_mqtt_protocol.h File Reference

Macros

#define _GN_MQTT_MAX_TOPIC_LENGTH   80
 
#define _GN_MQTT_MAX_PAYLOAD_LENGTH   CONFIG_GROWNODE_MQTT_BUFFER_SIZE
 
#define _GN_MQTT_COMMAND_MESS   "cmd"
 
#define _GN_MQTT_STATUS_MESS   "sts"
 
#define _GN_MQTT_LOG_MESS   "log"
 
#define _GN_MQTT_PAYLOAD_RST   "RST"
 
#define _GN_MQTT_PAYLOAD_OTA   "OTA"
 
#define _GN_MQTT_PAYLOAD_RBT   "RBT"
 
#define _GN_MQTT_DEFAULT_QOS   0
 

Functions

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...
 
esp_err_t gn_mqtt_subscribe_leaf_param (gn_leaf_param_handle_t param)
 
gn_err_t gn_mqtt_init (gn_config_handle_t config)
 inits the MQTT subsystem More...
 
gn_err_t gn_mqtt_send_node_config (gn_node_handle_t conf)
 send node parameters via JSON message to the server More...
 
gn_err_t gn_mqtt_send_leaf_message (gn_leaf_handle_t leaf, const char *msg)
 
gn_err_t gn_mqtt_send_leaf_param (gn_leaf_param_handle_t config)
 
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_log_message (gn_config_handle_t _config, char *log_tag, gn_log_level_t level, char *message)
 sends log message via MQTT More...
 

Macro Definition Documentation

◆ _GN_MQTT_COMMAND_MESS

#define _GN_MQTT_COMMAND_MESS   "cmd"

◆ _GN_MQTT_DEFAULT_QOS

#define _GN_MQTT_DEFAULT_QOS   0

◆ _GN_MQTT_LOG_MESS

#define _GN_MQTT_LOG_MESS   "log"

◆ _GN_MQTT_MAX_PAYLOAD_LENGTH

#define _GN_MQTT_MAX_PAYLOAD_LENGTH   CONFIG_GROWNODE_MQTT_BUFFER_SIZE

◆ _GN_MQTT_MAX_TOPIC_LENGTH

#define _GN_MQTT_MAX_TOPIC_LENGTH   80

◆ _GN_MQTT_PAYLOAD_OTA

#define _GN_MQTT_PAYLOAD_OTA   "OTA"

◆ _GN_MQTT_PAYLOAD_RBT

#define _GN_MQTT_PAYLOAD_RBT   "RBT"

◆ _GN_MQTT_PAYLOAD_RST

#define _GN_MQTT_PAYLOAD_RST   "RST"

◆ _GN_MQTT_STATUS_MESS

#define _GN_MQTT_STATUS_MESS   "sts"

Function Documentation

◆ 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  config)

◆ 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()

esp_err_t gn_mqtt_subscribe_leaf_param ( gn_leaf_param_handle_t  param)