|
@@ -17,7 +17,7 @@
|
|
|
#define TAG "api"
|
|
|
#define BUF_LEN 1000
|
|
|
|
|
|
-
|
|
|
+static TaskHandle_t* alarm_task_handle = NULL;
|
|
|
|
|
|
static char* extract_wakeup(const char* uri) {
|
|
|
return strrchr(uri, '/') +1;
|
|
@@ -77,6 +77,12 @@ static uint8_t validate_time(int hour, int minute) {
|
|
|
return (hour >= 0 && hour < 24) && (minute >= 0 && minute < 60);
|
|
|
}
|
|
|
|
|
|
+static void notify_alarm_task() {
|
|
|
+ if (alarm_task_handle != NULL) {
|
|
|
+ xTaskNotify(*alarm_task_handle, 0, eNoAction);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
static esp_err_t wakeup_put_handler(httpd_req_t *req) {
|
|
|
char* wakeup_str = extract_wakeup(req->uri);
|
|
|
char buf[BUF_LEN];
|
|
@@ -126,6 +132,7 @@ static esp_err_t wakeup_put_handler(httpd_req_t *req) {
|
|
|
esp_err_t ret = write_wakeup_time_str(wakeup_str, minute_of_day);
|
|
|
if (ret == ESP_OK) {
|
|
|
httpd_resp_sendstr(req, "");
|
|
|
+ notify_alarm_task();
|
|
|
} else {
|
|
|
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Error while writing data");
|
|
|
}
|
|
@@ -165,19 +172,22 @@ static const httpd_uri_t wakeup_delete = {
|
|
|
};
|
|
|
|
|
|
|
|
|
-httpd_handle_t start_webserver() {
|
|
|
- httpd_handle_t server;
|
|
|
- httpd_config_t config = HTTPD_DEFAULT_CONFIG();
|
|
|
- config.lru_purge_enable = true;
|
|
|
- config.uri_match_fn = httpd_uri_match_wildcard;
|
|
|
+httpd_handle_t start_webserver(TaskHandle_t* task_handle) {
|
|
|
+ httpd_handle_t server;
|
|
|
+ httpd_config_t config = HTTPD_DEFAULT_CONFIG();
|
|
|
+ config.lru_purge_enable = true;
|
|
|
+ config.uri_match_fn = httpd_uri_match_wildcard;
|
|
|
+ if (task_handle != NULL) {
|
|
|
+ alarm_task_handle = task_handle;
|
|
|
+ }
|
|
|
|
|
|
ESP_LOGI(TAG, "Starting server on port: '%d'", config.server_port);
|
|
|
if (httpd_start(&server, &config) == ESP_OK) {
|
|
|
- ESP_LOGI(TAG, "Registering URI handlers");
|
|
|
- httpd_register_uri_handler(server, &wakeup_get);
|
|
|
- httpd_register_uri_handler(server, &wakeup_put);
|
|
|
+ ESP_LOGI(TAG, "Registering URI handlers");
|
|
|
+ httpd_register_uri_handler(server, &wakeup_get);
|
|
|
+ httpd_register_uri_handler(server, &wakeup_put);
|
|
|
httpd_register_uri_handler(server, &wakeup_delete);
|
|
|
- return server;
|
|
|
+ return server;
|
|
|
}
|
|
|
|
|
|
ESP_LOGI(TAG, "Error starting server!");
|
|
@@ -206,6 +216,6 @@ void connect_handler(void* arg, esp_event_base_t event_base,
|
|
|
httpd_handle_t* server = (httpd_handle_t*) arg;
|
|
|
if (*server == NULL) {
|
|
|
ESP_LOGI(TAG, "Starting webserver");
|
|
|
- *server = start_webserver();
|
|
|
+ *server = start_webserver(NULL);
|
|
|
}
|
|
|
}
|