0

Every so often my variable gets corrupted. Sometimes it happens several times in a row and other times it doesn't happen in several hits. I put these logs to rule out that any of the operations interfered. But as you can see just between one log and another, the data is dirty.

This runs on an ESP32 with arduino as framework and this procedure comes from a freeRTOS dequeue.

log:

[D][RC_msgRouterProcessCommand.cpp:60] _cloudRXServiceWorker(): Mensaje desencolado:
 topic: iot/riego/prueba/valvula/1
 payload: {
  "controlRemoto": true,
  "modulo": 11,
  "slot": 1,
  "status": 1
}
[D][RC_msgRouterProcessCommand.cpp:61] _cloudRXServiceWorker(): running on core >>>> 0
[D][RC_msgRouterProcessCommand.cpp:62] _cloudRXServiceWorker(): 1 >>>>>>>>>>>>>>>>>>>>>> {
  "controlRemoto": true,
  "modulo": 11,
  "slot": 1,
  "status": 1
}
[D][RC_msgRouterProcessCommand.cpp:63] _cloudRXServiceWorker(): 1-1 >>>>>>>>>>>>>>>>>>>>>> {
  "controlRemoto": true,
  "modulo": 11,
  "slot": 1,
  "status": 1
}
[D][RC_msgRouterProcessCommand.cpp:64] _cloudRXServiceWorker(): 1-2 >>>>>>>>>>>>>>>>>>>>>> {
  "controlRemoto": true,
  "modulo": 11,
  "slot": 1,
  "status": 1
}
[D][RC_msgRouterProcessCommand.cpp:65] _cloudRXServiceWorker(): 1-3 >>>>>>>>>>>>>>>>>>>>>> ��@)�?
[D][RC_msgRouterProcessCommand.cpp:66] _cloudRXServiceWorker(): 1-4 >>>>>>>>>>>>>>>>>>>>>> ��@)�?
[D][RC_msgRouterProcessCommand.cpp:67] _cloudRXServiceWorker(): 1-5 >>>>>>>>>>>>>>>>>>>>>> ��@)�?
[D][RC_msgRouterProcessCommand.cpp:69] _cloudRXServiceWorker(): 2 >>>>>>>>>>>>>>>>>>>>>> ��@)�?
[D][RC_msgRouterProcessCommand.cpp:71] _cloudRXServiceWorker(): 3 >>>>>>>>>>>>>>>>>>>>>> ��@)�?
[D][RC_msgRouterProcessCommand.cpp:72] _cloudRXServiceWorker(): Item count: 5
[D][RC_msgRouterProcessCommand.cpp:73] _cloudRXServiceWorker(): 4 >>>>>>>>>>>>>>>>>>>>>> �^�?
[D][RC_msgRouterProcessCommand.cpp:76] _cloudRXServiceWorker(): Item @ index 0 : iot
[D][RC_msgRouterProcessCommand.cpp:76] _cloudRXServiceWorker(): Item @ index 1 : riego
[D][RC_msgRouterProcessCommand.cpp:76] _cloudRXServiceWorker(): Item @ index 2 : prueba
[D][RC_msgRouterProcessCommand.cpp:76] _cloudRXServiceWorker(): Item @ index 3 : valvula
[D][RC_msgRouterProcessCommand.cpp:76] _cloudRXServiceWorker(): Item @ index 4 : 1
[D][RC_msgRouterProcessCommand.cpp:78] _cloudRXServiceWorker(): 5 >>>>>>>>>>>>>>>>>>>>>> �^�?
[D][RC_msgRouterProcessCommand.cpp:93] _cloudRXServiceWorker(): CASE: RC_HW_TYPE_VALVULA
[D][RC_msgRouterProcessCommand.cpp:94] _cloudRXServiceWorker(): XXXXXXXXXXXXXXXXXXXXXXXXXXX �^�?
[E][RC_msgRouterProcessCommand.cpp:223] _get_valve_typeByPaylod(): _get_valve_typeByPaylod. deserializeJson Json: 
 �^�?
[E][RC_msgRouterProcessCommand.cpp:228] _get_valve_typeByPaylod(): Fallo la deserializacion del json
[E][RC_msgRouterProcessCommand.cpp:229] _get_valve_typeByPaylod(): Error: InvalidInput

code fragment:

void RC_msgRouter::_cloudRXServiceWorker(){
    log_d("iniciando worker cloudRXService running on core >>>> %d",xPortGetCoreID());
    msg_t mensaje;
    while (true)
    { 
        if(xQueueReceive(QfromCloud, &mensaje , queueSpeed / portTICK_PERIOD_MS)){
            log_d("Mensaje desencolado:\n topic: %s\n payload: %s", mensaje.topic,mensaje.payload);
            log_d("running on core >>>> %d",xPortGetCoreID());
            log_d("1 >>>>>>>>>>>>>>>>>>>>>> %s",mensaje.payload);
            log_d("1-1 >>>>>>>>>>>>>>>>>>>>>> %s",mensaje.payload);
            log_d("1-2 >>>>>>>>>>>>>>>>>>>>>> %s",mensaje.payload);
            log_d("1-3 >>>>>>>>>>>>>>>>>>>>>> %s",mensaje.payload);
            log_d("1-4 >>>>>>>>>>>>>>>>>>>>>> %s",mensaje.payload);
            log_d("1-5 >>>>>>>>>>>>>>>>>>>>>> %s",mensaje.payload);            
            StringSplitter *splitter = new StringSplitter(mensaje.topic, '/', -1);  // new StringSplitter(string_to_split, delimiter, limit)
            log_d("2 >>>>>>>>>>>>>>>>>>>>>> %s",mensaje.payload);
            int itemCount = splitter->getItemCount();
            log_d("3 >>>>>>>>>>>>>>>>>>>>>> %s",mensaje.payload);
            log_d("Item count: %d", itemCount);
            log_d("4 >>>>>>>>>>>>>>>>>>>>>> %s",mensaje.payload);
            for(int i = 0; i < itemCount; i++){
                String item = splitter->getItemAtIndex(i);
                log_d("Item @ index %d : %s", i,item);
            }
            log_d("5 >>>>>>>>>>>>>>>>>>>>>> %s",mensaje.payload);
4
  • Chances are there's something happening in some other thread that is corrupting (or even destroying entirely) your payload.
    – Majenko
    Commented Jan 16, 2022 at 15:19
  • Thx @Majenko that was the problem. Commented Jan 16, 2022 at 15:39
  • Hope you delete that dynamically allocated StringSplitter somewhere later, otherwise it'll eventually run out of memory. Is it even needed to have it allocated like this? Something like StringSplitter splitter { mensaje.topic, '/', -1 }; should be just fine and it's managed automatically
    – KIIV
    Commented Jan 17, 2022 at 9:55
  • @KIIV I add delete splitter; Thx for your suggestion. Commented Jan 17, 2022 at 14:18

1 Answer 1

2

The problem was that a task with higher priority interrupts the process. I increased the priority to this task and the problem is solved.

xTaskCreatePinnedToCore(_cloudRXServiceTask, "_cloudRXServiceTask", 2048, this, 20, &_cloudRXServiceWorker_handle,0);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.