Skip to content

Commit 03c9554

Browse files
committed
Update HTTP server Arduino example
1 parent 74f77c9 commit 03c9554

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

examples/arduino/w5500-http/mongoose_config.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@
1313
#define MG_ENABLE_DRIVER_W5500 1
1414
#define MG_ENABLE_TCPIP_DRIVER_INIT 0
1515
#define mkdir(a, b) (-1)
16+
#define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 0
17+
#define MG_ENABLE_CUSTOM_MILLIS 1
1618
#define MG_IO_SIZE 128
17-
//#define MG_ENABLE_LOG 0
19+
20+
// Enable TLS
21+
// #define MG_TLS MG_TLS_BUILTIN
22+
// #define MG_ENABLE_CUSTOM_RANDOM 1

examples/arduino/w5500-http/w5500-http.ino

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,36 @@
11
#include <SPI.h>
22
#include "mongoose.h"
33

4-
#define SS_PIN 17 // Slave select pin
5-
struct mg_mgr mgr; // Mongoose event manager
4+
#define LED_PIN 21 // Slave select pin
5+
#define SS_PIN 17 // Slave select pin
6+
67
struct mg_tcpip_spi spi = {
7-
NULL, // SPI data
8-
[](void *) { digitalWrite(SS_PIN, LOW); }, // begin transation
9-
[](void *) { digitalWrite(SS_PIN, HIGH); }, // end transaction
10-
[](void *, uint8_t c) { return SPI.transfer(c); }, // execute transaction
8+
NULL, // SPI metadata
9+
[](void *) { digitalWrite(SS_PIN, LOW); SPI.beginTransaction(SPISettings()); },
10+
[](void *) { digitalWrite(SS_PIN, HIGH); SPI.endTransaction(); },
11+
[](void *, uint8_t c) { return SPI.transfer(c); }, // Execute transaction
1112
};
12-
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 5}}; // network interface
13+
struct mg_mgr mgr; // Mongoose event manager
14+
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 5}}; // Network interface
15+
16+
uint64_t mg_millis(void) {
17+
return millis();
18+
}
1319

1420
void setup() {
15-
Serial.begin(115200);
16-
mg_log_set_fn([](char ch, void *) { Serial.print(ch); }, NULL);
17-
mg_log_set(MG_LL_DEBUG);
18-
while (!Serial) (void) 0;
19-
20-
pinMode(SS_PIN, OUTPUT);
21-
SPI.begin();
22-
23-
mg_mgr_init(&mgr);
24-
// delay(3000);
25-
MG_INFO(("Starting TCP/IP stack..."));
26-
SPI.transfer(0);
27-
MG_INFO(("--->..."));
28-
29-
mif.driver = &mg_tcpip_driver_w5500;
30-
mif.driver_data = &spi;
31-
mg_tcpip_init(&mgr, &mif);
32-
33-
// Start a 5 sec timer, print status message periodically
34-
mg_timer_add(
35-
&mgr, 5000, MG_TIMER_REPEAT,
36-
[](void *) {
37-
MG_INFO(("ethernet: %s", mg_tcpip_driver_w5500.up(&mif) ? "up" : "down"));
38-
},
39-
NULL);
21+
Serial.begin(115200); // Initialise serial
22+
while (!Serial) delay(50); // for debug output
23+
24+
SPI.begin(); // Iniitialise SPI
25+
pinMode(SS_PIN, OUTPUT); // to communicate with W5500 Ethernet module
26+
pinMode(LED_PIN, OUTPUT); // Initialise LED
27+
28+
mg_mgr_init(&mgr); // Initialise Mongoose event manager
29+
mg_log_set(MG_LL_DEBUG); // Set debug log level
30+
mg_log_set_fn([](char ch, void *) { Serial.print(ch); }, NULL); // Log serial
31+
mif.driver = &mg_tcpip_driver_w5500; // Use W5500 built-in driver
32+
mif.driver_data = &spi; // Pass SPI interface to W5500 driver
33+
mg_tcpip_init(&mgr, &mif); // Initialise built-in TCP/IP stack
4034

4135
// Setup HTTP listener. Respond "ok" on any HTTP request
4236
mg_http_listen(

0 commit comments

Comments
 (0)