Files
ch32v203-eth-node/include/mqtt_handler.h

43 lines
1.0 KiB
C

#ifndef MQTT_HANDLER_H
#define MQTT_HANDLER_H
#include <DHCP/dhcp.h>
#include <stdbool.h>
#include "ch32v003fun.h"
#include "w5500.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;
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;
extern char nodes_list[MAX_PAYLOAD_LENGTH];
void mqtt_init(mqtt_state_t* state);
void mqtt_process(mqtt_state_t* state);
void message_arrived(MessageData* md);
void publish_value(MQTTClient* client, const char* device_name,
const char* property, uint16_t value);
void publish_retained(MQTTClient* client, const char* topic,
const char* payload);
void publish_message(MQTTClient* client, const char* payload,
const char* topic);
#endif