Loom 4 v4.5
Arduino library for Internet of Things Rapid Prototyping in environmental sensing
Loading...
Searching...
No Matches
Loom_MQTT.h
1#pragma once
2
3#include <ArduinoMqttClient.h>
4
5#include "Loom_Manager.h"
6#include "Module.h"
7
8#include "../../../Hardware/Loom_BatchSD/Loom_BatchSD.h"
9
10
11
17class Loom_MQTT : public Module{
18 protected:
19
20 /* These aren't used with the MQTT */
21 void measure() override {};
22
23 void initialize() override {};
24 void power_up() override {};
25 void power_down() override {};
26 void package() override {};
27
28 public:
29
43 Manager& man,
44 Client& internet_client,
45 const char* broker_address,
46 int broker_port,
47 const char* database_name,
48 const char* broker_user = "",
49 const char* broker_pass = "",
50 const char* projectServer = ""
51 );
52
57 Loom_MQTT(Manager& man, Client& internet_client);
58
62 void publish();
63
67 void publish(Loom_BatchSD& batchSD);
68
73 void setKeepAlive(int time) { keep_alive = time; };
74
79 void setMaxRetries(int retries) { maxRetries = retries; };
80
85 void loadConfigFromJSON(char* json);
86
87 private:
88 Manager* manInst; // Instance of the manager
89
90 Client* internetClient; // Client to supply to the MQTT client to handle internet communication
91 MqttClient mqttClient; // MQTT Client to manage interactions with the MQTT broker
92
93 const char* getMQTTError(); // Get the string representation of the MQTT error codes
94
95 int keep_alive = 60000; // How long the broker should keep the connection open, defaults to a minute
96 int maxRetries = 4; // How many times we want to retry the connection
97
98 char address[100]; // Domain that the broker is running on
99 char database_name[100]; // Database to publish the data to
100 char projectServer[100]; // Project
101 int port; // Port the broker is listening on
102 char topic[100]; // Where to publish the data to
103 char username[100]; // Username to log into the broker
104 char password[100]; // Password to log into the broker
105
106
107
108};
Definition: Loom_BatchSD.h:9
Definition: Loom_MQTT.h:17
void setKeepAlive(int time)
Definition: Loom_MQTT.h:73
void setMaxRetries(int retries)
Definition: Loom_MQTT.h:79
void loadConfigFromJSON(char *json)
Definition: Loom_MQTT.cpp:244
void publish()
Definition: Loom_MQTT.cpp:35
Definition: Loom_Manager.h:18
Definition: Module.h:30