mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-14 10:20:01 +00:00
move MicroPython and dashboards -> tutorials
This commit is contained in:
1 parent
1078ba0a92
commit
b3f5d11275
97 files changed
+22
-20
No files matched your search
@@ -0,0 +1,13 @@
|
||||
|
||||
all: example
|
||||
micropython/ports/unix/build-standard/micropython main.py
|
||||
|
||||
example: micropython
|
||||
$(MAKE) -C micropython/ports/unix submodules
|
||||
$(MAKE) -C micropython/ports/unix USER_C_MODULES=../../..
|
||||
|
||||
micropython:
|
||||
git clone --depth 1 -b v1.22.2 https://github.com/micropython/micropython.git
|
||||
|
||||
clean:
|
||||
rm -rf micropython
|
||||
@@ -0,0 +1,11 @@
|
||||
# Mongoose as a MicroPython user module
|
||||
|
||||
The most basic usage is in `main.py`.
|
||||
|
||||
You'll have to configure Mongoose for your desired platform, this example runs on the `unix` port and Mongoose detects it as a known architecture and hence configures itself to use sockets and time base. For other platforms, you'll have to do your homework (there's plenty of Mongoose examples for several platforms); also check respective MicroPython build instructions.
|
||||
|
||||
For more information, check this third-party article: [part 1](https://www.embeddedrelated.com/showarticle/1649.php), [part 2](https://www.embeddedrelated.com/showarticle/1670.php)
|
||||
|
||||
Check [_thread](https://docs.micropython.org/en/latest/library/_thread.html) support for more advanced usage
|
||||
|
||||
https://docs.micropython.org/en/latest/develop/cmodules.html
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
THISDIR = $(realpath $(CURDIR))
|
||||
ROOTDIR = $(realpath $(CURDIR)/../../..)
|
||||
PORT ?= /dev/ttyUSB0
|
||||
DOCKER ?= docker run --rm $(DA) -v $(ROOTDIR):$(ROOTDIR) -w $(THISDIR) espressif/idf:v5.0.4
|
||||
# Note that the esp32 port needs the extra .. for relative paths due to the location of its main CMakeLists.txt file
|
||||
CMD ?= bash -c '$(MAKE) -C micropython/ports/esp32 submodules && $(MAKE) -C micropython/ports/esp32 USER_C_MODULES=../../../../mongoose/micropython.cmake'
|
||||
|
||||
all: example
|
||||
|
||||
example:
|
||||
true
|
||||
|
||||
build: micropython
|
||||
$(DOCKER) $(CMD)
|
||||
|
||||
micropython:
|
||||
$(DOCKER) git clone --depth 1 -b v1.22.2 https://github.com/micropython/micropython.git
|
||||
|
||||
clean:
|
||||
test -d micropython && $(DOCKER) rm -rf micropython || true
|
||||
|
||||
flash:
|
||||
flash: DA = --device $(PORT)
|
||||
flash: CMD = bash -c '$(MAKE) -C micropython/ports/esp32 erase deploy'
|
||||
flash: build
|
||||
@@ -0,0 +1,21 @@
|
||||
# Mongoose as a MicroPython user module on the ESP32
|
||||
|
||||
The most basic usage is:
|
||||
|
||||
```python
|
||||
import network
|
||||
import mongoose
|
||||
|
||||
sta_if = network.WLAN(network.STA_IF)
|
||||
sta_if.active(True)
|
||||
sta_if.connect("<SSID>", "<PASSWORD>")
|
||||
while not sta_if.isconnected():
|
||||
pass
|
||||
|
||||
mongoose.init()
|
||||
while True:
|
||||
mongoose.poll(1000)
|
||||
|
||||
```
|
||||
|
||||
[Please check the Linux example for more information and useful links](../README.md)
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright (c) 2022 Cesanta Software Limited
|
||||
// All rights reserved
|
||||
|
||||
#include "mongoose.h"
|
||||
|
||||
static void t_fn(void *arg) { // Tick periodically
|
||||
MG_INFO(("tick"));
|
||||
(void) arg;
|
||||
}
|
||||
|
||||
static void fn(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_HTTP_MSG) mg_http_reply(c, 200, "", "hi\n");
|
||||
(void) ev_data;
|
||||
}
|
||||
|
||||
static struct mg_mgr mgr;
|
||||
|
||||
void mgmp_init(void) {
|
||||
mg_mgr_init(&mgr); // Mongoose event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
|
||||
mg_timer_add(&mgr, 1000, MG_TIMER_REPEAT, t_fn, &mgr);
|
||||
mg_http_listen(&mgr, "http://0.0.0.0:80", fn, &mgr);
|
||||
}
|
||||
|
||||
void mgmp_poll(int t) {
|
||||
mg_mgr_poll(&mgr, t);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
../../mongoose/micropython.cmake
|
||||
@@ -0,0 +1 @@
|
||||
../../mongoose/micropython.mk
|
||||
@@ -0,0 +1 @@
|
||||
../../mongoose/module.c
|
||||
@@ -0,0 +1 @@
|
||||
../../../../mongoose.c
|
||||
@@ -0,0 +1 @@
|
||||
../../../../mongoose.h
|
||||
@@ -0,0 +1 @@
|
||||
#define MG_ARCH MG_ARCH_ESP32
|
||||
@@ -0,0 +1,5 @@
|
||||
import mongoose
|
||||
|
||||
mongoose.init()
|
||||
while True:
|
||||
mongoose.poll(1000)
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright (c) 2022 Cesanta Software Limited
|
||||
// All rights reserved
|
||||
|
||||
#include "mongoose.h"
|
||||
|
||||
static void t_fn(void *arg) { // Tick periodically
|
||||
MG_INFO(("tick"));
|
||||
(void) arg;
|
||||
}
|
||||
|
||||
static void fn(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_HTTP_MSG) mg_http_reply(c, 200, "", "hi\n");
|
||||
(void) ev_data;
|
||||
}
|
||||
|
||||
static struct mg_mgr mgr;
|
||||
|
||||
void mgmp_init(void) {
|
||||
mg_mgr_init(&mgr); // Mongoose event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
|
||||
mg_timer_add(&mgr, 1000, MG_TIMER_REPEAT, t_fn, &mgr);
|
||||
mg_http_listen(&mgr, "http://0.0.0.0:8000", fn, &mgr);
|
||||
}
|
||||
|
||||
void mgmp_poll(int t) {
|
||||
mg_mgr_poll(&mgr, t);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
# Create an INTERFACE library for our C module.
|
||||
add_library(usermod_mongoose INTERFACE)
|
||||
|
||||
# Add our source files to the lib
|
||||
target_sources(usermod_mongoose INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/module.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/mongoose.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/main.c
|
||||
)
|
||||
|
||||
# Add the current directory as an include directory.
|
||||
target_include_directories(usermod_mongoose INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Link our INTERFACE library to the usermod target.
|
||||
target_link_libraries(usermod INTERFACE usermod_mongoose)
|
||||
@@ -0,0 +1,9 @@
|
||||
CEXAMPLE_MOD_DIR := $(USERMOD_DIR)
|
||||
|
||||
# Add all C files to SRC_USERMOD.
|
||||
SRC_USERMOD += $(CEXAMPLE_MOD_DIR)/module.c
|
||||
SRC_USERMOD += $(CEXAMPLE_MOD_DIR)/mongoose.c
|
||||
SRC_USERMOD += $(CEXAMPLE_MOD_DIR)/main.c
|
||||
|
||||
# add our module folder to include paths
|
||||
CFLAGS_USERMOD += -I$(CEXAMPLE_MOD_DIR)
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "py/runtime.h"
|
||||
|
||||
extern void mgmp_init(void);
|
||||
extern void mgmp_poll(int);
|
||||
|
||||
STATIC mp_obj_t mongoose_init(void) {
|
||||
mgmp_init();
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mongoose_init_obj, mongoose_init);
|
||||
|
||||
STATIC mp_obj_t mongoose_poll(mp_obj_t t_obj) {
|
||||
mgmp_poll(mp_obj_get_int(t_obj));
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mongoose_poll_obj, mongoose_poll);
|
||||
|
||||
STATIC const mp_rom_map_elem_t mongoose_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_mongoose) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&mongoose_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_poll), MP_ROM_PTR(&mongoose_poll_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(mongoose_module_globals, mongoose_module_globals_table);
|
||||
|
||||
const mp_obj_module_t mongoose_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t *)&mongoose_module_globals,
|
||||
};
|
||||
|
||||
MP_REGISTER_MODULE(MP_QSTR_mongoose, mongoose_module);
|
||||
@@ -0,0 +1 @@
|
||||
../../../mongoose.c
|
||||
@@ -0,0 +1 @@
|
||||
../../../mongoose.h
|
||||
Reference in new issue
Block a user