manual parsing kind of works
This commit is contained in:
44
main/main.c
44
main/main.c
@@ -10,6 +10,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/types.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
@@ -50,8 +51,19 @@ static void https_request_task(void *pvparameters){
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
//static lwjson_token_t tokens[1100];
|
||||
//static lwjson_t lwjson;
|
||||
void get_json_string(char* buf, char* name, char* dest){
|
||||
char* element = strstr(buf, name);
|
||||
char *ptr= element;
|
||||
while(*ptr != ':') ptr++;
|
||||
while(*ptr != '"') ptr++;
|
||||
ptr++;
|
||||
|
||||
char *end=ptr;
|
||||
while(*end != '"') end++;
|
||||
|
||||
strncpy(dest, ptr, end-ptr);
|
||||
dest[end-ptr]=0;
|
||||
}
|
||||
|
||||
uint8_t json_ok = 0;
|
||||
static void json_parse_task(void *pvparameters){
|
||||
@@ -63,15 +75,27 @@ static void json_parse_task(void *pvparameters){
|
||||
ESP_LOGI("bsvg", "start at %ld: \"%.10s\"", (uint32_t)start, start);
|
||||
//departureList = cJSON_Parse(start);
|
||||
|
||||
uint8_t line = 0;
|
||||
char *item = start;
|
||||
char txt[5][50];
|
||||
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");
|
||||
char symbol[10];
|
||||
get_json_string(item, "symbol", symbol);
|
||||
|
||||
char direction[50];
|
||||
get_json_string(item, "direction", direction);
|
||||
|
||||
char countdown[10] ;
|
||||
get_json_string(item, "countdown", countdown);
|
||||
|
||||
if(line < 6){
|
||||
sprintf(txt[line], "%.3s %.15s %.3s", symbol, direction, countdown);
|
||||
printf("line = %d\n", line);
|
||||
printf("text = %s\n", txt[line]);
|
||||
put_line(fb, line, txt[line], 1, 1);
|
||||
//printf("\n");
|
||||
}
|
||||
line++;
|
||||
}
|
||||
|
||||
//lwjson_init(&lwjson, tokens, LWJSON_ARRAYSIZE(tokens));
|
||||
@@ -91,8 +115,6 @@ static void json_parse_task(void *pvparameters){
|
||||
// ESP_LOGI("bsvg", "parse fail");
|
||||
//}
|
||||
|
||||
printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) );
|
||||
|
||||
json_ok = 1;
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user