summaryrefslogtreecommitdiff
path: root/include/pio/libs/mqtt_module_diagnostics/homekit/mqtt/module/diagnostics.h
blob: bb7a81aba6634f3fe26f8f7f6d306724120e381e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef HOMEKIT_LIB_MQTT_MODULE_DIAGNOSTICS_H
#define HOMEKIT_LIB_MQTT_MODULE_DIAGNOSTICS_H

#include <stdint.h>
#include <homekit/mqtt/module.h>

namespace homekit::mqtt {

struct DiagnosticsFlags {
    uint8_t state: 1;
    uint8_t config_changed_value_present: 1;
    uint8_t config_changed: 1;
    uint8_t reserved: 5;
} __attribute__((packed));

struct MqttInitialDiagnosticsPayload {
    uint32_t ip;
    uint8_t fw_version;
    int8_t rssi;
    uint32_t free_heap;
    DiagnosticsFlags flags;
} __attribute__((packed));

struct MqttDiagnosticsPayload {
    int8_t rssi;
    uint32_t free_heap;
    DiagnosticsFlags flags;
} __attribute__((packed));


class MqttDiagnosticsModule: public MqttModule {
private:
    bool initialSent;

    void sendDiagnostics(Mqtt& mqtt);

public:
    MqttDiagnosticsModule()
        : MqttModule(30)
        , initialSent(false) {}

    void onConnect(Mqtt& mqtt) override;
    void onDisconnect(Mqtt& mqtt, espMqttClientTypes::DisconnectReason reason) override;
    void tick(Mqtt& mqtt) override;
};

}

#endif //HOMEKIT_LIB_MQTT_MODULE_DIAGNOSTICS_H