47 lines
1.1 KiB
C
47 lines
1.1 KiB
C
#ifndef MQTT_HANDLER_H
|
|
#define MQTT_HANDLER_H
|
|
|
|
#include <DHCP/dhcp.h>
|
|
#include <stdbool.h>
|
|
|
|
#include "ch32v003fun.h"
|
|
#include "network.h"
|
|
|
|
#define MAX_PAYLOAD_LENGTH 256
|
|
|
|
// Options structure for client identification
|
|
typedef struct {
|
|
char* clientid;
|
|
char* username;
|
|
char* password;
|
|
int qos;
|
|
} ch32_mqtt_options_t;
|
|
|
|
// MQTT state
|
|
typedef struct {
|
|
Network network;
|
|
MQTTClient client;
|
|
ch32_mqtt_options_t opts;
|
|
uint32_t last_reconnect;
|
|
uint32_t last_yield;
|
|
bool is_connected;
|
|
char base_topic[64];
|
|
bool discovery_published;
|
|
} mqtt_state_t;
|
|
|
|
// List of connected MQTT nodes
|
|
extern char nodes_list[MAX_PAYLOAD_LENGTH];
|
|
|
|
void mqtt_init(mqtt_state_t* state);
|
|
void mqtt_process(mqtt_state_t* state);
|
|
// Callback for handling incoming MQTT messages
|
|
void message_arrived(MessageData* md);
|
|
// Publish a retained message to an MQTT topic
|
|
void publish_retained(MQTTClient* client, const char* topic,
|
|
const char* payload);
|
|
// Publish a QoS 0 message to a MQTT topic
|
|
void publish_message(MQTTClient* client, const char* payload,
|
|
const char* topic);
|
|
|
|
#endif // MQTT_HANDLER_H
|