static const char *TAG = "blinky"; #include #include #include #include #include #include "wifi.hpp" #include "http_serv.hpp" #include "ota.hpp" #include "mqtt.hpp" // mDNS / NetBIOS #include #include static void start_mdns_service(const char *hostname) { // Initialize mDNS service ESP_ERROR_CHECK(mdns_init()); // Set hostname mdns_hostname_set(hostname); // Set default instance mdns_instance_name_set("Blinky Lights"); // NetBIOS too netbiosns_init(); netbiosns_set_name(hostname); } // Dummy FS static void start_filesystem() { ESP_LOGI(TAG, "Initializing filesystem"); esp_vfs_spiffs_conf_t conf = { .base_path = "/spiffs", .partition_label = NULL, .max_files = 5, .format_if_mount_failed = true }; // Use settings defined above to initialize and mount SPIFFS filesystem. // Note: esp_vfs_spiffs_register is an all-in-one convenience function. ESP_ERROR_CHECK(esp_vfs_spiffs_register(&conf)); } #include #include #include #include static void log_dir(const std::string &path) { struct stat st; int err = stat(path.c_str(), &st); if (err < 0) { ESP_LOGE(TAG, "%s %d", path.c_str(), errno); } else { ESP_LOGI(TAG, "%s %d", path.c_str(), st.st_size); } DIR *dir; if ((dir = opendir(path.c_str())) == NULL) { //ESP_LOGE(TAG, "Failed to open %s", path.c_str()); return; } struct dirent *de; while ((de = readdir(dir)) != NULL) { log_dir(path + "/" + de->d_name); } closedir(dir); } // Entry Point extern "C" void app_main(void) { // Initialize NVS for WiFi Data esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { ESP_ERROR_CHECK(nvs_flash_erase()); ret = nvs_flash_init(); } ESP_ERROR_CHECK(ret); // WiFi config_wifi(); // mDNS start_mdns_service("blinky-jr"); // HTTP Server httpd_handle_t server = start_webserver(); // OTA Server start_ota_serv(server); // Dummy Filesystem start_filesystem(); log_dir("/spiffs"); // TODO: Something useful esp_mqtt_client_handle_t client = start_mqtt_client(NULL, NULL, NULL); esp_mqtt_client_subscribe(client, "#", 0); // Spin }