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.

80 lines
2.3 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 "espurna.h"
  8. #include <WString.h>
  9. #include <utility>
  10. #include <functional>
  11. using mqtt_callback_f = std::function<void(unsigned int type, const char * topic, char * payload)>;
  12. using mqtt_msg_t = std::pair<String, String>; // topic, payload
  13. #if MQTT_SUPPORT
  14. #if MQTT_LIBRARY == MQTT_LIBRARY_ASYNCMQTTCLIENT
  15. #include <ESPAsyncTCP.h>
  16. #include <AsyncMqttClient.h>
  17. #elif MQTT_LIBRARY == MQTT_LIBRARY_ARDUINOMQTT
  18. #include <MQTTClient.h>
  19. #elif MQTT_LIBRARY == MQTT_LIBRARY_PUBSUBCLIENT
  20. #include <PubSubClient.h>
  21. #endif
  22. void mqttRegister(mqtt_callback_f callback);
  23. String mqttTopic(const char * magnitude, bool is_set);
  24. String mqttTopic(const char * magnitude, unsigned int index, bool is_set);
  25. String mqttMagnitude(char * topic);
  26. bool mqttSendRaw(const char * topic, const char * message, bool retain);
  27. bool mqttSendRaw(const char * topic, const char * message);
  28. void mqttSend(const char * topic, const char * message, bool force, bool retain);
  29. void mqttSend(const char * topic, const char * message, bool force);
  30. void mqttSend(const char * topic, const char * message);
  31. void mqttSend(const char * topic, unsigned int index, const char * message, bool force, bool retain);
  32. void mqttSend(const char * topic, unsigned int index, const char * message, bool force);
  33. void mqttSend(const char * topic, unsigned int index, const char * message);
  34. void mqttSendStatus();
  35. void mqttFlush();
  36. int8_t mqttEnqueue(const char * topic, const char * message, unsigned char parent);
  37. int8_t mqttEnqueue(const char * topic, const char * message);
  38. const String& mqttPayloadOnline();
  39. const String& mqttPayloadOffline();
  40. const char* mqttPayloadStatus(bool status);
  41. void mqttSetBroker(IPAddress ip, uint16_t port);
  42. void mqttSetBrokerIfNone(IPAddress ip, uint16_t port);
  43. void mqttSubscribeRaw(const char * topic);
  44. void mqttSubscribe(const char * topic);
  45. void mqttUnsubscribeRaw(const char * topic);
  46. void mqttUnsubscribe(const char * topic);
  47. void mqttEnabled(bool status);
  48. bool mqttEnabled();
  49. bool mqttForward();
  50. bool mqttConnected();
  51. void mqttDisconnect();
  52. void mqttSetup();
  53. #endif // MQTT_SUPPORT == 1