Skip to content

mqtt::MqttConnector

Mqtt Connector class.

Public Functions

Name
def init(self self)
Initialise the module.
def connect_mqtt(self self)
Connect to the MQTT server.
def on_connect(self self, client client, userdata userdata, flags flags, response_code response_code)
Callback on client connect.
def on_message(self self, client client, userdata userdata, message message)
Callback on message received.
def send_message(self self, topic topic, payload payload)
Helper function to send a message.
def prep_payload(self self, data data)
Helper function to prepare the wrapper for the message.

Public Attributes

Name
broker
port
string client_id
username
password
client
bool connected
connected

Public Functions Documentation

function init

def init(
    self self
)

Initialise the module.

function connect_mqtt

def connect_mqtt(
    self self
)

Connect to the MQTT server.

function on_connect

def on_connect(
    self self,
    client client,
    userdata userdata,
    flags flags,
    response_code response_code
)

Callback on client connect.

Parameters:

  • client The client object
  • userdata Data on the user
  • flags Flags!
  • response_code Response code from the server

Return: None

function on_message

def on_message(
    self self,
    client client,
    userdata userdata,
    message message
)

Callback on message received.

Parameters:

  • client The client object
  • userdata Data on the user
  • message Object representing the message that has been received

Return: None

function send_message

def send_message(
    self self,
    topic topic,
    payload payload
)

Helper function to send a message.

Parameters:

  • topic The topic to which to send a message
  • payload The payload to send in the message

Return: None

function prep_payload

def prep_payload(
    self self,
    data data
)

Helper function to prepare the wrapper for the message.

Parameters:

  • data The data to wrap within the envelope

Return: The wrapped message

Public Attributes Documentation

variable broker

static broker =  os.getenv("MQTT_BROKER");

variable port

static port =  os.getenv("MQTT_PORT");

variable client_id

static string client_id =  'audioplayer';

variable username

static username =  os.getenv("MQTT_USERNAME");

variable password

static password =  os.getenv("MQTT_PASSWORD");

variable client

static client =  None;

variable connected

static bool connected =  False;

variable connected

connected;

Updated on 2022-11-28 at 15:55:23 +0000