Starting to add httpd server

parent 9f31120e
Subproject commit baf849bf66e6dc56b9eb92c7a0b28d6a7bf6e3bb Subproject commit 202ecff281b8cafa95f52a61c2a6cb245a04dd30
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "lwip/err.h" #include "lwip/err.h"
#include "lwip/sys.h" #include "lwip/sys.h"
#include "https_server.h"
/* You can set Wifi configuration via /* You can set Wifi configuration via
'make menuconfig'. 'make menuconfig'.
...@@ -32,6 +34,23 @@ const int WIFI_CONNECTED_BIT = BIT0; ...@@ -32,6 +34,23 @@ const int WIFI_CONNECTED_BIT = BIT0;
static const char *TAG = "Nexboot"; static const char *TAG = "Nexboot";
http_server_t server;
esp_err_t httpd_start(void)
{
ESP_LOGI(TAG, "Starting HTTPD...");
#if HTTPS_SERVER
http_server_options_t http_options = HTTPS_SERVER_OPTIONS_DEFAULT();
#else
http_server_options_t http_options = HTTP_SERVER_OPTIONS_DEFAULT();
#endif
esp_err_t res;
ESP_ERROR_CHECK( res = http_server_start(&http_options, &server) );
ESP_LOGI(TAG, "HTTPD Started");
return res;
}
static esp_err_t event_handler(void *ctx, system_event_t *event) static esp_err_t event_handler(void *ctx, system_event_t *event)
{ {
switch(event->event_id) { switch(event->event_id) {
...@@ -42,6 +61,7 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) ...@@ -42,6 +61,7 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
ESP_LOGI(TAG, "got ip:%s", ESP_LOGI(TAG, "got ip:%s",
ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip)); ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
xEventGroupSetBits(wifi_event_group, WIFI_CONNECTED_BIT); xEventGroupSetBits(wifi_event_group, WIFI_CONNECTED_BIT);
ESP_ERROR_CHECK(httpd_start());
break; break;
case SYSTEM_EVENT_AP_STACONNECTED: case SYSTEM_EVENT_AP_STACONNECTED:
ESP_LOGI(TAG, "station:"MACSTR" join, AID=%d", ESP_LOGI(TAG, "station:"MACSTR" join, AID=%d",
...@@ -54,6 +74,9 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) ...@@ -54,6 +74,9 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
event->event_info.sta_disconnected.aid); event->event_info.sta_disconnected.aid);
break; break;
case SYSTEM_EVENT_STA_DISCONNECTED: case SYSTEM_EVENT_STA_DISCONNECTED:
ESP_LOGI(TAG, "Stopping HTTPD");
ESP_ERROR_CHECK(http_server_stop(server));
ESP_LOGI(TAG, "HTTPD Stopped");
esp_wifi_connect(); esp_wifi_connect();
xEventGroupClearBits(wifi_event_group, WIFI_CONNECTED_BIT); xEventGroupClearBits(wifi_event_group, WIFI_CONNECTED_BIT);
break; break;
...@@ -92,6 +115,7 @@ void wifi_init_softap() ...@@ -92,6 +115,7 @@ void wifi_init_softap()
ESP_LOGI(TAG, "wifi_init_softap finished.SSID:%s password:%s", ESP_LOGI(TAG, "wifi_init_softap finished.SSID:%s password:%s",
ESP_WIFI_SSID, ESP_WIFI_PASS); ESP_WIFI_SSID, ESP_WIFI_PASS);
ESP_ERROR_CHECK(httpd_start());
} }
#else // if ESP_WIFI_MODE_AP #else // if ESP_WIFI_MODE_AP
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment