|
|
|
|
@ -22,9 +22,10 @@
|
|
|
|
|
#include "wlan.h"
|
|
|
|
|
#include "https.h"
|
|
|
|
|
|
|
|
|
|
#include "cJSON/cJSON.h"
|
|
|
|
|
#include "esp_heap_caps.h"
|
|
|
|
|
|
|
|
|
|
#include "lwjson/lwjson.h"
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_IDF_TARGET_ESP32
|
|
|
|
|
#define CHIP_NAME "ESP32"
|
|
|
|
|
#endif
|
|
|
|
|
@ -39,7 +40,7 @@ const esp_timer_create_args_t periodic_timer_args = {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
uint8_t buf_ok = 0;
|
|
|
|
|
char bsvg_buf[33000];
|
|
|
|
|
char bsvg_buf[40000];
|
|
|
|
|
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...");
|
|
|
|
|
@ -49,15 +50,47 @@ static void https_request_task(void *pvparameters){
|
|
|
|
|
vTaskDelete(NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//static lwjson_token_t tokens[1100];
|
|
|
|
|
//static lwjson_t lwjson;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
//char *start = strstr(bsvg_buf, "{");
|
|
|
|
|
ESP_LOGI("bsvg", "start at %ld: \"%.10s\"", (uint32_t)start, start);
|
|
|
|
|
departureList = cJSON_Parse(start);
|
|
|
|
|
//departureList = cJSON_Parse(start);
|
|
|
|
|
|
|
|
|
|
char *item = start;
|
|
|
|
|
while((item = strstr(item+1, "{ \"stopID\":")) != 0){
|
|
|
|
|
char *symbol = strstr(item, "\"symbol\"");
|
|
|
|
|
char *direction = strstr(item, "\"direction\"");
|
|
|
|
|
char *countdown = strstr(item, "\"countdown\"");
|
|
|
|
|
if(symbol && direction && countdown)
|
|
|
|
|
printf("%.15s\t%.30s\t%.15s\n", symbol, direction, countdown);
|
|
|
|
|
else
|
|
|
|
|
printf("cant find symbol\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//lwjson_init(&lwjson, tokens, LWJSON_ARRAYSIZE(tokens));
|
|
|
|
|
//if (lwjson_parse(&lwjson, start) == lwjsonOK) {
|
|
|
|
|
// const lwjson_token_t* t;
|
|
|
|
|
// printf("JSON parsed..\r\n");
|
|
|
|
|
|
|
|
|
|
// /* Find custom key in JSON */
|
|
|
|
|
// if ((t = lwjson_find(&lwjson, "stopID")) != NULL) {
|
|
|
|
|
// printf("Key found with data type: %d\r\n", (int)t->type);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* Call this when not used anymore */
|
|
|
|
|
// lwjson_free(&lwjson);
|
|
|
|
|
//}
|
|
|
|
|
//else{
|
|
|
|
|
// ESP_LOGI("bsvg", "parse fail");
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) );
|
|
|
|
|
|
|
|
|
|
json_ok = 1;
|
|
|
|
|
@ -108,41 +141,41 @@ void app_main(void)
|
|
|
|
|
}
|
|
|
|
|
ESP_LOGI("bsvg", "Done");
|
|
|
|
|
|
|
|
|
|
if (departureList == NULL)
|
|
|
|
|
{
|
|
|
|
|
ESP_LOGI("bsvg", "did not get list");
|
|
|
|
|
const char *error_ptr = cJSON_GetErrorPtr();
|
|
|
|
|
heap_caps_print_heap_info(MALLOC_CAP_DEFAULT);
|
|
|
|
|
if (error_ptr != NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "Error at %ld: %.10s\n", (uint32_t)error_ptr-(uint32_t)bsvg_buf, error_ptr);
|
|
|
|
|
fprintf(stderr, "%.100s%.100s\n", error_ptr-100, error_ptr);
|
|
|
|
|
fprintf(stderr, " ^\n");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fprintf(stderr, "did not get err ptr\n");
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
ESP_LOGI("bsvg", "got list");
|
|
|
|
|
printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) );
|
|
|
|
|
ESP_LOGI("bsvg", "type: %d", departureList->type);
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//if (departureList == NULL)
|
|
|
|
|
//{
|
|
|
|
|
// ESP_LOGI("bsvg", "did not get list");
|
|
|
|
|
// const char *error_ptr = cJSON_GetErrorPtr();
|
|
|
|
|
// heap_caps_print_heap_info(MALLOC_CAP_DEFAULT);
|
|
|
|
|
// if (error_ptr != NULL)
|
|
|
|
|
// {
|
|
|
|
|
// fprintf(stderr, "Error at %ld: %.10s\n", (uint32_t)error_ptr-(uint32_t)bsvg_buf, error_ptr);
|
|
|
|
|
// fprintf(stderr, "%.100s%.100s\n", error_ptr-100, error_ptr);
|
|
|
|
|
// fprintf(stderr, " ^\n");
|
|
|
|
|
// }
|
|
|
|
|
// else {
|
|
|
|
|
// fprintf(stderr, "did not get err ptr\n");
|
|
|
|
|
// }
|
|
|
|
|
//}else{
|
|
|
|
|
// ESP_LOGI("bsvg", "got list");
|
|
|
|
|
// printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) );
|
|
|
|
|
// ESP_LOGI("bsvg", "type: %d", departureList->type);
|
|
|
|
|
// 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 (;;) {
|
|
|
|
|
|