This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP-EXP432E401Y: Maximum JSON-Object Array elements

Part Number: MSP-EXP432E401Y

Hello TI-Community,

I am trying to write an integer array into a JSON object (see Code: Data->U and Data->Y).

I am using the TI Utilities JSON API. (https://software-dl.ti.com/simplelink/esd/simplelink_msp432e4_sdk/3.10.00.11/docs/tiutils/html/group__ti__utils__json__JSON.html#ga455cfaada898bfb72f7ab01f4dbfc3be)

It works for small arrays:

#define SYS_IDENT_TEMPLATE              \
"{"                                     \
  "\"Device\": string,"                 \
  "\"Data\": {"                         \
    "\"U\": [int32],"                   \
    "\"Y\": [int32],"                   \
  "}"                                   \
"}"

#define DEFAULT_JSONBUF                     \
"{"                                         \
  "\"Device\": \"IoTDeviceID\","            \
  "\"Data\": {"                             \
    "\"U\": [],"                            \
    "\"Y\": [],"                            \
  "}"                                       \
"}"

When I add elements to the JSON-Array like this:

int j;
for (j = 0; j < (&my_array)->used; j= j+1 ) {
    int temp = (&my_array)->value[j];
    sprintf(keyBuf, "\"Data\".\"U\".[%d]", j);
    retVal = Json_setValue(hObject, keyBuf, &temp, sizeof(temp));
    if (retVal != 0) {
        Display_printf(display, 0, 0, "Error setting the Data vector U value");
        while (1);
    }
}

it works unitl array element 255.

Is it possible to add more array elements (I need 1000)?

If it`s possible could you show me the problem?

(Note: In Json_createObject is the maxObjectSize set to 8196 => thats more than enough, thats not the problem)


With best regards

Patrick

  • Part Number: MSP-EXP432E401Y

    Hello,

    I am trying to write an integer array into a JSON object (see Data->U and Data->Y).

    However, the examples included in the documentation and the sample programs only show the use of the "Json_setValue(...)" method for simple integer values.

    The relevant code of my previous program:

    #define SYS_IDENT_TEMPLATE              \
    "{"                                     \
      "\"Device\": string,"                 \
      "\"SerialNumber\": string,"           \
      "\"TypeDesignation\": string,"        \
      "\"Location\": string,"               \
      "\"ProcessParams\": {"                \
        "\"NonDegree\": int32,"             \
        "\"MaxLag\": int32,"                \
        "\"Model\": string,"                \
      "},"                                  \
      "\"ControlParams\": {"                \
        "\"Kp\": string,"                   \
        "\"Ki\": string,"                   \
        "\"Kd\": string,"                   \
        "\"Alpha\": string,"                \
        "\"Ts\": string,"                   \
      "},"                                  \
      "\"MechanicalLimitations\": {"        \
        "\"LimitUMin\": int32,"             \
        "\"LimitUMax\": int32,"             \
        "\"LimitYMin\": int32,"             \
        "\"LimitYMax\": int32,"             \
      "},"                                  \
      "\"Data\": {"                         \
        "\"U\": [int32],"                   \
        "\"Y\": [int32],"                   \
      "}"                                   \
    "}"
    
    #define DEFAULT_JSONBUF                     \
    "{"                                         \
      "\"Device\": \"IoTDeviceID\","            \
      "\"SerialNumber\": \"SN=XXXX\","          \
      "\"TypeDesignation\": \"Default\","       \
      "\"Location\": \"DE_KA_RnD\","            \
      "\"ProcessParams\": {"                    \
        "\"NonDegree\": 0,"                     \
        "\"MaxLag\": 0,"                        \
        "\"Model\": \"Default\""                \
      "},"                                      \
      "\"ControlParams\": {"                    \
        "\"Kp\": \"0.0\","                      \
        "\"Ki\": \"0.0\","                      \
        "\"Kd\": \"0.0\","                      \
        "\"Alpha\": \"0.0\","                   \
        "\"Ts\": \"0.0\""                       \
      "},"                                      \
      "\"MechanicalLimitations\": {"            \
        "\"LimitUMin\": 0,"                     \
        "\"LimitUMax\": 0,"                     \
        "\"LimitYMin\": 0,"                     \
        "\"LimitYMax\": 0"                      \
      "},"                                      \
      "\"Data\": {"                             \
        "\"U\": [1, 2, 3, 4],"                            \
        "\"Y\": [1, 2, 3],"                            \
      "}"                                       \
    "}"
    

    For the generation of the arrays I would like to use the following way in the long run:

    typedef struct {
      int *value;
      size_t used;
      size_t size;
    } Vector;
    
    Vector u_voltage;
    Vector y1_position;
    Vector y2_velocity;
    
    void initVector(Vector *vec, size_t initialSize) {
        vec->value = malloc(initialSize * sizeof(int));
        vec->used = 0;
        vec->size = initialSize;
    }
    
    void insertVector(Vector *vec, int element) {
        if (vec->used == vec->size) {
            vec->size *= 2;
            vec->value = realloc(vec->value, vec->size * sizeof(int));
        }
        vec->value[vec->used++] = element;
    }
    
    void freeVector(Vector *vec) {
        free(vec->value);
        vec->value = NULL;
        vec->used = vec->size = 0;
    }
    
    //... then in main
    
    /* Init Vectors */
    initVector(&u_voltage, 10);
    initVector(&y1_position, 10);
    initVector(&y2_velocity, 10);
    
    /* Only Test generation */
    int iterator = 0;
    for (iterator = 1; iterator < 11; ++iterator)
    {
        insertVector(&u_voltage, u);
        insertVector(&y1_position, y1);
        u = u + 10;
        y1 = y1 + 100;
    }
    // u_voltage = [0], [10], [20], [30], [40], [50], [60], [70], [80], [90],
    // y1_position = [-100], [0], [100], [200], [300], [400], [500], [600], [700], [800],
    
    // Set method
    retVal = Json_setValue(hObject, "\"Data\".\"U\"", (&u_voltage)->value, 10);
    if (retVal != 0) {
        Display_printf(display, 0, 0, "Error setting the Data vector U value");
        while (1);
    }
    
    freeVector(&u_voltage);
    freeVector(&y1_position);
    freeVector(&y2_velocity);
    
    //...

    This way of generation only serves as another test possibility to get the desired set method running:

    int test[] = {1, 2};
    retVal = Json_setValue(hObject, "\"Data\".\"U\"", *test, sizeof(test));
    if (retVal != 0) {
        Display_printf(display, 0, 0, "Error setting the Data vector U value");
        while (1);
    }

    Both tests won't work for the JSON array.

    Failure: Error setting the Data vector U value (from the retval!=0 query)

    How is it possible to set the array variable with "Json_setValue() "?

    Thanks & Regards.

    Patrick

  • Just to make the question more specific. Writing the array values individually works (see code below). However, this is definitely not very efficient for the very large amounts of measurement data present in my use case.

        int j;
        for (j = 0; j < (&u_voltage)->used; j= j+1 ) {
            int temp = (&u_voltage)->value[j];
            sprintf(keyBuf, "\"Data\".\"U\".[%d]", j);
            retVal = Json_setValue(hObject, keyBuf, &temp, sizeof(temp));
            if (retVal != 0) {
                Display_printf(display, 0, 0, "Error setting the Data vector U value %d", j);
                while (1);
            }
        }

  • Hi Patrick,

      Thanks for posting on E2E.  Please provide some additional information about the processor being used, as well as other ICs in the design.

    Thank you,

    ~Leonard 

  • Hi Patrick,

    Do you mean you want to find a more efficient way to replace Display_printf() function?

    Best regards,

    Cash Hao

  • Hello Cash Hao11,

    no thats not what I want. I want to create a JSON-Object. The JSON-Object holds an array. And I want to set this array in one "Json_setValue"-Call and not value by value.

  • Another Problem:

    I am not able to add more array elements to the JSON-Object than 255. Is this limit fix or is it possible to add more elements.