[Urgent] Data loss when receiving from the Queue

q220085
Posts: 3
Joined: Tue Jan 05, 2021 12:15 am

[Urgent] Data loss when receiving from the Queue

Postby q220085 » Fri Jan 08, 2021 11:44 pm

Hi, I am doing a project with writing two tasks both pinned to core 0 with TTGO LoRa ESP32 as a server device. One task (say, Task 1) for sending data (which is received from other client esps via LoRa radio) to the queue, one (say, Task 2) for receiving data from the queue.

The code for Task 2 is below:

Code: Select all

 xTaskCreatePinnedToCore( logWiFiDeviceData,                        // Task function
                                         "TaskForLoggingWiFiDeviceData",    // Task name
                                         10000,                                           // Stack size in words
                                         NULL,                                            // Parameter passed as input to task
                                         0,                                                  // Task priority (0 is the lowest priority)
                                         NULL,                                            // Task handle
                                         0 );                                                // Core ID

Code: Select all

void logWiFiDeviceData( void* parameter )
{
  wifiDevicePayload payload;

  for(;;)
  {
    for ( size_t i = 0; i < cg_queueSizeBetweenReceiveAndLog; ++i )
    {
      xQueueReceive( g_queueBetweenReceiveAndLog, &payload, portMAX_DELAY );
      
     if ( strcmp( payload.mac, DESIRED_DEVICE_MAC_ADDRESS ) == 0 )
      {
        Serial.println( "MAC matched!" );
        Serial.print( "Slave ID = " );
        Serial.println( payload.slaveID );
        Serial.print( "MAC = " );
        Serial.println( payload.mac );
        Serial.print( "RSSI = " );
        Serial.println( payload.rssi );
        Serial.print( "Packet ID = " );
        Serial.println( payload.packetID ); 
      }
     }
     vTaskDelay( 1 / portTICK_PERIOD_MS );
  }

} // logWiFiDeviceData

The struct wifiDevicePayload is defined as:
[code]
typedef struct
{
  char mac[100] = {0};
  uint32_t packetID;
  int8_t rssi;                           
  int8_t slaveID;

} __attribute__((packed)) wifiDevicePayload;
The output is as follows:
[/code]
2021-01-09 00 10 38.jpg
2021-01-09 00 10 38.jpg (106.47 KiB) Viewed 184 times

My question is: why are the information of payload.slaveID, payload.rssi, payload.packetID(which are type of int8_t, int8_t, uint32_t, respectively) got lost when transmitted by the Queue?
I am sure that the three members have non-zero values before sending into the Queue. They should be something like:

MAC matched!
Slave ID = 4
MAC = 38:10:D5:5C:58:62
RSSI = -76
packetID = 3465


I really can't figure out why I got this result and have nothing to do with this weird issue.....
Please help me...Any help is greatly appreciated!

Who is online

Users browsing this forum: Bing [Bot] and 24 guests