Skip to content

Commit

Permalink
Fix http_client freertos examples
Browse files Browse the repository at this point in the history
  • Loading branch information
peterharperuk committed Mar 12, 2024
1 parent cabe91c commit 1c0d38d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
5 changes: 3 additions & 2 deletions pico_w/wifi/freertos/http_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ target_include_directories(picow_freertos_http_client_nosys PRIVATE
target_link_libraries(picow_freertos_http_client_nosys
pico_cyw43_arch_lwip_threadsafe_background
pico_stdlib
pico_lwip_http_util
example_lwip_http_util
FreeRTOS-Kernel-Heap4 # FreeRTOS kernel and dynamic heap
)
pico_add_extra_outputs(picow_freertos_http_client_nosys)
Expand All @@ -27,6 +27,7 @@ target_compile_definitions(picow_freertos_http_client_sys PRIVATE
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
NO_SYS=0 # don't want NO_SYS (generally this would be in your lwipopts.h)
ALTCP_MBEDTLS_AUTHMODE=MBEDTLS_SSL_VERIFY_REQUIRED
CYW43_TASK_STACK_SIZE=2048
)
target_include_directories(picow_freertos_http_client_sys PRIVATE
${CMAKE_CURRENT_LIST_DIR}
Expand All @@ -36,7 +37,7 @@ target_include_directories(picow_freertos_http_client_sys PRIVATE
target_link_libraries(picow_freertos_http_client_sys
pico_cyw43_arch_lwip_sys_freertos
pico_stdlib
pico_lwip_http_util
example_lwip_http_util
FreeRTOS-Kernel-Heap4 # FreeRTOS kernel and dynamic heap
)
pico_add_extra_outputs(picow_freertos_http_client_sys)
Expand Down
33 changes: 6 additions & 27 deletions pico_w/wifi/freertos/http_client/picow_freertos_http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

#include "pico/cyw43_arch.h"
#include "pico/stdlib.h"
#include "pico/http_client_util.h"
#include "lwip/altcp_tls.h"

#include "lwip/netif.h"

#include "FreeRTOS.h"
#include "task.h"
#include "example_http_client_util.h"

#ifndef RUN_FREERTOS_ON_CORE
#define RUN_FREERTOS_ON_CORE 0
#endif

#define TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2UL )
#define BLINK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4UL )
#define TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2UL )
#define TEST_TASK_STACK_SIZE 1024

// Using this url as we know the root cert won't change for a long time
#define HOST "fw-download-alias1.raspberrypi.com"
Expand All @@ -46,31 +46,11 @@ PC3wSPqJ1byJKA6D+ZyjKR1aORbiDQVEpDNWRKiQ5QapLg8wbcED0MrRKQIxAKUT\n\
v8TJkb/8jC/oBVTmczKlPMkciN+uiaZSXahgYKyYhvKTatCTZb+geSIhc0w/2w==\n\
-----END CERTIFICATE-----\n"

void blink_task(__unused void *params) {
bool on = false;
printf("blink_task starts\n");
while (true) {
#if 0 && configNUM_CORES > 1
static int last_core_id;
if (portGET_CORE_ID() != last_core_id) {
last_core_id = portGET_CORE_ID();
printf("blinking now from core %d\n", last_core_id);
}
#endif
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, on);
on = !on;
vTaskDelay(200);
}
vTaskDelete(NULL);
}

void main_task(__unused void *params) {
if (cyw43_arch_init()) {
printf("failed to initialise\n");
return;
}
TaskHandle_t blinkHandle = NULL;
xTaskCreate(blink_task, "BlinkThread", configMINIMAL_STACK_SIZE, NULL, BLINK_TASK_PRIORITY, &blinkHandle);

cyw43_arch_enable_sta_mode();
printf("Connecting to Wi-Fi...\n");
Expand All @@ -82,27 +62,26 @@ void main_task(__unused void *params) {
}

static const uint8_t cert_ok[] = TLS_ROOT_CERT_OK;
EXAMPLE_HTTP_REQUEST_T req = {0};
static EXAMPLE_HTTP_REQUEST_T req = {0};
req.hostname = HOST;
req.url = URL_REQUEST;
req.headers_fn = http_client_header_print_fn;
req.recv_fn = http_client_receive_print_fn;
req.tls_config = altcp_tls_create_config_client(cert_ok, sizeof(cert_ok));

int pass = http_client_request_sync(cyw43_arch_async_context(), &req);
altcp_tls_free_config(req.tls_config);

if (pass != 0) {
panic("test failed");
}

vTaskDelete(blinkHandle);
cyw43_arch_deinit();
panic("Test passed");
}

void vLaunch( void) {
TaskHandle_t task;
xTaskCreate(main_task, "TestMainThread", 1024, NULL, TEST_TASK_PRIORITY, &task);
xTaskCreate(main_task, "TestMainThread", TEST_TASK_STACK_SIZE, NULL, TEST_TASK_PRIORITY, &task);

#if NO_SYS && configUSE_CORE_AFFINITY && configNUM_CORES > 1
// we must bind the main task to one core (well at least while the init is called)
Expand Down
3 changes: 3 additions & 0 deletions pico_w/wifi/http_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ pico_mirrored_target_link_libraries(example_lwip_http_util INTERFACE
pico_lwip_mbedtls
pico_mbedtls
)
target_include_directories(example_lwip_http_util INTERFACE
${CMAKE_CURRENT_LIST_DIR}
)

add_executable(picow_http_client
picow_http_client.c
Expand Down

0 comments on commit 1c0d38d

Please sign in to comment.