Modular ESP Firmware - MQTT - Declarations and Defines

From The TinkerNet Wiki
Jump to navigation Jump to search

In TopSecret.h

 1 // MQTT
 2 // Store your MQTT credentials here.
 3 // Update these with values suitable for your network.
 4 
 5 // Set BrokerName OR BrokerIP, not both...
 6 const char* MQTT_broker = "BROKER.YOURDOMAIN.TLD";
 7 // const int*  MQTT_BrokerIP = { 192, 168, 0, 12 };
 8 
 9 const char* MQTT_user = "";
10 const char* MQTT_pass = "";
11 
12 const char* MQTT_ClientName = "GimmeAName";

In MQTT.h

 1 #ifndef MQTT_H
 2 #define MQTT_H
 3 
 4 #define MQTT_BUFFER_SIZE (50)       // This number is arbitrary
 5                                     // Topic can be up to 65,536 bytes
 6                                     // Message can be up to 268,435,456 bytes
 7 
 8 char MQTT_outTopic[MQTT_BUFFER_SIZE];
 9 char MQTT_inTopic[MQTT_BUFFER_SIZE];
10 char MQTT_teleTopic[MQTT_BUFFER_SIZE];
11 char MQTT_statTopic[MQTT_BUFFER_SIZE];
12 
13 char MQTT_msg_out[MQTT_BUFFER_SIZE];
14 
15 unsigned long beacon_timer = 0;
16 #define BEACON_INTERVAL 30000 // Timer interval for the "keep-alive" status beacon
17 
18 #endif  // MQTT_H

In functions.h

 1 // MQTT Stuff
 2 
 3 #include <PubSubClient.h>
 4 
 5 void setup_mqtt();
 6 
 7 void MQTT_callback(char *topic, byte *payload, int length);
 8 void MQTT_reconnect();
 9 void MQTT_beacon();
10 
11 void DOtheBloodyMQTT();
12 
13 void setup();
14 void loop();
15 
16 bool getTimer(unsigned long &timer, unsigned long interval);
17 void blinkLED();                // Just a little function to blink the LED for the beacon function.
18 void DoLights(char const *WhatToDo);  // Turn LED on/off
19 void DoAnswer(char *WhatToDo);  // Send back text
20 void DoControl(char *WhatToDo); // Send MQTT to another device/topic
21 
22 void MQTT_Status(char const *Device, char const *Status);