Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.6 KiB

  1. /*
  2. MQTT MODULE
  3. Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
  4. Updated secure client support by Niek van der Maas < mail at niekvandermaas dot nl>
  5. */
  6. #pragma once
  7. #include <WString.h>
  8. #include <utility>
  9. #include <functional>
  10. using mqtt_callback_f = std::function<void(unsigned int type, const char * topic, char * payload)>;
  11. using mqtt_msg_t = std::pair<String, String>; // topic, payload
  12. #if MQTT_SUPPORT
  13. #if MQTT_LIBRARY == MQTT_LIBRARY_ASYNCMQTTCLIENT
  14. #include <ESPAsyncTCP.h>
  15. #include <AsyncMqttClient.h>
  16. #elif MQTT_LIBRARY == MQTT_LIBRARY_ARDUINOMQTT
  17. #include <MQTTClient.h>
  18. #elif MQTT_LIBRARY == MQTT_LIBRARY_PUBSUBCLIENT
  19. #include <PubSubClient.h>
  20. #endif
  21. void mqttRegister(mqtt_callback_f callback);
  22. String mqttTopic(const char * magnitude, bool is_set);
  23. String mqttTopic(const char * magnitude, unsigned int index, bool is_set);
  24. String mqttMagnitude(char * topic);
  25. bool mqttSendRaw(const char * topic, const char * message, bool retain);
  26. bool mqttSendRaw(const char * topic, const char * message);
  27. void mqttSend(const char * topic, const char * message, bool force, bool retain);
  28. void mqttSend(const char * topic, const char * message, bool force);
  29. void mqttSend(const char * topic, const char * message);
  30. void mqttSend(const char * topic, unsigned int index, const char * message, bool force);
  31. void mqttSend(const char * topic, unsigned int index, const char * message);
  32. const String& mqttPayloadOnline();
  33. const String& mqttPayloadOffline();
  34. const char* mqttPayloadStatus(bool status);
  35. void mqttSendStatus();
  36. #endif // MQTT_SUPPORT == 1