remove root handler

This commit is contained in:
2020-09-13 21:53:21 -05:00
parent dbf96f7a62
commit 2339d11d77

View File

@@ -13,8 +13,6 @@
static const char *TAG = "BME280";
/* An HTTP GET handler */
static esp_err_t root_get_handler(httpd_req_t *req);
static esp_err_t bme280_readout_handler(httpd_req_t *req);
static httpd_handle_t start_webserver(void);
static void stop_webserver(httpd_handle_t server);
@@ -23,12 +21,6 @@ static void disconnect_handler(void* arg, esp_event_base_t event_base,
static void connect_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data);
static const httpd_uri_t root = {
.uri = "/",
.method = HTTP_GET,
.handler = root_get_handler
};
static const httpd_uri_t bme280_uri = {
.uri = "/bme280",
.method = HTTP_GET,
@@ -73,11 +65,10 @@ void app_main(void)
int8_t ret = init_bme280();
printf("BME init result %d\n", ret);
while(1) {
// take BME280 readings.
lastReadoutStatus = bme280_readout();
vTaskDelay(1600/portTICK_PERIOD_MS);
}
/* while(1) { */
/* lastReadoutStatus = bme280_readout(); */
/* vTaskDelay(1600/portTICK_PERIOD_MS); */
/* } */
}
struct bme280_data comp_data;
@@ -97,31 +88,23 @@ int8_t bme280_readout(){
return ret;
}
static esp_err_t root_get_handler(httpd_req_t *req)
{
httpd_resp_set_type(req, "text/html");
httpd_resp_send(req, "<h1>Hello Secure World!</h1>", -1); // -1 = use strlen()
return ESP_OK;
}
static esp_err_t bme280_readout_handler(httpd_req_t *req)
{
char buffer[128];
httpd_resp_set_type(req, "text/json");
int8_t ret = bme280_readout();
if (ret == 0) {
snprintf(buffer, sizeof(buffer), "{\"status\": \"ok\", \"sensor\": \"bme280\", \"temp\": %.1f, \"humidity\": %.1f, \"pressure\": %0.1f}",
comp_data.temperature, comp_data.humidity, comp_data.pressure/100.);
ESP_LOGI(TAG, "%s", buffer);
httpd_resp_send(req, buffer, -1);
}
else {
ESP_LOGE(TAG, "bme280_readout failed");
httpd_resp_send(req, "{\"status\": failed, \"error\": \"could not read from sensor\"}", -1);
}
char buffer[128];
httpd_resp_set_type(req, "text/json");
int8_t ret = bme280_readout();
if (ret == 0) {
snprintf(buffer, sizeof(buffer), "{\"status\": \"ok\", \"sensor\": \"bme280\", \"temp\": %.1f, \"humidity\": %.1f, \"pressure\": %0.1f}",
comp_data.temperature, comp_data.humidity, comp_data.pressure/100.);
ESP_LOGI(TAG, "%s", buffer);
httpd_resp_send(req, buffer, -1);
}
else {
ESP_LOGE(TAG, "bme280_readout failed");
httpd_resp_send(req, "{\"status\": failed, \"error\": \"could not read from sensor\"}", -1);
}
return ESP_OK;
return ESP_OK;
}
static httpd_handle_t start_webserver(void)
@@ -151,14 +134,12 @@ static httpd_handle_t start_webserver(void)
// Set URI handlers
ESP_LOGI(TAG, "Registering URI handlers");
httpd_register_uri_handler(server, &root);
httpd_register_uri_handler(server, &bme280_uri);
return server;
}
static void stop_webserver(httpd_handle_t server)
{
// Stop the httpd server
httpd_ssl_stop(server);
}