Data Gator
Hardware and software documentation for the Data Gator project.
Loading...
Searching...
No Matches
MQTTMailer.hpp
1
10#ifndef MQTTMAILER_H
11#define MQTTMAILER_H
12
13#include "PubSubClient.h" /*MQTT Interface*/
14#include <WiFiClientSecure.h>
15#include <ArduinoJson.h>
16#include <BLEAddress.h>
17#include <esp_gap_ble_api.h>
18
19extern const bool USB_DEBUG;
20
21/*
22 * Packet design for saving data between transmissions
23 */
24enum PacketType_t {
25 INVALID, // data is garbage, all values should be either 0 or INT_MAX
26 FUDGED, // data has been intentionally set to a "believable value", but don't trust it, it's still garbage
27 VWC, // volumetric water data
28 PH, // same as above, but fourth sensor field is the soil PH reading
29 HT, // temperature and/or humidity data
30 TLM_BLE, // telemetry data from BLE sensor ()
31 TLM // telemetry data for the aggregator
32 };
33
38public:
39 MQTTMail(){}
40 MQTTMail(std::string topic, std::string message){
41 this->topic = topic;
42 this->message = message;
43 }
44
45 std::string getMessage(); // output MQTT compatible representation of data
46 std::string getTopic(); // get the topic string connected to this message
47 //
48 std::string to_string(){ return getTopic() + getMessage(); }
49
50private:
51 std::string topic; // MQTT topic to publish to
52 std::string message;
53
54 PacketType_t packet_type = INVALID; // what information is stored in this packet
55};
56
61public:
62 static MQTTMailer getInstance(){
64 return instance;
65 }
66
67 void mailMessage(
69 std::string topic,
70 std::string message,
71 bool serial_debug=true);
72
74 std::string buildMessage(std::string* elements, int num_elements);
75
76private:
77 MQTTMailer(){}
78};
79
80#endif
An object that stores data from which a topic and message can be extracted for publishing to an MQTT ...
Definition MQTTMailer.hpp:37
std::string getTopic()
The topic/destination this MQTT object should be published to.
Definition MQTTMailer.cpp:20
std::string getMessage()
Convert the data fields to an MQTT message string which can be published.
Definition MQTTMailer.cpp:11
Converts MQTTMail objects into viable MQTT messages so that they can be published.
Definition MQTTMailer.hpp:60
void mailMessage(PubSubClient *mqtt_client, std::string topic, std::string message, bool serial_debug=true)
Publish an MQTT message to a topic hosted by a specific broker.
Definition MQTTMailer.cpp:31
std::string buildMessage(std::string *elements, int num_elements)
Builds a message.
Definition MQTTMailer.cpp:79
void reconnect(PubSubClient mqtt_client)
Attempt to reconnect to MQTT broker every 5 seconds until successful.
Definition MQTTMailer.cpp:48
int reset_count
number of resets retrieved for NVS
Definition scheduler.hpp:31
const bool USB_DEBUG
USB serial debugging enabled.
Definition main.cpp:62
PubSubClient mqtt_client
MQTT client object for logging.