/* Hello World Example This example code is in the Public Domain (or CC0 licensed, at your option.) Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ #include #include #include #include #include "sdkconfig.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_system.h" #include "esp_timer.h" #include "esp_log.h" #include "display.h" #include "text.h" #include "wlan.h" #include "https.h" #include "cJSON/cJSON.h" #include "esp_heap_caps.h" #ifdef CONFIG_IDF_TARGET_ESP32 #define CHIP_NAME "ESP32" #endif #ifdef CONFIG_IDF_TARGET_ESP32S2BETA #define CHIP_NAME "ESP32-S2 Beta" #endif const esp_timer_create_args_t periodic_timer_args = { .callback = &display_cycle, }; uint8_t buf_ok = 0; char bsvg_buf[33000]; static void https_request_task(void *pvparameters){ while(https_get_request_using_crt_bundle(bsvg_buf, sizeof(bsvg_buf)) != 0){ ESP_LOGE("bsvg", "Failed to get data from server. Retrying..."); vTaskDelay(1); } buf_ok = 1; vTaskDelete(NULL); } uint8_t json_ok = 0; cJSON *departureList; static void json_parse_task(void *pvparameters){ //uint16_t start_ptr = 0; //while(buf[start_ptr] != '{' && start_ptr < sizeof(buf)) // start_ptr++; char *start = strstr(bsvg_buf, "\"departureList\"") + 17; ESP_LOGI("bsvg", "start at %ld: \"%.10s\"", (uint32_t)start, start); departureList = cJSON_Parse(start); printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) ); json_ok = 1; vTaskDelete(NULL); } void app_main(void) { printf("Hello world!\n"); printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) ); ESP_LOGI("bsvg", "display init"); display_init(); printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) ); esp_timer_handle_t periodic_timer; ESP_ERROR_CHECK(esp_timer_create(&periodic_timer_args, &periodic_timer)); ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, 500)); put_line(fb, 1, "Moin", 1, 1); wlan_init(); put_line(fb, 2, "wifi", 1, 1); printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) ); xTaskCreate(&https_request_task, "https_get_task", 8192, NULL, 5, NULL); while (!buf_ok) { vTaskDelay(1); } printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) ); ESP_LOGI("bsvg", "got from https server:"); for(uint32_t i=0; itype); ESP_LOGI("bsvg", "child: %ld", (uint32_t)departureList->child); if(cJSON_IsArray(departureList)){ ESP_LOGI("bsvg", "is Array"); const cJSON *departure = NULL; cJSON_ArrayForEach(departure, departureList){ cJSON *number = cJSON_GetObjectItemCaseSensitive(cJSON_GetObjectItemCaseSensitive(departure, "servingLine"), "number");; if(number == NULL) ESP_LOGI("bsvg", "cant get number"); else if(cJSON_IsNumber(number)) ESP_LOGI("bsvg", "number (int): %d\n", number->valueint); else if(cJSON_IsString(number)) ESP_LOGI("bsvg", "number (str): %.3s\n", number->valuestring); else ESP_LOGI("bsvg", "cant get number value"); } } } for (;;) { vTaskDelay(1); } }