First implementation
This commit is contained in:
24
.gitmodules
vendored
Normal file
24
.gitmodules
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
[submodule "esp-idf"]
|
||||||
|
path = esp-idf
|
||||||
|
url = git@github.com:0xFEEDC0DE64/esp-idf.git
|
||||||
|
[submodule "components/cpputils"]
|
||||||
|
path = components/cpputils
|
||||||
|
url = git@github.com:0xFEEDC0DE64/cpputils.git
|
||||||
|
[submodule "components/arduino-esp32"]
|
||||||
|
path = components/arduino-esp32
|
||||||
|
url = git@github.com:0xFEEDC0DE64/arduino-esp32.git
|
||||||
|
[submodule "components/espchrono"]
|
||||||
|
path = components/espchrono
|
||||||
|
url = git@github.com:0xFEEDC0DE64/espchrono.git
|
||||||
|
[submodule "components/espcpputils"]
|
||||||
|
path = components/espcpputils
|
||||||
|
url = git@github.com:0xFEEDC0DE64/espcpputils.git
|
||||||
|
[submodule "components/expected"]
|
||||||
|
path = components/expected
|
||||||
|
url = git@github.com:0xFEEDC0DE64/expected.git
|
||||||
|
[submodule "components/espwifistack"]
|
||||||
|
path = components/espwifistack
|
||||||
|
url = git@github.com:0xFEEDC0DE64/espwifistack.git
|
||||||
|
[submodule "components/date"]
|
||||||
|
path = components/date
|
||||||
|
url = git@github.com:0xFEEDC0DE64/date.git
|
8
CMakeLists.txt
Normal file
8
CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.16.3)
|
||||||
|
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
project(deckenlampe)
|
1
components/arduino-esp32
Submodule
1
components/arduino-esp32
Submodule
Submodule components/arduino-esp32 added at ff9ec961c1
1
components/cpputils
Submodule
1
components/cpputils
Submodule
Submodule components/cpputils added at a33ed96bc5
1
components/date
Submodule
1
components/date
Submodule
Submodule components/date added at b1a75847d5
1
components/espchrono
Submodule
1
components/espchrono
Submodule
Submodule components/espchrono added at 7f8a185678
1
components/espcpputils
Submodule
1
components/espcpputils
Submodule
Submodule components/espcpputils added at a504262f39
1
components/espwifistack
Submodule
1
components/espwifistack
Submodule
Submodule components/espwifistack added at 4d0efeea96
1
components/expected
Submodule
1
components/expected
Submodule
Submodule components/expected added at 30ee4ea505
1
esp-idf
Submodule
1
esp-idf
Submodule
Submodule esp-idf added at 9e9abdf483
34
main/CMakeLists.txt
Normal file
34
main/CMakeLists.txt
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
idf_build_get_property(project_dir PROJECT_DIR)
|
||||||
|
message(STATUS "The project dir is: ${project_dir}")
|
||||||
|
|
||||||
|
set(headers
|
||||||
|
)
|
||||||
|
|
||||||
|
set(sources
|
||||||
|
main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(dependencies
|
||||||
|
freertos nvs_flash esp_http_server esp_https_ota mdns app_update esp_system mqtt
|
||||||
|
arduino-esp32 cpputils espchrono espcpputils espwifistack expected
|
||||||
|
)
|
||||||
|
|
||||||
|
idf_component_register(
|
||||||
|
SRCS
|
||||||
|
${headers}
|
||||||
|
${sources}
|
||||||
|
INCLUDE_DIRS
|
||||||
|
.
|
||||||
|
REQUIRES
|
||||||
|
${dependencies}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_options(${COMPONENT_TARGET}
|
||||||
|
PRIVATE
|
||||||
|
-fstack-reuse=all
|
||||||
|
-fstack-protector-all
|
||||||
|
-Wno-unused-function
|
||||||
|
-Wno-deprecated-declarations
|
||||||
|
-Wno-missing-field-initializers
|
||||||
|
-Wno-parentheses
|
||||||
|
)
|
145
main/main.cpp
Normal file
145
main/main.cpp
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
|
// system includes
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
// esp-idf includes
|
||||||
|
#include <esp_log.h>
|
||||||
|
#include <freertos/FreeRTOS.h>
|
||||||
|
#if defined(CONFIG_ESP_TASK_WDT_PANIC) || defined(CONFIG_ESP_TASK_WDT)
|
||||||
|
#include <freertos/task.h>
|
||||||
|
#include <esp_task_wdt.h>
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_APP_ROLLBACK_ENABLE
|
||||||
|
#include <esp_ota_ops.h>
|
||||||
|
#endif
|
||||||
|
#include <nvs_flash.h>
|
||||||
|
|
||||||
|
// Arduino includes
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "espwifistack.h"
|
||||||
|
#include "tickchrono.h"
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr const char * const TAG = "MAIN";
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
extern "C" void app_main()
|
||||||
|
{
|
||||||
|
#if defined(CONFIG_ESP_TASK_WDT_PANIC) || defined(CONFIG_ESP_TASK_WDT)
|
||||||
|
{
|
||||||
|
const auto taskHandle = xTaskGetCurrentTaskHandle();
|
||||||
|
if (!taskHandle)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "could not get handle to current main task!");
|
||||||
|
}
|
||||||
|
else if (const auto result = esp_task_wdt_add(taskHandle); result != ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "could not add main task to watchdog: %s", esp_err_to_name(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_APP_ROLLBACK_ENABLE
|
||||||
|
esp_ota_img_states_t ota_state;
|
||||||
|
if (const esp_partition_t * const running = esp_ota_get_running_partition())
|
||||||
|
{
|
||||||
|
if (const auto result = esp_ota_get_state_partition(running, &ota_state); result == ESP_ERR_NOT_FOUND)
|
||||||
|
ota_state = ESP_OTA_IMG_VALID;
|
||||||
|
else if (result != ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "esp_ota_get_state_partition() failed with %s", esp_err_to_name(result));
|
||||||
|
ota_state = ESP_OTA_IMG_UNDEFINED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "esp_ota_get_running_partition() returned nullptr");
|
||||||
|
ota_state = ESP_OTA_IMG_UNDEFINED;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto result = nvs_flash_init();
|
||||||
|
ESP_LOG_LEVEL_LOCAL((result == ESP_OK ? ESP_LOG_INFO : ESP_LOG_ERROR), TAG, "nvs_flash_init(): %s", esp_err_to_name(result));
|
||||||
|
//if (result != ESP_OK)
|
||||||
|
// return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
nvs_handle_t handle;
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto result = nvs_open("deckenlampe", NVS_READWRITE, &handle);
|
||||||
|
ESP_LOG_LEVEL_LOCAL((result == ESP_OK ? ESP_LOG_INFO : ESP_LOG_ERROR), TAG, "nvs_open(): %s", esp_err_to_name(result));
|
||||||
|
//if (result != ESP_OK)
|
||||||
|
// return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
wifi_stack::config wifiConfig {
|
||||||
|
.wifiEnabled = true,
|
||||||
|
.hostname = "deckenlampe1",
|
||||||
|
.wifis = std::array<wifi_stack::wifi_entry, 10> {
|
||||||
|
wifi_stack::wifi_entry { .ssid = "McDonalds Free WiFi", .key = "Passwort_123" },
|
||||||
|
wifi_stack::wifi_entry { .ssid = {}, .key = {} },
|
||||||
|
wifi_stack::wifi_entry { .ssid = {}, .key = {} },
|
||||||
|
wifi_stack::wifi_entry { .ssid = {}, .key = {} },
|
||||||
|
wifi_stack::wifi_entry { .ssid = {}, .key = {} },
|
||||||
|
wifi_stack::wifi_entry { .ssid = {}, .key = {} },
|
||||||
|
wifi_stack::wifi_entry { .ssid = {}, .key = {} },
|
||||||
|
wifi_stack::wifi_entry { .ssid = {}, .key = {} },
|
||||||
|
wifi_stack::wifi_entry { .ssid = {}, .key = {} },
|
||||||
|
wifi_stack::wifi_entry { .ssid = {}, .key = {} }
|
||||||
|
},
|
||||||
|
.sta_ip = {
|
||||||
|
.dhcpEnabled = true,
|
||||||
|
// .staticIp = {},
|
||||||
|
// .staticGateway = {},
|
||||||
|
// .staticSubnet = {},
|
||||||
|
// .staticDns1 = {},
|
||||||
|
// .staticDns2 = {}
|
||||||
|
},
|
||||||
|
.ap = {
|
||||||
|
{
|
||||||
|
.ssid = "deckenlampe1",
|
||||||
|
.key = "Passwort_123"
|
||||||
|
},
|
||||||
|
.channel = 1,
|
||||||
|
.authmode = WIFI_AUTH_WPA2_PSK,
|
||||||
|
.ssid_hidden = false,
|
||||||
|
.max_connection = 4,
|
||||||
|
.beacon_interval = 100,
|
||||||
|
.ip{10, 128, 250, 181},
|
||||||
|
.subnet{255, 255, 255, 0}
|
||||||
|
},
|
||||||
|
.min_rssi = -90
|
||||||
|
};
|
||||||
|
|
||||||
|
wifi_stack::init(wifiConfig);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
wifi_stack::update(wifiConfig);
|
||||||
|
|
||||||
|
#if defined(CONFIG_ESP_TASK_WDT_PANIC) || defined(CONFIG_ESP_TASK_WDT)
|
||||||
|
if (const auto result = esp_task_wdt_reset(); result != ESP_OK)
|
||||||
|
ESP_LOGE(TAG, "esp_task_wdt_reset() failed with %s", esp_err_to_name(result));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_APP_ROLLBACK_ENABLE
|
||||||
|
if (ota_state == ESP_OTA_IMG_PENDING_VERIFY)
|
||||||
|
{
|
||||||
|
const auto result = esp_ota_mark_app_valid_cancel_rollback();
|
||||||
|
ESP_LOG_LEVEL_LOCAL((result == ESP_OK ? ESP_LOG_INFO : ESP_LOG_ERROR), TAG, "esp_ota_mark_app_valid_cancel_rollback() returned: %s", esp_err_to_name(result));
|
||||||
|
ota_state = ESP_OTA_IMG_VALID;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
vPortYield();
|
||||||
|
|
||||||
|
vTaskDelay(std::chrono::ceil<espcpputils::ticks>(100ms).count());
|
||||||
|
}
|
||||||
|
}
|
6
partitions.csv
Normal file
6
partitions.csv
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# Name, Type, SubType, Offset, Size, Flags
|
||||||
|
nvs, data, nvs, 0x9000, 0x5000,
|
||||||
|
otadata, data, ota, 0xe000, 0x2000,
|
||||||
|
app0, app, ota_0, 0x10000, 0x1E0000,
|
||||||
|
app1, app, ota_1, 0x1F0000, 0x1E0000,
|
||||||
|
spiffs, data, spiffs, 0x3D0000, 0x30000,
|
|
Reference in New Issue
Block a user