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.

110 lines
3.7 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. struct mqtt_msg_t {
  51. String topic;
  52. String message;
  53. };
  54. void mqttHeartbeat(heartbeat::Callback);
  55. void mqttRegister(mqtt_callback_f callback);
  56. String mqttTopic(const char * magnitude, bool is_set);
  57. String mqttTopic(const char * magnitude, unsigned int index, bool is_set);
  58. String mqttMagnitude(const char* topic);
  59. bool mqttSendRaw(const char * topic, const char * message, bool retain);
  60. bool mqttSendRaw(const char * topic, const char * message);
  61. void mqttSend(const char * topic, const char * message, bool force, bool retain);
  62. void mqttSend(const char * topic, const char * message, bool force);
  63. void mqttSend(const char * topic, const char * message);
  64. void mqttSend(const char * topic, unsigned int index, const char * message, bool force, bool retain);
  65. void mqttSend(const char * topic, unsigned int index, const char * message, bool force);
  66. void mqttSend(const char * topic, unsigned int index, const char * message);
  67. void mqttSendStatus();
  68. void mqttFlush();
  69. int8_t mqttEnqueue(const char * topic, const char * message, unsigned char parent);
  70. int8_t mqttEnqueue(const char * topic, const char * message);
  71. const String& mqttPayloadOnline();
  72. const String& mqttPayloadOffline();
  73. const char* mqttPayloadStatus(bool status);
  74. void mqttSetBroker(IPAddress ip, uint16_t port);
  75. void mqttSetBrokerIfNone(IPAddress ip, uint16_t port);
  76. void mqttSubscribeRaw(const char * topic);
  77. void mqttSubscribe(const char * topic);
  78. void mqttUnsubscribeRaw(const char * topic);
  79. void mqttUnsubscribe(const char * topic);
  80. void mqttEnabled(bool status);
  81. bool mqttEnabled();
  82. bool mqttForward();
  83. bool mqttConnected();
  84. void mqttDisconnect();
  85. void mqttSetup();