diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 0a4bebd..5eb06c3 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,3 +1,3 @@ -idf_component_register(SRCS "main.c" "font.c" "display.c" "text.c" "wlan.c" "http.c" - REQUIRES esp_driver_gpio esp_wifi nvs_flash esp_timer +idf_component_register(SRCS "main.c" "font.c" "display.c" "text.c" "wlan.c" "https.c" + REQUIRES esp_driver_gpio esp_wifi nvs_flash esp_timer esp-tls INCLUDE_DIRS "") diff --git a/main/http.h b/main/http.h new file mode 100644 index 0000000..77130eb --- /dev/null +++ b/main/http.h @@ -0,0 +1,10 @@ +#include "esp_system.h" + +/* Constants that aren't configurable in menuconfig */ +#define WEB_SERVER "mustbehax.de" +#define WEB_PORT "80" +#define WEB_PATH "/test" + +#define RCV_BUFSIZE 8000 + +esp_err_t http_request(char* buf); diff --git a/main/https.c b/main/https.c index 0288827..0cd81c1 100644 --- a/main/https.c +++ b/main/https.c @@ -7,9 +7,18 @@ static const char *TAG = "https"; +#define WEB_SERVER "bsvg.efa.de" +#define WEB_PORT "443" +#define WEB_URL "/bsvagstd/XML_DM_REQUEST?outputFormat=JSON&stateless=1&locationServerActive=1&type_dm=stop&name_dm=\"Freiastr,Braunschweig\"&mode=direct&ptOptionsActive=1&useRealtime=1" + +static const char HOWSMYSSL_REQUEST[] = "GET " WEB_URL " HTTP/1.1\r\n" + "Host: "WEB_SERVER"\r\n" + "User-Agent: esp-idf/1.0 esp32\r\n" + "\r\n"; + static void https_get_request(esp_tls_cfg_t cfg, const char *WEB_SERVER_URL, const char *REQUEST) { - char buf[512]; + char buf[47000]; int ret, len; esp_tls_t *tls = esp_tls_init(); @@ -89,20 +98,11 @@ exit: } } -#define WEB_SERVER "www.howsmyssl.com" -#define WEB_PORT "443" -#define WEB_URL "https://www.howsmyssl.com/a/check" - -static const char HOWSMYSSL_REQUEST[] = "GET " WEB_URL " HTTP/1.1\r\n" - "Host: "WEB_SERVER"\r\n" - "User-Agent: esp-idf/1.0 esp32\r\n" - "\r\n"; - void https_get_request_using_crt_bundle(void) { ESP_LOGI(TAG, "https_request using crt bundle"); esp_tls_cfg_t cfg = { .crt_bundle_attach = esp_crt_bundle_attach, }; - https_get_request(cfg, WEB_URL, HOWSMYSSL_REQUEST); + https_get_request(cfg, "https://"WEB_SERVER""WEB_URL, HOWSMYSSL_REQUEST); } diff --git a/main/main.c b/main/main.c index d3e60d2..b833b53 100644 --- a/main/main.c +++ b/main/main.c @@ -18,7 +18,7 @@ #include "display.h" #include "text.h" #include "wlan.h" -#include "http.h" +#include "https.h" #ifdef CONFIG_IDF_TARGET_ESP32 #define CHIP_NAME "ESP32" @@ -47,15 +47,16 @@ void app_main(void) put_line(fb, 2, "wifi", 1, 1); - //xTaskCreate(&http_get_task, "http_get_task", 4096, NULL, 5, NULL); - char buf[RCV_BUFSIZE]; - bzero(buf, RCV_BUFSIZE); - http_request(buf); - for(uint32_t i=0; i