mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-06 15:51:25 +00:00
Add esp32 example
This commit is contained in:
1 parent
1252a61479
commit
b641fc6b79
6 files changed
+161
-5
No files matched your search
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2020 Cesanta Software Limited
|
||||
// All rights reserved
|
||||
|
||||
#include "mongoose.h"
|
||||
|
||||
#define WIFI_SSID "MY_WIFI_NETWORK"
|
||||
#define WIFI_PASS "MY_WIFI_PASSWORD"
|
||||
#define LISTENING_ADDR "http://0.0.0.0:80"
|
||||
|
||||
// Event handler for an accepted connection
|
||||
static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
if (ev == MG_EV_HTTP_MSG) {
|
||||
mg_http_reply(c, 200, "Hello from ESP32!");
|
||||
}
|
||||
}
|
||||
|
||||
// Called after we're connected to WiFi network
|
||||
static void start_server(void) {
|
||||
struct mg_mgr mgr;
|
||||
mg_log_set("3");
|
||||
mg_mgr_init(&mgr);
|
||||
mg_http_listen(&mgr, LISTENING_ADDR, cb, &mgr);
|
||||
LOG(LL_INFO, ("Starting Mongoose web server v%s", MG_VERSION));
|
||||
for (;;) mg_mgr_poll(&mgr, 1000);
|
||||
mg_mgr_free(&mgr);
|
||||
}
|
||||
|
||||
void app_main(void) {
|
||||
// Setup wifi. This function is implemented in wifi.c
|
||||
// It blocks until connected to the configured WiFi network
|
||||
void wifi_init(const char *ssid, const char *pass);
|
||||
wifi_init(WIFI_SSID, WIFI_PASS);
|
||||
|
||||
// Done connecting to WiFi, now start HTTP server
|
||||
start_server();
|
||||
}
|
||||
Reference in new issue
Block a user