Skip to content

Commit

Permalink
Add extra debugging messages.
Browse files Browse the repository at this point in the history
Ref #1035
  • Loading branch information
crankyoldgit committed Feb 1, 2020
1 parent 7de4902 commit e717c5f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
16 changes: 8 additions & 8 deletions examples/IRMQTTServer/IRMQTTServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
#define BAUD_RATE 115200 // Serial port Baud rate.

// Change if you need multiple independent send gpios & topics. (MQTT only)
const uint8_t kNrOfIrTxGpios = 1;
const uint8_t kNrOfIrTxGpios = 7;
// Default GPIO the IR LED is connected to/controlled by. GPIO 4 = D2.
// For an ESP-01 we suggest you use RX/GPIO3/Pin 7. i.e. kDefaultIrLed = 3
// Note: A value of -1 means unused.
const int8_t kDefaultIrLed = 4; // <=- CHANGE_ME (optional)
const int8_t kDefaultIrLed = 16; // <=- CHANGE_ME (optional)

// **DANGER** Optional flag to invert the output. (default = false)
// `false`: The LED is illuminated when the GPIO is HIGH.
Expand Down Expand Up @@ -101,25 +101,25 @@ const uint32_t kMqttReconnectTime = 5000; // Delay(ms) between reconnect tries.
#define MQTT_CLIMATE_CMND "cmnd" // Sub-topic for the climate command topics.
#define MQTT_CLIMATE_STAT "stat" // Sub-topic for the climate stat topics.
// Enable sending/receiving climate via JSON. `true` cost ~5k of program space.
#define MQTT_CLIMATE_JSON false
#define MQTT_CLIMATE_JSON true
// Use Home Assistant-style operation modes.
// i.e. Change the climate mode to "off" when turning the power "off".
// See: https://www.home-assistant.io/components/climate.mqtt/#modes
// Change to false, if your home automation system doesn't like this.
#define MQTT_CLIMATE_HA_MODE true
#define MQTT_CLIMATE_HA_MODE false
// Do we send an IR message when we reboot and recover the existing A/C state?
// If set to `false` you may miss requested state changes while the ESP was
// down. If set to `true`, it will resend the previous desired state sent to the
// A/C. Depending on your circumstances, you may need to change this.
#define MQTT_CLIMATE_IR_SEND_ON_RESTART false
#define MQTT_CLIMATE_IR_SEND_ON_RESTART true
#define MQTTbroadcastInterval 10 * 60 // Seconds between rebroadcasts.

#define QOS 1 // MQTT broker should queue up any unreceived messages for us
// #define QOS 0 // MQTT broker WON'T queue up messages for us. Fire & Forget.

// Enable(true)/Disable(false) the option to send a MQTT Discovery message for
// the AirCon/Climate system to Home Assistant. Note: `false` saves ~1.5k.
#define MQTT_DISCOVERY_ENABLE true
#define MQTT_DISCOVERY_ENABLE false
// Enable(true)/Disable(false) the option to clear any settings stored in MQTT
// for this device's current config. e.g. Climate states using MQTT retain.
// In theory, you shouldn't need this as you can always clean up by hand, hence
Expand Down Expand Up @@ -233,13 +233,13 @@ const uint16_t kJsonAcStateMaxSize = 1024; // Bytes
// See `isSerialGpioUsedByIr()`.
// Note: Debug costs ~6k of program space.
#ifndef DEBUG
#define DEBUG false // Change to 'true' for serial debug output.
#define DEBUG true // Change to 'true' for serial debug output.
#endif // DEBUG

// ----------------- End of User Configuration Section -------------------------

// Constants
#define _MY_VERSION_ "v1.4.5"
#define _MY_VERSION_ "v1.4.5-kevinspecial"

const uint8_t kRebootTime = 15; // Seconds
const uint8_t kQuickDisplayTime = 2; // Seconds
Expand Down
21 changes: 17 additions & 4 deletions examples/IRMQTTServer/IRMQTTServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,19 @@ void unsubscribing(const String topic_name) {
debug(topic_name.c_str());
}

// Send an MQTT message and log what we did to debug.
bool mqttPublish(const char* topic, const char* payload, boolean retained) {
if (retained)
debug("MQTT publish (with retain):");
else
debug("MQTT publish:");
debug("Topic:");
debug(topic);
debug("Payload:");
debug(payload);
return mqtt_client.publish(topic, payload, retained);
}

void mqttLog(const char* str) {
debug(str);
mqtt_client.publish(MqttLog.c_str(), str);
Expand Down Expand Up @@ -2784,7 +2797,7 @@ bool sendIRCode(IRsend *irsend, decode_type_t const ir_type,
bool sendInt(const String topic, const int32_t num, const bool retain) {
#if MQTT_ENABLE
mqttSentCounter++;
return mqtt_client.publish(topic.c_str(), String(num).c_str(), retain);
return mqttPublish(topic.c_str(), String(num).c_str(), retain);
#else // MQTT_ENABLE
return true;
#endif // MQTT_ENABLE
Expand All @@ -2793,7 +2806,7 @@ bool sendInt(const String topic, const int32_t num, const bool retain) {
bool sendBool(const String topic, const bool on, const bool retain) {
#if MQTT_ENABLE
mqttSentCounter++;
return mqtt_client.publish(topic.c_str(), (on ? "on" : "off"), retain);
return mqttPublish(topic.c_str(), (on ? "on" : "off"), retain);
#else // MQTT_ENABLE
return true;
#endif // MQTT_ENABLE
Expand All @@ -2802,7 +2815,7 @@ bool sendBool(const String topic, const bool on, const bool retain) {
bool sendString(const String topic, const String str, const bool retain) {
#if MQTT_ENABLE
mqttSentCounter++;
return mqtt_client.publish(topic.c_str(), str.c_str(), retain);
return mqttPublish(topic.c_str(), str.c_str(), retain);
#else // MQTT_ENABLE
return true;
#endif // MQTT_ENABLE
Expand All @@ -2811,7 +2824,7 @@ bool sendString(const String topic, const String str, const bool retain) {
bool sendFloat(const String topic, const float_t temp, const bool retain) {
#if MQTT_ENABLE
mqttSentCounter++;
return mqtt_client.publish(topic.c_str(), String(temp, 1).c_str(), retain);
return mqttPublish(topic.c_str(), String(temp, 1).c_str(), retain);
#else // MQTT_ENABLE
return true;
#endif // MQTT_ENABLE
Expand Down

0 comments on commit e717c5f

Please sign in to comment.