mirror of
https://github.com/cesanta/mongoose.git
synced 2026-12-05 22:08:23 +00:00
Restore logging, make WiFi creds settable from make
This commit is contained in:
1 parent
a9a94a6904
commit
b68da1548b
11 files changed
+74
-4
No files matched your search
@@ -16,3 +16,12 @@ pico_enable_stdio_usb(firmware 1) # Route stdio to USB
|
|||||||
|
|
||||||
# Prevent extreme optimization from breaking OTA
|
# Prevent extreme optimization from breaking OTA
|
||||||
target_compile_options(firmware PRIVATE -fno-tree-loop-distribute-patterns)
|
target_compile_options(firmware PRIVATE -fno-tree-loop-distribute-patterns)
|
||||||
|
|
||||||
|
# Wi-Fi credentials from the environment, e.g. make WIFI_NAME=... WIFI_PASS=...
|
||||||
|
# Read when build/ is configured: run "make clean" after changing them
|
||||||
|
if (DEFINED ENV{WIFI_NAME})
|
||||||
|
target_compile_definitions(firmware PRIVATE "WIFI_SSID=\"$ENV{WIFI_NAME}\"")
|
||||||
|
endif()
|
||||||
|
if (DEFINED ENV{WIFI_PASS})
|
||||||
|
target_compile_definitions(firmware PRIVATE "WIFI_PASS=\"$ENV{WIFI_PASS}\"")
|
||||||
|
endif()
|
||||||
@@ -16,10 +16,16 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void log_fn(char ch, void *param) {
|
||||||
|
(void) param;
|
||||||
|
putchar(ch);
|
||||||
|
}
|
||||||
|
|
||||||
// In an RTOS environment, give this task 8 KB of stack space.
|
// In an RTOS environment, give this task 8 KB of stack space.
|
||||||
static void run_mongoose(void) {
|
static void run_mongoose(void) {
|
||||||
void driver_init(struct mg_mgr *mgr);
|
void driver_init(struct mg_mgr *mgr);
|
||||||
struct mg_mgr mgr;
|
struct mg_mgr mgr;
|
||||||
|
mg_log_set_fn(log_fn, NULL);
|
||||||
mg_mgr_init(&mgr);
|
mg_mgr_init(&mgr);
|
||||||
driver_init(&mgr);
|
driver_init(&mgr);
|
||||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||||
|
|||||||
@@ -4,8 +4,13 @@
|
|||||||
#include "hardware/pio.h"
|
#include "hardware/pio.h"
|
||||||
#include "mongoose.h"
|
#include "mongoose.h"
|
||||||
|
|
||||||
#define WIFI_SSID "YOUR_WIFI_NETWORK_NAME" // SET THIS!
|
// Set these, or pass on the command line: make WIFI_NAME=... WIFI_PASS=...
|
||||||
#define WIFI_PASS "YOUR_WIFI_PASSWORD" // SET THIS!
|
#ifndef WIFI_SSID
|
||||||
|
#define WIFI_SSID "YOUR_WIFI_NETWORK_NAME"
|
||||||
|
#endif
|
||||||
|
#ifndef WIFI_PASS
|
||||||
|
#define WIFI_PASS "YOUR_WIFI_PASSWORD"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SPIPIO pio0
|
#define SPIPIO pio0
|
||||||
#define SPISM 0
|
#define SPISM 0
|
||||||
|
|||||||
@@ -44,9 +44,15 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void log_fn(char ch, void *param) {
|
||||||
|
(void) param;
|
||||||
|
putchar(ch);
|
||||||
|
}
|
||||||
|
|
||||||
// In an RTOS environment, give this task 8 KB of stack space.
|
// In an RTOS environment, give this task 8 KB of stack space.
|
||||||
static void run_mongoose(void) {
|
static void run_mongoose(void) {
|
||||||
struct mg_mgr mgr;
|
struct mg_mgr mgr;
|
||||||
|
mg_log_set_fn(log_fn, NULL);
|
||||||
mg_mgr_init(&mgr);
|
mg_mgr_init(&mgr);
|
||||||
driver_init(&mgr);
|
driver_init(&mgr);
|
||||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||||
|
|||||||
@@ -64,12 +64,18 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_dta) {
|
|||||||
if (ev == MG_EV_HTTP_MSG) return mg_http_reply(c, 200, "", "ok\n");
|
if (ev == MG_EV_HTTP_MSG) return mg_http_reply(c, 200, "", "ok\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void log_fn(char ch, void *param) {
|
||||||
|
(void) param;
|
||||||
|
putchar(ch);
|
||||||
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||||
stdio_init_all();
|
stdio_init_all();
|
||||||
|
|
||||||
struct mg_mgr mgr; // Initialise Mongoose event manager
|
struct mg_mgr mgr; // Initialise Mongoose event manager
|
||||||
|
mg_log_set_fn(log_fn, NULL);
|
||||||
mg_mgr_init(&mgr); // and attach it to the interface
|
mg_mgr_init(&mgr); // and attach it to the interface
|
||||||
|
|
||||||
struct mg_tcpip_driver driver = {.tx = usb_tx, .poll = usb_poll};
|
struct mg_tcpip_driver driver = {.tx = usb_tx, .poll = usb_poll};
|
||||||
|
|||||||
@@ -69,9 +69,15 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void log_fn(char ch, void *param) {
|
||||||
|
(void) param;
|
||||||
|
putchar(ch);
|
||||||
|
}
|
||||||
|
|
||||||
// In an RTOS environment, give this task 8 KB of stack space.
|
// In an RTOS environment, give this task 8 KB of stack space.
|
||||||
static void run_mongoose(void) {
|
static void run_mongoose(void) {
|
||||||
struct mg_mgr mgr;
|
struct mg_mgr mgr;
|
||||||
|
mg_log_set_fn(log_fn, NULL);
|
||||||
mg_mgr_init(&mgr);
|
mg_mgr_init(&mgr);
|
||||||
driver_init(&mgr);
|
driver_init(&mgr);
|
||||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||||
|
|||||||
@@ -16,3 +16,12 @@ pico_enable_stdio_usb(firmware 1) # Route stdio to USB
|
|||||||
|
|
||||||
# Prevent extreme optimization from breaking OTA
|
# Prevent extreme optimization from breaking OTA
|
||||||
target_compile_options(firmware PRIVATE -fno-tree-loop-distribute-patterns)
|
target_compile_options(firmware PRIVATE -fno-tree-loop-distribute-patterns)
|
||||||
|
|
||||||
|
# Wi-Fi credentials from the environment, e.g. make WIFI_NAME=... WIFI_PASS=...
|
||||||
|
# Read when build/ is configured: run "make clean" after changing them
|
||||||
|
if (DEFINED ENV{WIFI_NAME})
|
||||||
|
target_compile_definitions(firmware PRIVATE "WIFI_NAME=\"$ENV{WIFI_NAME}\"")
|
||||||
|
endif()
|
||||||
|
if (DEFINED ENV{WIFI_PASS})
|
||||||
|
target_compile_definitions(firmware PRIVATE "WIFI_PASS=\"$ENV{WIFI_PASS}\"")
|
||||||
|
endif()
|
||||||
@@ -23,9 +23,15 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void log_fn(char ch, void *param) {
|
||||||
|
(void) param;
|
||||||
|
putchar(ch);
|
||||||
|
}
|
||||||
|
|
||||||
// In an RTOS environment, give this task 8 KB of stack space.
|
// In an RTOS environment, give this task 8 KB of stack space.
|
||||||
static void run_mongoose(void) {
|
static void run_mongoose(void) {
|
||||||
struct mg_mgr mgr;
|
struct mg_mgr mgr;
|
||||||
|
mg_log_set_fn(log_fn, NULL);
|
||||||
mg_mgr_init(&mgr);
|
mg_mgr_init(&mgr);
|
||||||
mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL);
|
mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL);
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,13 @@
|
|||||||
|
|
||||||
#include "mongoose.h"
|
#include "mongoose.h"
|
||||||
|
|
||||||
#define WIFI_NAME "YOUR_WIFI_NETWORK" // SET THIS!
|
// Set these, or pass on the command line: make WIFI_NAME=... WIFI_PASS=...
|
||||||
#define WIFI_PASS "YOUR_WIFI_PASSWORD" // SET THIS!
|
#ifndef WIFI_NAME
|
||||||
|
#define WIFI_NAME "YOUR_WIFI_NETWORK"
|
||||||
|
#endif
|
||||||
|
#ifndef WIFI_PASS
|
||||||
|
#define WIFI_PASS "YOUR_WIFI_PASSWORD"
|
||||||
|
#endif
|
||||||
|
|
||||||
// Access point setup
|
// Access point setup
|
||||||
#define ENABLE_AP false // Change to true to enable
|
#define ENABLE_AP false // Change to true to enable
|
||||||
|
|||||||
@@ -66,6 +66,11 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void log_fn(char ch, void *param) {
|
||||||
|
(void) param;
|
||||||
|
putchar(ch);
|
||||||
|
}
|
||||||
|
|
||||||
// In an RTOS environment, give this task 8 KB of stack space.
|
// In an RTOS environment, give this task 8 KB of stack space.
|
||||||
static void run_mongoose(void) {
|
static void run_mongoose(void) {
|
||||||
struct mg_mgr mgr;
|
struct mg_mgr mgr;
|
||||||
@@ -75,6 +80,7 @@ static void run_mongoose(void) {
|
|||||||
.driver_data = &spi,
|
.driver_data = &spi,
|
||||||
};
|
};
|
||||||
generate_mac_from_board_id(mif.mac);
|
generate_mac_from_board_id(mif.mac);
|
||||||
|
mg_log_set_fn(log_fn, NULL);
|
||||||
mg_mgr_init(&mgr);
|
mg_mgr_init(&mgr);
|
||||||
mg_tcpip_init(&mgr, &mif);
|
mg_tcpip_init(&mgr, &mif);
|
||||||
MG_INFO(("Driver: W5500, MAC: %M", mg_print_mac, mif.mac));
|
MG_INFO(("Driver: W5500, MAC: %M", mg_print_mac, mif.mac));
|
||||||
|
|||||||
@@ -179,10 +179,16 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void log_fn(char ch, void *param) {
|
||||||
|
(void) param;
|
||||||
|
putchar(ch);
|
||||||
|
}
|
||||||
|
|
||||||
// In an RTOS environment, give this task 8 KB of stack space.
|
// In an RTOS environment, give this task 8 KB of stack space.
|
||||||
static void run_mongoose(void) {
|
static void run_mongoose(void) {
|
||||||
struct mg_mgr mgr;
|
struct mg_mgr mgr;
|
||||||
|
|
||||||
|
mg_log_set_fn(log_fn, NULL);
|
||||||
mg_mgr_init(&mgr);
|
mg_mgr_init(&mgr);
|
||||||
mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL);
|
mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user