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.

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