I want to access the HTTP server using over the internet.
I’m going to serve files from the SD card. (Done with this part, but I can access it only locally).
I’ve given the internet to ESP32 using the pppos 4G SIM connection (and not using the WiFi) and I’m getting an IP address after connection establishment. I want to use this IP address globally and as an HTTP Server so that I can access my SD card files from anywhere.
This is my main.c file
#include "mgos.h"
#include "mgos_http_server.h"
#include "esp_err.h"
#include "esp_vfs_fat.h"
#include "driver/sdmmc_host.h"
#include "driver/sdspi_host.h"
#include "sdmmc_cmd.h"
#define MGOS_F_RELOAD_CONFIG MG_F_USER_5
//****SPI2 Pin Defined Here****
#define PIN_NUM_MISO 19
#define PIN_NUM_MOSI 23
#define PIN_NUM_CLK 18
#define PIN_NUM_CS 5
//****************************
static const char *uri = "/sdcard/";
static void event_handler(struct mg_connection *c, int ev, void *p, void *user_data)
{
(void)p;
if (ev != MG_EV_HTTP_REQUEST)
return;
LOG(LL_INFO, ("Foo requested"));
mg_send_response_line(c, 200, "Content-Type: multipart/form-data\r\n");
mg_printf(c, "%s\r\n", "event_handler");
c->flags |= (MG_F_SEND_AND_CLOSE | MGOS_F_RELOAD_CONFIG);
(void)user_data;
}
// static void timer_cb(void *arg) {}
enum mgos_app_init_result mgos_app_init(void)
{
// mgos_set_timer(1000 /* ms */, MGOS_TIMER_REPEAT, timer_cb, NULL);
//-----------------SD-CARD----------------------//
LOG(LL_INFO, ("%s", "SDMMC initialize !!!!!"));
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
sdspi_slot_config_t slot_config = SDSPI_SLOT_CONFIG_DEFAULT();
slot_config.gpio_miso = PIN_NUM_MISO;
slot_config.gpio_mosi = PIN_NUM_MOSI;
slot_config.gpio_sck = PIN_NUM_CLK;
slot_config.gpio_cs = PIN_NUM_CS;
esp_vfs_fat_sdmmc_mount_config_t mount_config =
{
.format_if_mount_failed = false,
.max_files = 5,
.allocation_unit_size = 16 * 1024};
sdmmc_card_t *card;
esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
if (ret != ESP_OK)
{
if (ret == ESP_FAIL)
{
LOG(LL_INFO, ("%s", "Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true."));
}
else
{
LOG(LL_INFO, ("Failed to initialize the card (%s). ", esp_err_to_name(ret)));
}
return false;
}
sdmmc_card_print_info(stdout, card);
//-----------------SD-CARD----------------------//
//start my code---------------------------HTTP----------------------------------//
struct mg_connection *mgos_get_sys_http_server(void);
mgos_register_http_endpoint(uri, event_handler, NULL);
//end my code-----------------------------HTTP----------------------------1 ----//
return MGOS_APP_INIT_SUCCESS;
}
And this one is my mos.yml file
author: mongoose-os
description: A Mongoose OS app skeleton
version: 1.0
libs_version: ${mos.version}
modules_version: ${mos.version}
mongoose_os_version: ${mos.version}
tags:
- c
sources:
- src
filesystem:
- fs
config_schema:
- ["http", "o", {title: "HTTP Server"}]
- ["http.enable", "b", true, {title: "Enable HTTP Server"}]
- ["http.listen_addr", "s", "80", {title: "Listening port / address"}]
- ["http.document_root", "s", "/sdcard/", {title: "Root for serving files. Setting to empty disables file serving."}]
- ["http.index_files", "s", "", {title: "Comma-separated list of index files"}]
cdefs:
MGOS_ENABLE_WEB_CONFIG: 0
libs:
- origin: https://github.com/mongoose-os-libs/boards
- origin: https://github.com/mongoose-os-libs/ca-bundle
- origin: https://github.com/mongoose-os-libs/rpc-service-config
- origin: https://github.com/mongoose-os-libs/rpc-service-fs
- origin: https://github.com/mongoose-os-libs/rpc-uart
- origin: https://github.com/mongoose-os-libs/http-server
- origin: https://github.com/nliviu/sdlib
# Used by the mos tool to catch mos binaries incompatible with this file format
manifest_version: 2017-09-29