mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-21 19:51:50 +00:00
Make w5500 driver like the rest
This commit is contained in:
1 parent
277741ca53
commit
93f2939655
17 files changed
+182
-130
No files matched your search
@@ -10,7 +10,12 @@
|
||||
#define MG_ARCH MG_ARCH_CUSTOM
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_DRIVER_W5500 1
|
||||
#define MG_ENABLE_TCPIP_DRIVER_INIT 0
|
||||
// Fixed MAC address for the W5500 module
|
||||
#define MG_SET_MAC_ADDRESS(mac) \
|
||||
do { \
|
||||
mac[0] = 2, mac[1] = 0, mac[2] = 1, mac[3] = 2; \
|
||||
mac[4] = 3, mac[5] = 5; \
|
||||
} while (0)
|
||||
#define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 0
|
||||
#define MG_ENABLE_CUSTOM_MILLIS 1
|
||||
#define MG_ENABLE_CUSTOM_RANDOM 1
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
#define LED_PIN 21 // LED pin
|
||||
|
||||
struct mg_connection *mqtt_connection;
|
||||
struct mg_tcpip_spi spi = {
|
||||
// SPI bus used by the W5500 driver, see MG_TCPIP_DRIVER_W5500_INIT
|
||||
struct mg_tcpip_spi mg_spi = {
|
||||
NULL, // SPI metadata
|
||||
[](void *) { digitalWrite(SS_PIN, LOW); SPI.beginTransaction(SPISettings()); },
|
||||
[](void *) { digitalWrite(SS_PIN, HIGH); SPI.endTransaction(); },
|
||||
@@ -20,8 +21,7 @@ struct mg_tcpip_spi spi = {
|
||||
}
|
||||
},
|
||||
};
|
||||
struct mg_mgr mgr; // Mongoose event manager
|
||||
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 5}}; // Network interface
|
||||
struct mg_mgr mgr; // Mongoose event manager
|
||||
|
||||
uint64_t mg_millis(void) {
|
||||
return millis();
|
||||
@@ -79,7 +79,7 @@ static void mqtt_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
||||
}
|
||||
|
||||
void reconnect_if_not_connected(void) {
|
||||
if (mif.state == MG_TCPIP_STATE_READY && mqtt_connection == NULL) {
|
||||
if (mgr.ifp->state == MG_TCPIP_STATE_READY && mqtt_connection == NULL) {
|
||||
struct mg_mqtt_opts opts = {};
|
||||
opts.clean = true;
|
||||
mqtt_connection =
|
||||
@@ -95,12 +95,9 @@ void setup() {
|
||||
pinMode(SS_PIN, OUTPUT); // to communicate with W5500 Ethernet module
|
||||
pinMode(LED_PIN, OUTPUT); // Initialise LED
|
||||
|
||||
mg_mgr_init(&mgr); // Initialise Mongoose event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set debug log level
|
||||
mg_log_set_fn([](char ch, void *) { Serial.print(ch); }, NULL); // Log serial
|
||||
mif.driver = &mg_tcpip_driver_w5500; // Use W5500 built-in driver
|
||||
mif.driver_data = &spi; // Pass SPI interface to W5500 driver
|
||||
mg_tcpip_init(&mgr, &mif); // Initialise built-in TCP/IP stack
|
||||
mg_mgr_init(&mgr); // Initialise Mongoose event manager and W5500 driver
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
@@ -10,7 +10,12 @@
|
||||
#define MG_ARCH MG_ARCH_CUSTOM
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_DRIVER_W5500 1
|
||||
#define MG_ENABLE_TCPIP_DRIVER_INIT 0
|
||||
// Fixed MAC address for the W5500 module
|
||||
#define MG_SET_MAC_ADDRESS(mac) \
|
||||
do { \
|
||||
mac[0] = 2, mac[1] = 0, mac[2] = 1, mac[3] = 2; \
|
||||
mac[4] = 3, mac[5] = 5; \
|
||||
} while (0)
|
||||
#define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 0
|
||||
#define MG_ENABLE_CUSTOM_MILLIS 1
|
||||
#define MG_ENABLE_CUSTOM_RANDOM 1
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
#define LED_PIN LED_BUILTIN // LED pin
|
||||
#define SS_PIN 17 // Slave select pin for the W5500 module
|
||||
|
||||
struct mg_tcpip_spi spi = {
|
||||
// SPI bus used by the W5500 driver, see MG_TCPIP_DRIVER_W5500_INIT
|
||||
struct mg_tcpip_spi mg_spi = {
|
||||
NULL, // SPI metadata
|
||||
[](void *) { digitalWrite(SS_PIN, LOW); SPI.beginTransaction(SPISettings()); },
|
||||
[](void *) { digitalWrite(SS_PIN, HIGH); SPI.endTransaction(); },
|
||||
@@ -16,8 +17,7 @@ struct mg_tcpip_spi spi = {
|
||||
}
|
||||
},
|
||||
};
|
||||
struct mg_mgr mgr; // Mongoose event manager
|
||||
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 5}}; // Network interface
|
||||
struct mg_mgr mgr; // Mongoose event manager
|
||||
|
||||
// Used by Mongoose for time tracking
|
||||
uint64_t mg_millis(void) {
|
||||
@@ -99,12 +99,9 @@ void setup() {
|
||||
pinMode(SS_PIN, OUTPUT); // to communicate with W5500 Ethernet module
|
||||
pinMode(LED_PIN, OUTPUT); // Initialise LED
|
||||
|
||||
mg_mgr_init(&mgr); // Initialise Mongoose event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set debug log level
|
||||
mg_log_set_fn([](char ch, void *) { Serial.print(ch); }, NULL); // Log serial
|
||||
mif.driver = &mg_tcpip_driver_w5500; // Use W5500 built-in driver
|
||||
mif.driver_data = &spi; // Pass SPI interface to W5500 driver
|
||||
mg_tcpip_init(&mgr, &mif); // Initialise built-in TCP/IP stack
|
||||
mg_mgr_init(&mgr); // Initialise Mongoose event manager and W5500 driver
|
||||
|
||||
// Setup HTTP & HTTPS listeners. Respond "ok" on any HTTP request
|
||||
mg_http_listen(&mgr, "http://0.0.0.0:80", http_ev_handler, NULL);
|
||||
|
||||
@@ -11,7 +11,12 @@
|
||||
#define MG_ENABLE_SOCKET 0
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_DRIVER_W5500 1
|
||||
#define MG_ENABLE_TCPIP_DRIVER_INIT 0
|
||||
// Fixed MAC address for the W5500 module
|
||||
#define MG_SET_MAC_ADDRESS(mac) \
|
||||
do { \
|
||||
mac[0] = 2, mac[1] = 0, mac[2] = 1, mac[3] = 2; \
|
||||
mac[4] = 3, mac[5] = 5; \
|
||||
} while (0)
|
||||
#define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 0
|
||||
#define MG_ENABLE_CUSTOM_MILLIS 1
|
||||
#define MG_ENABLE_CUSTOM_RANDOM 1
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
#define LED_PIN 21 // LED pin
|
||||
|
||||
struct mg_connection *mqtt_connection;
|
||||
struct mg_tcpip_spi spi = {
|
||||
// SPI bus used by the W5500 driver, see MG_TCPIP_DRIVER_W5500_INIT
|
||||
struct mg_tcpip_spi mg_spi = {
|
||||
NULL, // SPI metadata
|
||||
[](void *) { digitalWrite(SS_PIN, LOW); SPI.beginTransaction(SPISettings()); },
|
||||
[](void *) { digitalWrite(SS_PIN, HIGH); SPI.endTransaction(); },
|
||||
@@ -20,8 +21,7 @@ struct mg_tcpip_spi spi = {
|
||||
}
|
||||
},
|
||||
};
|
||||
struct mg_mgr mgr; // Mongoose event manager
|
||||
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 5}}; // Network interface
|
||||
struct mg_mgr mgr; // Mongoose event manager
|
||||
|
||||
uint64_t mg_millis(void) {
|
||||
return millis();
|
||||
@@ -79,7 +79,7 @@ static void mqtt_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
||||
}
|
||||
|
||||
void reconnect_if_not_connected(void) {
|
||||
if (mif.state == MG_TCPIP_STATE_READY && mqtt_connection == NULL) {
|
||||
if (mgr.ifp->state == MG_TCPIP_STATE_READY && mqtt_connection == NULL) {
|
||||
struct mg_mqtt_opts opts = {};
|
||||
opts.clean = true;
|
||||
mqtt_connection =
|
||||
@@ -95,12 +95,9 @@ void setup() {
|
||||
pinMode(SS_PIN, OUTPUT); // to communicate with W5500 Ethernet module
|
||||
pinMode(LED_PIN, OUTPUT); // Initialise LED
|
||||
|
||||
mg_mgr_init(&mgr); // Initialise Mongoose event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set debug log level
|
||||
mg_log_set_fn([](char ch, void *) { Serial.print(ch); }, NULL); // Log serial
|
||||
mif.driver = &mg_tcpip_driver_w5500; // Use W5500 built-in driver
|
||||
mif.driver_data = &spi; // Pass SPI interface to W5500 driver
|
||||
mg_tcpip_init(&mgr, &mif); // Initialise built-in TCP/IP stack
|
||||
mg_mgr_init(&mgr); // Initialise Mongoose event manager and W5500 driver
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
Reference in new issue
Block a user