chore: mqtt impl, fix more wiznet bugs

This commit is contained in:
2024-11-10 02:47:54 +06:00
parent 80cf21f143
commit 3ac9c62241
19 changed files with 1093 additions and 253 deletions

View File

@@ -3,23 +3,74 @@
#include <stdint.h>
// Debug flags
#define DEBUG_MODE 1
#define DNS_RUN_INTERVAL_MS 100
// Device Bus Types
typedef enum { BUS_RS485, BUS_ONEWIRE } bus_type_t;
// #define LOCAL_PORT 5000
// Device Type Definitions
typedef enum {
DEVICE_RELAY = 1,
DEVICE_SOIL_SENSOR = 2,
DEVICE_THERMOMETER = 3
} device_type_t;
// MQTT configuration
#define CLIENT_ID "ch32_node"
// Node Configuration
typedef struct {
const char* id; // Unique identifier for the node
const char* name; // Human readable name
const char* location; // Optional location description
} node_config_t;
#define MQTT_TARGET_IP {192, 168, 102, 100}
#define MQTT_TARGET_PORT 1883
// RS485 Device Configuration
typedef struct {
uint8_t slave_id; // Modbus slave ID
device_type_t type; // Type of device
const char* name; // Device name (used in MQTT topics)
} rs485_device_t;
// OneWire naming scheme configuration
typedef struct {
const char* location; // Location prefix for the sensor
const char* name_prefix; // Prefix for auto-generated names
} onewire_naming_t;
// Network Configuration
#define MQTT_SERVER_IP {192, 168, 102, 100}
#define MQTT_PORT 1883
// MQTT Configuration
#define MQTT_KEEP_ALIVE_INTERVAL 60
#define MQTT_TX_BUFFER_SIZE 128
#define MQTT_RX_BUFFER_SIZE 128
#define MQTT_COMMAND_TIMEOUT_MS 1000
#define SUB_TOPIC "listen/world"
#define PUB_TOPIC "hello/world"
// Node Specific Configuration
static const node_config_t NODE_CONFIG = {
.id = "ch32-node1", .name = "CH32 Node 1", .location = "somewhere"};
// RS485 Devices Configuration
#define RS485_DEVICE_COUNT 2
static const rs485_device_t RS485_DEVICES[RS485_DEVICE_COUNT] = {
{.slave_id = 0x01, .type = DEVICE_RELAY, .name = "relay-1"},
{.slave_id = 0x02, .type = DEVICE_SOIL_SENSOR, .name = "soil-monitor-1"}};
// OneWire Naming Configuration
#define MAX_ONEWIRE_DEVICES 8
static const onewire_naming_t ONEWIRE_NAMING[] = {
{.location = "tank", .name_prefix = "water-temp"},
{.location = "ambient", .name_prefix = "air-temp"},
{.location = "soil", .name_prefix = "soil-temp"}};
// Structure to store discovered OneWire devices
typedef struct {
uint8_t address[8]; // OneWire address
uint8_t location_index; // Index into ONEWIRE_NAMING array
char name[32]; // Generated name (e.g., "tank-water-temp-1")
uint8_t sequence; // Sequence number within its location
} onewire_device_t;
#endif // CONFIG_H