LOM2M  0.8.0
Functions | Variables
mqttBinding.cpp File Reference
#include "mqttBinding.h"
#include "JsonMapper.h"
#include "RequestPrimitive.h"
#include "gateway.h"
#include "keys.h"
#include "lom2m.h"
#include "tools.h"
#include <LittleFS.h>
#include <NTPClient.h>
#include <WiFiUdp.h>

Functions

bool sendBadRequestMqtt (MqttTopic *mqttTopic)
 
bool mqtt_setup (WiFiClientSecure *espClient)
 
void mqtt_reconnect (WiFiClientSecure *espClient, PubSubClient *client, bool loop)
 
void mqtt_callback (char *topic, byte *payload, unsigned int length)
 
bool mqtt_send_response (PubSubClient &client, ResponsePrimitive &resp, MqttTopic &mqttTopic)
 
bool mqtt_send_request (PubSubClient &client, RequestPrimitive &req, String &mqttTopic)
 
void sendResponse (ResponsePrimitive &response)
 

Variables

PubSubClient * MQTT_CLIENT = nullptr
 
WiFiClientSecure * ESP_CLIENT = nullptr
 
String message
 
MqttTopic mqttTopic
 

Function Documentation

◆ mqtt_callback()

void mqtt_callback ( char *  topic,
byte *  payload,
unsigned int  length 
)

Callback to use when a new MQTT message is received

Parameters
topic- the topic of the received message
payload- of the message
lenght- of the message

This is used for MQTT setup and subscription

◆ mqtt_reconnect()

void mqtt_reconnect ( WiFiClientSecure *  espClient,
PubSubClient *  client,
bool  loop = true 
)

Reconnect to the MQTT broker

Parameters
client- PubSubClient (mqtt) used to publish and subscribe to topics on the broker
espClientused for the TCP connection
loop- enables to try only once to reconnect or to loop until it is connected Default is keep looping until connected. Used when connection is lost and will lock the process into reconnection phase until it succeeds (if loop set to true or not set at all)

◆ mqtt_send_request()

bool mqtt_send_request ( PubSubClient &  client,
RequestPrimitive req,
String &  mqttTopic 
)

◆ mqtt_send_response()

bool mqtt_send_response ( PubSubClient &  client,
ResponsePrimitive resp,
MqttTopic mqttTopic 
)

Send a response over MQTTS

Parameters
client- MQTT client to use
resp- response primitive to serialize and to send over mqtt
topic- mqtt topic structure containing elements to build the topic to publish to

◆ mqtt_setup()

bool mqtt_setup ( WiFiClientSecure *  espClient)

Perform all the setup for MQTTS binding

  • load CA
  • load device cert
  • load private key
    Parameters
    espClientused for secure connection establishment

◆ sendBadRequestMqtt()

bool sendBadRequestMqtt ( MqttTopic mqttTopic)

◆ sendResponse()

void sendResponse ( ResponsePrimitive response)

Variable Documentation

◆ ESP_CLIENT

WiFiClientSecure* ESP_CLIENT = nullptr

◆ message

String message

◆ MQTT_CLIENT

PubSubClient* MQTT_CLIENT = nullptr

◆ mqttTopic

MqttTopic mqttTopic