NetBurner 3.5.6
PDF Version
mqtt.h File Reference

NetBurner MQTT Library. More...

#include <predef.h>
#include <constants.h>
#include <config_obj.h>
#include <config_fs_bulkstore.h>
#include <nettimer.h>
#include <mqtt/msg_types.h>
#include <mqtt/mqtt_msg_reqs.h>
#include <webclient/http_funcs.h>
#include <json_lexer.h>
#include <pins.h>
#include <crypto/NetBurner/NbSslCtx.h>
#include <mqtt/mqtt_internal.h>
#include <mqtt/config_mqtt_obj.h>

Go to the source code of this file.

Classes

struct  MQTT::TopicHandler
 TopicHandler context definition. More...
 
class  MQTT::Client
 Advanced low-level MQTT Client for interacting with Mqtt Brokers. The client handles all network communications with the Broker and handles local message queueing and dispatching to topic handlers. More...
 
class  MQTT::ConfiguredClient
 Easy MQTT Client wrapper for interacting with MQTT brokers. The client handles all network communications with the Broker and handles local message queueing and dispatching to topic handlers. Adds ConfigObj for automatically configuring all Client settings via the Config System. More...
 
class  MQTT::mqtt_leaf
 Base class for all Mqtt Objects (MqttObj). Mqtt Objects provide a seamless bridge/synchronization to communicate information through an MQTT Broker via a Client object. More...
 
class  MQTT::mqtt_obj
 Base class for easy MQTT Objects (MqttObj). mqtt_obj are comprised of higher order parent objects that contain registered child objects. More...
 
class  MQTT::mqtt_int
 Easy MqttObj class for automatically publishing and subscribing unsigned integer values to/from an MQTT topic. Use like a normal int32_t. More...
 
class  MQTT::mqtt_uint
 Easy MqttObj class for automatically publishing and subscribing unsigned integer values to/from an MQTT topic. Use like a normal uint32_t. More...
 
class  MQTT::mqtt_float
 Easy MqttObj class for automatically publishing and subscribing floating point values to/from an MQTT topic. Use like a normal double. More...
 
class  MQTT::mqtt_string
 Easy MqttObj class for automatically publishing and subscribing string values to/from an MQTT topic. Use like a normal NBString. More...
 
class  MQTT::mqtt_bool
 Easy MqttObj class for automatically publishing and subscribing boolean values to/from an MQTT topic. Use like a normal bool. More...
 
class  MQTT::mqtt_IO
 Easy MqttObj class for automatically publishing and subscribing hardware GPIO pins to/from an MQTT topic. Use like a normal PinIO. More...
 
class  MQTT::mqtt_IO_Input
 MqttObj connecting hardware GPIO pins to an Mqtt Broker. This class defaults the pin to an Input state. More...
 
class  MQTT::mqtt_IO_Output
 MqttObj connecting hardware GPIO pins to an Mqtt Broker. This class defaults the pin to an Output state. More...
 
class  MQTT::ConfigExposer
 Easy MqttObj class for automatically publishing and subscribing NetBurner Config system objects to/from an MQTT topic. Use like a normal ConfigObj. More...
 
class  MQTT::SubHandler
 Easy class for registering a callback function that receives messages on an MQTT topic and handles them appropriately. Behaves similarly to HttpResponseHandler. More...
 

Namespaces

namespace  MQTT
 MQTT Namespace.
 

Macros

#define MQTT_WAIT   (TICKS_PER_SECOND*10)
 
 
#define MQTT_TLS_NEGOTIATE_TIMEOUT   (TICKS_PER_SECOND*50)
 
 
#define MQTT_OBJ_PRIORITY_COUNT   (16)
 
 
#define MQTT_OBJ_PRIORITY_MAX   0
 
 
#define MQTT_OBJ_PRIORITY_MIN   15
 
 
#define MQTT_MAX_PKT_SIZE   (0x2FFFFFFF)
 
 
#define MQTT_MAX_MAX_SUPPORTED_IN_FLIGHT   (256)
 
 
#define MQTT_MAX_SUPPORTED_IN_FLIGHT   (16)
 
 
#define MQTT_MAX_HANDLERS_PER_CONNECTION   (256)
 
 
#define MQTT_MAX_SUPPORTED_RX_TOPIC_ALIASES   (128)
 
 
#define MQTT_DEFAULT_SESSION_EXPIRY_INTERVAL   (3600)
 
 
#define MQTT_DEFAULT_KEEP_ALIVE   (30)
 
 
#define MQTT_MAX_SUB_IDs   (128)
 
 

Typedefs

typedef int(* MQTT::MsgCallback_t) (MQTT::Client *mConn, int mqttFd, MQTT::PacketInfo::Msg *msg, void *ctx)
 Function signature for a user-implemented callback function to receive messages from a subscription.
 

Enumerations

enum  MQTT::eResult_t {
  MQTT::eResult_Success = 0 , MQTT::eResult_Mqtt_Unspecified = -Pkt::eReason_Error_Unspecified , MQTT::eResult_Mqtt_MalformedPkt = -Pkt::eReason_Error_MalformedPkt , MQTT::eResult_Mqtt_Protocol = -Pkt::eReason_Error_Protocol ,
  MQTT::eResult_Mqtt_Implementation = -Pkt::eReason_Error_Implementation , MQTT::eResult_Mqtt_UnsupportedProtoVer = -Pkt::eReason_Error_UnsupportedProtoVer , MQTT::eResult_Mqtt_ClientIdInvalid = -Pkt::eReason_Error_ClientIdInvalid , MQTT::eResult_Mqtt_UserPassword = -Pkt::eReason_Error_UserPassword ,
  MQTT::eResult_Mqtt_NotAuthorized = -Pkt::eReason_Error_NotAuthorized , MQTT::eResult_Mqtt_ServerUnavail = -Pkt::eReason_Error_ServerUnavail , MQTT::eResult_Mqtt_ServerBusy = -Pkt::eReason_Error_ServerBusy , MQTT::eResult_Mqtt_Banned = -Pkt::eReason_Error_Banned ,
  MQTT::eResult_Mqtt_ServerShutdown = -Pkt::eReason_Error_ServerShutdown , MQTT::eResult_Mqtt_BadAuthMethod = -Pkt::eReason_Error_BadAuthMethod , MQTT::eResult_Mqtt_KATimeout = -Pkt::eReason_Error_KATimeout , MQTT::eResult_Mqtt_SessTakeover = -Pkt::eReason_Error_SessTakeover ,
  MQTT::eResult_Mqtt_FilterInvalid = -Pkt::eReason_Error_FilterInvalid , MQTT::eResult_Mqtt_NameInvalid = -Pkt::eReason_Error_NameInvalid , MQTT::eResult_Mqtt_PktId_InUse = -Pkt::eReason_Error_PktId_InUse , MQTT::eResult_Mqtt_PktId_NotFound = -Pkt::eReason_Error_PktId_NotFound ,
  MQTT::eResult_Mqtt_RcvMax_Exceeded = -Pkt::eReason_Error_RcvMax_Exceeded , MQTT::eResult_Mqtt_TopicAlias_Invalid = -Pkt::eReason_Error_TopicAlias_Invalid , MQTT::eResult_Mqtt_TooLarge = -Pkt::eReason_Error_TooLarge , MQTT::eResult_Mqtt_MsgRate = -Pkt::eReason_Error_MsgRate ,
  MQTT::eResult_Mqtt_Quota = -Pkt::eReason_Error_Quota , MQTT::eResult_Mqtt_Admin = -Pkt::eReason_Error_Admin , MQTT::eResult_Mqtt_PayFmt_Invalid = -Pkt::eReason_Error_PayFmt_Invalid , MQTT::eResult_Mqtt_NotSupported_Retain = -Pkt::eReason_Error_NotSupported_Retain ,
  MQTT::eResult_Mqtt_NotSupported_QoS = -Pkt::eReason_Error_NotSupported_QoS , MQTT::eResult_Mqtt_UseOther = -Pkt::eReason_Error_UseOther , MQTT::eResult_Mqtt_ServerMoved = -Pkt::eReason_Error_ServerMoved , MQTT::eResult_Mqtt_NotSupported_SharedSubs = -Pkt::eReason_Error_NotSupported_SharedSubs ,
  MQTT::eResult_Mqtt_ConnRate = -Pkt::eReason_Error_ConnRate , MQTT::eResult_Mqtt_MaxConnTime = -Pkt::eReason_Error_MaxConnTime , MQTT::eResult_Mqtt_NotSupported_SubIds = -Pkt::eReason_Error_NotSupported_SubIds , MQTT::eResult_Mqtt_NotSupported_WildSubs = -Pkt::eReason_Error_NotSupported_WildSubs ,
  MQTT::eResult_Mqtt_Transport_Error = -Pkt::eReason_Error_Transport_Error , MQTT::eResult_Error_NetErr = -Pkt::eReason_Error_Transport_Error , MQTT::eResult_Socket_TryAgain = -256 , MQTT::eResult_Socket_NeedDNS = -257 ,
  MQTT::eResult_Cont_Auth = -258 , MQTT::eResult_Error_InvalidURI = -259 , MQTT::eResult_Error_NoneAvail = -260 , MQTT::eResult_Error_Malformed = -261 ,
  MQTT::eResult_Error_Timeout = -262 , MQTT::eResult_Error_BadProp = -263 , MQTT::eResult_Error_NoSuchConn = -264 , MQTT::eResult_Error_BadArg = -265
}
 MQTT library return codes. More...
 
enum  {
  MQTT::eObj_Flag_PubOnWrite = 0x0001 , MQTT::eObj_Flag_PubQoS_AtLeastOnce = 0x0002 , MQTT::eObj_Flag_PubQoS_ExactlyOnce = 0x0004 , MQTT::eObj_Flag_PubRetain = 0x0008 ,
  MQTT::eObj_Flag_Subscribe = 0x0010 , MQTT::eObj_Flag_Sub_HandlerOnly = 0x0020 , MQTT::eObj_Flag_Sub_IncludeLocal = 0x0040 , MQTT::eObj_Flag_Sub_QoS_AtLeastOnce = 0x0080 ,
  MQTT::eObj_Flag_Sub_QoS_ExactlyOnce = 0x0100 , MQTT::eObj_Flag_Sub_NoLocal = 0x0200 , MQTT::eObj_Flag_Sub_Retained_IfNew = 0x0400 , MQTT::eObj_Flag_Sub_Retained_Never = 0x0800 ,
  MQTT::eObj_Flag_WaitForPub = 0x1000 , MQTT::eObj_Flag_DynTopicName = 0x2000
}
 MqttObj Control Flags. More...
 
enum  MQTT::eObj_Serialize_t {
  MQTT::eObj_Serialize_Disabled = 0x00 , MQTT::eObj_Serialize_String = 0x01 , MQTT::eObj_Serialize_JSON = 0x02 , MQTT::eObj_Serialize_JSON_ValOnly = 0x04 ,
  MQTT::eObj_Serialize_MqttString = 0x08 , MQTT::eObj_Serialize_BigEndian = 0x10 , MQTT::eObj_Serialize_LittleEndian = 0x20 , MQTT::eObj_Serialize_NativeEndian = 0x40 ,
  MQTT::eObj_Serialize_CURRENT_FORM = 0x80
}
 MqttObj Serialization Formats. More...
 

Functions

void UserMain (void *pd)
 Main function.
 
const char * MQTT::GetPacketTypeString (Pkt::eType_t pkt)
 Get the name of a specific eType_t protocol packet type.
 
const char * MQTT::GetReturnCodeString (MQTT::eResult_t result)
 Get the name of a specific API eResult_t return code.
 
const char * MQTT::GetConnectionStatusString (int status)
 Get the name of a specific GetConnectionStatus return code.
 

Detailed Description

NetBurner MQTT Library.

Function Documentation

◆ UserMain()

void UserMain ( void * pd)

Main function.

UserMain

Main entry point for the example

UserMain

Main entry point of the example

UserMain

Main entry point to the example

UserMain

The main task

UserMain, the entry point of the example


UserMain

UserMain

Main entry point of program

UserMain

Main entry point for example

Main function.

UserMain Task

UserMain Task This is the first task to be executed and will create the UDP Reader Task.

UserMain This is the first task to be executed and will create the UDP Reader Task.

UserMain

Main entry point for the program

Set up a file descriptor (FD) set so we can select() on the serial ports. Once configured, the select() function will block until activity is detected on a FD (a serial port in this example), or a timeout occurs (set to 1 second here). If a timeout does occur, we simply go back to the select() function and wait for more activity. The "write" and "error" FD sets of the select() function are not used and set to nullptr; only read operations caused by the items in read_fds will cause select() to exit. A timeout value of 0 would disable the timeout, and select() would wait forever.

Detailed description of how select() works: The select() function operates on a bit mapped field of 64 bits. In this example, the bit field is read_fds. When select() is called, read_fds represents a MASK of which file descriptors to check. AFTER select() exits, read_fds contains the STATUS of which file descriptors have pending events. This means that read_fds must be reinitialized to contain MASK information each time before select() is called. FD_ZERO, FD_SET, and FD_ISSET are macros that execute very fast.