dhcp attempts

This commit is contained in:
2024-10-13 05:32:44 +06:00
parent ec9dcc76f7
commit 480a4a1ca5
12 changed files with 329 additions and 63 deletions

25
include/config.h Normal file
View File

@@ -0,0 +1,25 @@
#ifndef CONFIG_H
#define CONFIG_H
#include <stdint.h>
#define DEBUG_MODE 1
#define DNS_RUN_INTERVAL_MS 100
// #define LOCAL_PORT 5000
// MQTT configuration
#define CLIENT_ID "ch32_node"
#define MQTT_TARGET_IP {192, 168, 102, 147}
#define MQTT_TARGET_PORT 1883
#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"
#endif // CONFIG_H

14
include/debug.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef DEBUG_H
#define DEBUG_H
#include <stdio.h>
#include "config.h"
#ifdef DEBUG_MODE
#define DEBUG_PRINT(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DEBUG_PRINT(fmt, ...)
#endif
#endif // DEBUG_H

14
include/systick.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef SYSTICK_H
#define SYSTICK_H
#include <stdint.h>
#define SYSTICK_ONE_MILLISECOND ((uint32_t)FUNCONF_SYSTEM_CORE_CLOCK / 1000)
#define millis() (systick_millis)
void systick_init(void);
// ms counter incremented by SysTick
extern volatile uint32_t systick_millis;
#endif // SYSTICK_H

View File

@@ -1,25 +1,25 @@
#ifndef W5500_H
#define W5500_H
#include <MQTT/MQTTClient.h>
#include <stdint.h>
// Sets the CS pin low
void w5500_select(void);
// Definitions for socket indexes
#define DHCP_SOCKET 0
#define DNS_SOCKET 1
#define TCP_SOCKET 2
// Sets the CS pin high
void w5500_unselect(void);
// Options structure for client identification
typedef struct {
char* clientid;
char* username;
char* password;
int qos;
} ch32_mqtt_options_t;
// Reads a byte via SPI
uint8_t w5500_read_byte(void);
extern volatile int ip_assigned;
// Writes a byte via SPI
void w5500_write_byte(uint8_t byte);
// Reads multiple bytes via SPI
void w5500_read_buffer(uint8_t* buff, uint16_t len);
// Writes multiple bytes via SPI
void w5500_write_buffer(uint8_t* buff, uint16_t len);
void handle_ip_assigned(void);
// Initializes the W5500 chip
void configure_network(void);
@@ -27,4 +27,14 @@ void configure_network(void);
// resolves a domain name
void resolve_domain_name(const char* domain_name);
// init and connect the MQTT client
MQTTClient setup_mqtt_client(Network* network, ch32_mqtt_options_t* opts);
int subscribe_to_topic(MQTTClient* client, const char* topic, enum QoS qos,
messageHandler message_callback);
// publish a message to a topic
void publish_message(MQTTClient* client, const char* payload,
const char* topic);
#endif // W5500_H