Add wifi, nvs and inplace_function implementations
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
set(SOURCES src/main.cpp)
|
||||
set(INCLUDES include)
|
||||
|
||||
idf_component_register(SRCS ${SOURCES} INCLUDE_DIRS ${INCLUDES})
|
||||
idf_component_register(SRCS ${SOURCES} INCLUDE_DIRS ${INCLUDES} REQUIRES wifi nvs nanofmt)
|
||||
|
||||
@@ -1,54 +1,46 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: CC0-1.0
|
||||
*/
|
||||
#include <nvs/nvs.h>
|
||||
#include <wifi/wifi.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_chip_info.h"
|
||||
#include "esp_flash.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "nanofmt/format.h"
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
printf("Hello world!\n");
|
||||
extern "C" void app_main(void) {
|
||||
try {
|
||||
nvs::init();
|
||||
wifi::init();
|
||||
|
||||
/* Print chip information */
|
||||
esp_chip_info_t chip_info;
|
||||
uint32_t flash_size;
|
||||
esp_chip_info(&chip_info);
|
||||
printf("This is %s chip with %d CPU core(s), %s%s%s%s, ",
|
||||
CONFIG_IDF_TARGET,
|
||||
chip_info.cores,
|
||||
(chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "WiFi/" : "",
|
||||
(chip_info.features & CHIP_FEATURE_BT) ? "BT" : "",
|
||||
(chip_info.features & CHIP_FEATURE_BLE) ? "BLE" : "",
|
||||
(chip_info.features & CHIP_FEATURE_IEEE802154) ? ", 802.15.4 (Zigbee/Thread)" : "");
|
||||
// wifi::set_mode(wifi::Mode::station);
|
||||
// wifi::configure_station(
|
||||
// "Vodafone-180C", "giraffen!",
|
||||
// {.stationStarted = []() { wifi::station_connect(); },
|
||||
// .disconnected = [] { wifi::station_connect(); },
|
||||
// .gotIp =
|
||||
// [](auto ip) {
|
||||
// ESP_LOGI("DEBUG - ip callback ", "Got ip: %s",
|
||||
// ip.data());
|
||||
// }});
|
||||
// wifi::start();
|
||||
|
||||
unsigned major_rev = chip_info.revision / 100;
|
||||
unsigned minor_rev = chip_info.revision % 100;
|
||||
printf("silicon revision v%d.%d, ", major_rev, minor_rev);
|
||||
if(esp_flash_get_size(NULL, &flash_size) != ESP_OK) {
|
||||
printf("Get flash size failed");
|
||||
return;
|
||||
// wifi::stop();
|
||||
// wifi::clear_callbacks();
|
||||
// wifi::stop();
|
||||
// wifi::deinit();
|
||||
|
||||
wifi::set_mode(wifi::Mode::soft_ap);
|
||||
wifi::configure_soft_ap(
|
||||
"HyperLink", "1234567890",
|
||||
{.connected =
|
||||
[](auto mac, auto aid) {
|
||||
ESP_LOGI("DEBUG - ap callback", "Connected to mac %s",
|
||||
mac.data());
|
||||
},
|
||||
.disconnected =
|
||||
[](auto mac, auto aid) {
|
||||
ESP_LOGI("DEBUG - ap callback", "Disconnected from mac %s",
|
||||
mac.data());
|
||||
}});
|
||||
wifi::start();
|
||||
} catch (const std::exception& e) {
|
||||
ESP_LOGE("main", "Exception: %s", e.what());
|
||||
}
|
||||
|
||||
printf("%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024),
|
||||
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
|
||||
|
||||
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
|
||||
|
||||
for (int i = 10; i >= 0; i--) {
|
||||
printf("Restarting in %d seconds...\n", i);
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
printf("Restarting now.\n");
|
||||
fflush(stdout);
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user