How to use mongoose in Arduino Opta Lite #2499
-
Copied from the issues section: #2498
Environment
Example code: #include "mongoose.h"
struct mg_mgr mgr; // Mongoose event manager
struct mg_tcpip_driver_stm32_data driver_data = {.mdc_cr = 4};
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 5}}; // network interface
void setup() {
Serial.begin(115200);
while (!Serial);
// Set logging function to a serial print
Serial.print("Booting...");
mg_log_set_fn([](char ch, void *) { Serial.print(ch); }, NULL);
mg_mgr_init(&mgr);
delay(3000);
MG_INFO(("Starting TCP/IP stack..."));
mif.driver = &mg_tcpip_driver_stm32;
mif.driver_data = &driver_data;
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_stm32.up(&mif) ? "up" : "down"));
},
NULL);
// Setup HTTP listener. Respond "ok" on any HTTP request
mg_http_listen(
&mgr, "http://0.0.0.0",
[](struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (ev == MG_EV_HTTP_MSG) mg_http_reply(c, 200, "", "ok\n");
},
&mgr);
}
void loop() {
mg_mgr_poll(&mgr, 1);
} To get it compiling, I got this part commented out (mongoose.c lines from 9297-9319):
The mongoose_custom.h file, I tested: #pragma once
#include "Arduino.h"
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
#include "mbedtls_config.h"
#define MG_ARCH MG_ARCH_CUSTOM
#define MG_ENABLE_SOCKET 0
#define MG_ENABLE_TCPIP 1
#define MG_ENABLE_FILE 0 // Disable POSIX filesystem
#define MG_ENABLE_MBEDTLS 1
#define MG_ENABLE_DRIVER_STM32 1
#define mkdir(a, b) (-1)
#define MG_IO_SIZE 128
#define MG_TLS MG_TLS_MBED
#define MG_ENABLE_PACKED_FS 1
I hope you are now happy, @scaprile. I recommend you to not hinder open source spirit, as your project is open source, and I did free work to test on a different microcontroller. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Answered in the referred issue |
Beta Was this translation helpful? Give feedback.
Answered in the referred issue