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.

105 lines
3.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 "espurna.h"
  8. #include <functional>
  9. // These will be concatenated to the MQTT_TOPIC base to form the actual topic
  10. #define MQTT_TOPIC_JSON "data"
  11. #define MQTT_TOPIC_ACTION "action"
  12. #define MQTT_TOPIC_RELAY "relay"
  13. #define MQTT_TOPIC_LED "led"
  14. #define MQTT_TOPIC_BUTTON "button"
  15. #define MQTT_TOPIC_IP "ip"
  16. #define MQTT_TOPIC_SSID "ssid"
  17. #define MQTT_TOPIC_BSSID "bssid"
  18. #define MQTT_TOPIC_VERSION "version"
  19. #define MQTT_TOPIC_UPTIME "uptime"
  20. #define MQTT_TOPIC_DATETIME "datetime"
  21. #define MQTT_TOPIC_TIMESTAMP "timestamp"
  22. #define MQTT_TOPIC_FREEHEAP "freeheap"
  23. #define MQTT_TOPIC_VCC "vcc"
  24. #define MQTT_TOPIC_STATUS "status"
  25. #define MQTT_TOPIC_MAC "mac"
  26. #define MQTT_TOPIC_RSSI "rssi"
  27. #define MQTT_TOPIC_MESSAGE_ID "id"
  28. #define MQTT_TOPIC_APP "app"
  29. #define MQTT_TOPIC_INTERVAL "interval"
  30. #define MQTT_TOPIC_HOSTNAME "host"
  31. #define MQTT_TOPIC_DESCRIPTION "desc"
  32. #define MQTT_TOPIC_TIME "time"
  33. #define MQTT_TOPIC_RFOUT "rfout"
  34. #define MQTT_TOPIC_RFIN "rfin"
  35. #define MQTT_TOPIC_RFLEARN "rflearn"
  36. #define MQTT_TOPIC_RFRAW "rfraw"
  37. #define MQTT_TOPIC_UARTIN "uartin"
  38. #define MQTT_TOPIC_UARTOUT "uartout"
  39. #define MQTT_TOPIC_LOADAVG "loadavg"
  40. #define MQTT_TOPIC_BOARD "board"
  41. #define MQTT_TOPIC_PULSE "pulse"
  42. #define MQTT_TOPIC_SPEED "speed"
  43. #define MQTT_TOPIC_IRIN "irin"
  44. #define MQTT_TOPIC_IROUT "irout"
  45. #define MQTT_TOPIC_OTA "ota"
  46. #define MQTT_TOPIC_TELNET_REVERSE "telnet_reverse"
  47. #define MQTT_TOPIC_CURTAIN "curtain"
  48. #define MQTT_TOPIC_CMD "cmd"
  49. using mqtt_callback_f = std::function<void(unsigned int type, const char * topic, char * payload)>;
  50. void mqttHeartbeat(heartbeat::Callback);
  51. void mqttRegister(mqtt_callback_f callback);
  52. String mqttTopic(const char * magnitude, bool is_set);
  53. String mqttTopic(const char * magnitude, unsigned int index, bool is_set);
  54. String mqttMagnitude(const char* topic);
  55. bool mqttSendRaw(const char * topic, const char * message, bool retain);
  56. bool mqttSendRaw(const char * topic, const char * message);
  57. void mqttSend(const char * topic, const char * message, bool force, bool retain);
  58. void mqttSend(const char * topic, const char * message, bool force);
  59. void mqttSend(const char * topic, const char * message);
  60. void mqttSend(const char * topic, unsigned int index, const char * message, bool force, bool retain);
  61. void mqttSend(const char * topic, unsigned int index, const char * message, bool force);
  62. void mqttSend(const char * topic, unsigned int index, const char * message);
  63. void mqttSendStatus();
  64. void mqttFlush();
  65. void mqttEnqueue(const char* topic, const char* message);
  66. const String& mqttPayloadOnline();
  67. const String& mqttPayloadOffline();
  68. const char* mqttPayloadStatus(bool status);
  69. void mqttSetBroker(IPAddress ip, uint16_t port);
  70. void mqttSetBrokerIfNone(IPAddress ip, uint16_t port);
  71. void mqttSubscribeRaw(const char * topic);
  72. void mqttSubscribe(const char * topic);
  73. void mqttUnsubscribeRaw(const char * topic);
  74. void mqttUnsubscribe(const char * topic);
  75. void mqttEnabled(bool status);
  76. bool mqttEnabled();
  77. bool mqttForward();
  78. bool mqttConnected();
  79. void mqttDisconnect();
  80. void mqttSetup();