66
77#include "pico/cyw43_arch.h"
88#include "pico/stdlib.h"
9- #include "pico/http_client_util.h"
109#include "lwip/altcp_tls.h"
1110
1211#include "lwip/netif.h"
1312
1413#include "FreeRTOS.h"
1514#include "task.h"
15+ #include "example_http_client_util.h"
1616
1717#ifndef RUN_FREERTOS_ON_CORE
1818#define RUN_FREERTOS_ON_CORE 0
1919#endif
2020
21- #define TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2UL )
22- #define BLINK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4UL )
21+ #define TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2UL )
22+ #define TEST_TASK_STACK_SIZE 1024
2323
2424// Using this url as we know the root cert won't change for a long time
2525#define HOST "fw-download-alias1.raspberrypi.com"
@@ -46,31 +46,11 @@ PC3wSPqJ1byJKA6D+ZyjKR1aORbiDQVEpDNWRKiQ5QapLg8wbcED0MrRKQIxAKUT\n\
4646v8TJkb/8jC/oBVTmczKlPMkciN+uiaZSXahgYKyYhvKTatCTZb+geSIhc0w/2w==\n\
4747-----END CERTIFICATE-----\n"
4848
49- void blink_task (__unused void * params ) {
50- bool on = false;
51- printf ("blink_task starts\n" );
52- while (true) {
53- #if 0 && configNUM_CORES > 1
54- static int last_core_id ;
55- if (portGET_CORE_ID () != last_core_id ) {
56- last_core_id = portGET_CORE_ID ();
57- printf ("blinking now from core %d\n" , last_core_id );
58- }
59- #endif
60- cyw43_arch_gpio_put (CYW43_WL_GPIO_LED_PIN , on );
61- on = !on ;
62- vTaskDelay (200 );
63- }
64- vTaskDelete (NULL );
65- }
66-
6749void main_task (__unused void * params ) {
6850 if (cyw43_arch_init ()) {
6951 printf ("failed to initialise\n" );
7052 return ;
7153 }
72- TaskHandle_t blinkHandle = NULL ;
73- xTaskCreate (blink_task , "BlinkThread" , configMINIMAL_STACK_SIZE , NULL , BLINK_TASK_PRIORITY , & blinkHandle );
7454
7555 cyw43_arch_enable_sta_mode ();
7656 printf ("Connecting to Wi-Fi...\n" );
@@ -82,27 +62,26 @@ void main_task(__unused void *params) {
8262 }
8363
8464 static const uint8_t cert_ok [] = TLS_ROOT_CERT_OK ;
85- EXAMPLE_HTTP_REQUEST_T req = {0 };
65+ static EXAMPLE_HTTP_REQUEST_T req = {0 };
8666 req .hostname = HOST ;
8767 req .url = URL_REQUEST ;
8868 req .headers_fn = http_client_header_print_fn ;
8969 req .recv_fn = http_client_receive_print_fn ;
9070 req .tls_config = altcp_tls_create_config_client (cert_ok , sizeof (cert_ok ));
71+
9172 int pass = http_client_request_sync (cyw43_arch_async_context (), & req );
9273 altcp_tls_free_config (req .tls_config );
93-
9474 if (pass != 0 ) {
9575 panic ("test failed" );
9676 }
9777
98- vTaskDelete (blinkHandle );
9978 cyw43_arch_deinit ();
10079 panic ("Test passed" );
10180}
10281
10382void vLaunch ( void ) {
10483 TaskHandle_t task ;
105- xTaskCreate (main_task , "TestMainThread" , 1024 , NULL , TEST_TASK_PRIORITY , & task );
84+ xTaskCreate (main_task , "TestMainThread" , TEST_TASK_STACK_SIZE , NULL , TEST_TASK_PRIORITY , & task );
10685
10786#if NO_SYS && configUSE_CORE_AFFINITY && configNUM_CORES > 1
10887 // we must bind the main task to one core (well at least while the init is called)
0 commit comments