Data Gator
Hardware and software documentation for the Data Gator project.
Loading...
Searching...
No Matches
mqtt_util.hpp File Reference

Utilities for receiving and sending MQTT commands. More...

#include <ArduinoJson.h>
#include <string>
#include "SDReader.hpp"
Include dependency graph for mqtt_util.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void process_command (string command, string message)
 Process a command execute it.
 
void callback (char *topic, byte *message, unsigned int length)
 Called when MQTT message is passed to the device by the broker.
 

Detailed Description

Utilities for receiving and sending MQTT commands.

Utilities and interface for receiving MQTT messages from the broker. Also used to request data logged to the uSD card from the device.

  1. defines a basic callback to attach to the MQTT client object to handle received messages.
  2. defines a function to check and take proper action on commands received via MQTT.
Author
Garrett Wells

Function Documentation

◆ callback()

void callback ( char topic,
byte message,
unsigned int  length 
)

Called when MQTT message is passed to the device by the broker.

Prints command and message to serial interface, then parses the MQTT packet and processes the command.

Commands are defined as a anything published to the datagator/cmd/# topic tree. The # symbol is an MQTT regex glob symbol that matches all MAC addresses. It tells the DG to subscribe to all commands published to ALL DGs.

The command is only processed in process_command(...) if the MAC address in the topic, such as datagator/cmd/AC:45... matches the MAC of this DG.

Parameters
[in]topicThe topic the message was published on
[in]messageThe message in the MQTT packet
[in]lengthThe length of the message

◆ process_command()

void process_command ( string  command,
string  message 
)

Process a command execute it.

Checks the command, if the command matches one of the known commands, then the message is processed. The message contains details about how the command should be carried out.

Parameters
[in]commandThe command as a string.
[in]messageThe body/message sent with the command.