diff --git a/examples/arduino/w5500-http/mongoose_config.h b/examples/arduino/w5500-http/mongoose_config.h index 31a4d635..a42cf006 100644 --- a/examples/arduino/w5500-http/mongoose_config.h +++ b/examples/arduino/w5500-http/mongoose_config.h @@ -8,15 +8,11 @@ #include #define MG_ARCH MG_ARCH_CUSTOM -#define MG_ENABLE_SOCKET 0 #define MG_ENABLE_TCPIP 1 #define MG_ENABLE_DRIVER_W5500 1 #define MG_ENABLE_TCPIP_DRIVER_INIT 0 -#define mkdir(a, b) (-1) #define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 0 #define MG_ENABLE_CUSTOM_MILLIS 1 -#define MG_IO_SIZE 128 - -// Enable TLS +#define MG_ENABLE_CUSTOM_RANDOM 1 // #define MG_TLS MG_TLS_BUILTIN -// #define MG_ENABLE_CUSTOM_RANDOM 1 +#define MG_IO_SIZE 128 diff --git a/examples/arduino/w5500-http/w5500-http.ino b/examples/arduino/w5500-http/w5500-http.ino index 0073be24..d1be1a8c 100644 --- a/examples/arduino/w5500-http/w5500-http.ino +++ b/examples/arduino/w5500-http/w5500-http.ino @@ -1,8 +1,8 @@ #include #include "mongoose.h" -#define LED_PIN 21 // Slave select pin -#define SS_PIN 17 // Slave select pin +#define LED_PIN LED_BUILTIN // LED pin - can be LED_BUILTIN +#define SS_PIN 17 // Slave select pin struct mg_tcpip_spi spi = { NULL, // SPI metadata @@ -17,6 +17,20 @@ uint64_t mg_millis(void) { return millis(); } +bool mg_random(void *buf, size_t len) { // For TLS + uint8_t *p = (uint8_t *) buf; + while (len--) *p++ = (unsigned char) (rand() & 255); + return true; +} + +// Crude function to get available RAM, for quick profiling +size_t getFreeRAM(void) { + size_t size = 0, increment = 100; + void *p; + while ((p = malloc(size)) != NULL) free(p), size += increment; + return size; +} + void setup() { Serial.begin(115200); // Initialise serial while (!Serial) delay(50); // for debug output @@ -36,7 +50,18 @@ void setup() { mg_http_listen( &mgr, "http://0.0.0.0", [](struct mg_connection *c, int ev, void *ev_data) { - if (ev == MG_EV_HTTP_MSG) mg_http_reply(c, 200, "", "ok\n"); + if (ev == MG_EV_HTTP_MSG) { + struct mg_http_message *hm = (struct mg_http_message *) ev_data; + if (mg_match(hm->uri, mg_str("/api/led/on"), NULL)) { + digitalWrite(LED_PIN, HIGH); + mg_http_reply(c, 200, "", "{%m: %d}\n", MG_ESC("led"), digitalRead(LED_PIN)); + } else if (mg_match(hm->uri, mg_str("/api/led/off"), NULL)) { + digitalWrite(LED_PIN, LOW); + mg_http_reply(c, 200, "", "{%m: %d}\n", MG_ESC("led"), digitalRead(LED_PIN)); + } else { + mg_http_reply(c, 200, "", "ok, free RAM: %u\n", getFreeRAM()); + } + } }, &mgr); } diff --git a/examples/arduino/w5500-mqtt/mongoose_config.h b/examples/arduino/w5500-mqtt/mongoose_config.h index 782aa509..d9e625d8 100644 --- a/examples/arduino/w5500-mqtt/mongoose_config.h +++ b/examples/arduino/w5500-mqtt/mongoose_config.h @@ -12,7 +12,6 @@ #define MG_ENABLE_TCPIP 1 #define MG_ENABLE_DRIVER_W5500 1 #define MG_ENABLE_TCPIP_DRIVER_INIT 0 -#define mkdir(a, b) (-1) #define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 0 #define MG_ENABLE_CUSTOM_MILLIS 1 #define MG_ENABLE_CUSTOM_RANDOM 1