mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-18 19:31:02 +00:00
Update HTTP server Arduino example
This commit is contained in:
1 parent
74f77c9ded
commit
03c955410c
2 files changed
+30
-31
No files matched your search
@@ -13,5 +13,10 @@
|
|||||||
#define MG_ENABLE_DRIVER_W5500 1
|
#define MG_ENABLE_DRIVER_W5500 1
|
||||||
#define MG_ENABLE_TCPIP_DRIVER_INIT 0
|
#define MG_ENABLE_TCPIP_DRIVER_INIT 0
|
||||||
#define mkdir(a, b) (-1)
|
#define mkdir(a, b) (-1)
|
||||||
|
#define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 0
|
||||||
|
#define MG_ENABLE_CUSTOM_MILLIS 1
|
||||||
#define MG_IO_SIZE 128
|
#define MG_IO_SIZE 128
|
||||||
//#define MG_ENABLE_LOG 0
|
|
||||||
|
// Enable TLS
|
||||||
|
// #define MG_TLS MG_TLS_BUILTIN
|
||||||
|
// #define MG_ENABLE_CUSTOM_RANDOM 1
|
||||||
@@ -1,42 +1,36 @@
|
|||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include "mongoose.h"
|
#include "mongoose.h"
|
||||||
|
|
||||||
#define SS_PIN 17 // Slave select pin
|
#define LED_PIN 21 // Slave select pin
|
||||||
struct mg_mgr mgr; // Mongoose event manager
|
#define SS_PIN 17 // Slave select pin
|
||||||
|
|
||||||
struct mg_tcpip_spi spi = {
|
struct mg_tcpip_spi spi = {
|
||||||
NULL, // SPI data
|
NULL, // SPI metadata
|
||||||
[](void *) { digitalWrite(SS_PIN, LOW); }, // begin transation
|
[](void *) { digitalWrite(SS_PIN, LOW); SPI.beginTransaction(SPISettings()); },
|
||||||
[](void *) { digitalWrite(SS_PIN, HIGH); }, // end transaction
|
[](void *) { digitalWrite(SS_PIN, HIGH); SPI.endTransaction(); },
|
||||||
[](void *, uint8_t c) { return SPI.transfer(c); }, // execute transaction
|
[](void *, uint8_t c) { return SPI.transfer(c); }, // Execute transaction
|
||||||
};
|
};
|
||||||
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 5}}; // network interface
|
struct mg_mgr mgr; // Mongoose event manager
|
||||||
|
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 5}}; // Network interface
|
||||||
|
|
||||||
|
uint64_t mg_millis(void) {
|
||||||
|
return millis();
|
||||||
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200); // Initialise serial
|
||||||
mg_log_set_fn([](char ch, void *) { Serial.print(ch); }, NULL);
|
while (!Serial) delay(50); // for debug output
|
||||||
mg_log_set(MG_LL_DEBUG);
|
|
||||||
while (!Serial) (void) 0;
|
|
||||||
|
|
||||||
pinMode(SS_PIN, OUTPUT);
|
SPI.begin(); // Iniitialise SPI
|
||||||
SPI.begin();
|
pinMode(SS_PIN, OUTPUT); // to communicate with W5500 Ethernet module
|
||||||
|
pinMode(LED_PIN, OUTPUT); // Initialise LED
|
||||||
|
|
||||||
mg_mgr_init(&mgr);
|
mg_mgr_init(&mgr); // Initialise Mongoose event manager
|
||||||
// delay(3000);
|
mg_log_set(MG_LL_DEBUG); // Set debug log level
|
||||||
MG_INFO(("Starting TCP/IP stack..."));
|
mg_log_set_fn([](char ch, void *) { Serial.print(ch); }, NULL); // Log serial
|
||||||
SPI.transfer(0);
|
mif.driver = &mg_tcpip_driver_w5500; // Use W5500 built-in driver
|
||||||
MG_INFO(("--->..."));
|
mif.driver_data = &spi; // Pass SPI interface to W5500 driver
|
||||||
|
mg_tcpip_init(&mgr, &mif); // Initialise built-in TCP/IP stack
|
||||||
mif.driver = &mg_tcpip_driver_w5500;
|
|
||||||
mif.driver_data = &spi;
|
|
||||||
mg_tcpip_init(&mgr, &mif);
|
|
||||||
|
|
||||||
// Start a 5 sec timer, print status message periodically
|
|
||||||
mg_timer_add(
|
|
||||||
&mgr, 5000, MG_TIMER_REPEAT,
|
|
||||||
[](void *) {
|
|
||||||
MG_INFO(("ethernet: %s", mg_tcpip_driver_w5500.up(&mif) ? "up" : "down"));
|
|
||||||
},
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
// Setup HTTP listener. Respond "ok" on any HTTP request
|
// Setup HTTP listener. Respond "ok" on any HTTP request
|
||||||
mg_http_listen(
|
mg_http_listen(
|
||||||
|
|||||||
Reference in new issue
Block a user