gasagna / A76XX

Arduino library for the A76XX family of SIMCOM cellular modules, with native MQTT(S), HTTP(S), etc, clients!
MIT License
6 stars 1 forks source link

Can't do HTTP POST with xTaskCreatePinnedToCore #2

Closed Moskus closed 9 months ago

Moskus commented 9 months ago

I'm stuck on creating a task that can upload data in parallell to gathering data. I can't for the life of me not get this to work. When the task ("gathering data" and "sending data") are running on the same core, everything works. When both are running on Core 0 or on different cores, it does not work, for some reason.

When they run on different cores, the upload (http.post()) halts the operation and I get errors (post error -2 among them).

In the function SendMessage() I create a task for uploading the jsonString:

  char *msg = (char *)jsonString.c_str();
  xTaskCreatePinnedToCore(
      SendJson,   /* Function to implement the task */
      "SendJSON", /* Name of the task */
      10000,      /* Stack size in bytes */
      msg,        /* Task input parameter */
      9,          /* Priority of the task */
      NULL,       /* Task handle. */
      0);         /* Core where the task should run */

---
void SendJson(void *parameter)
{
  //String data = *((String *)parameter);
  char *data = (char *)parameter;
  Serial.println(data);
  lte_post(data);
  vTaskDelete(NULL);
}

... in setup() I create two tasks, one that reads the queue every 2 second and uploads it (using the task above) and one that creates random messages.

    xTaskCreatePinnedToCore(
        SendMessagesTask,   /* Function to implement the task */
        "SendMessagesTask", /* Name of the task */
        10000,              /* Stack size in bytes */
        NULL,               /* Task input parameter */
        1,                  /* Priority of the task */
        NULL,               /* Task handle. */
        1);                 /* Core where the task should run */

    xTaskCreatePinnedToCore(
        CreateMessagesTask,   /* Function to implement the task */
        "CreateMessagesTask", /* Name of the task */
        10000,                /* Stack size in bytes */
        NULL,                 /* Task input parameter */
        1,                    /* Priority of the task */
        NULL,                 /* Task handle. */
        0);                   /* Core where the task should run */

These tasks can be on different cores. but it's crucial that CreateMessagesTask and the SendJson task is on the same Core0, but it does not matter if it's on core 0 or 1.

No matter what I do I can't get the creating/gathering of data to run in parallell with sending on a different core. Is there some limitations of this library or the A7608 modem?

The code I'm using is attached: code.zip

Moskus commented 9 months ago

In the code there's this line: messageToSend.mdate = modem.getUnixTime()

... and that's what blocking the core. So this needs to be done in a different way.

gasagna commented 9 months ago

Hi, I do not think this library is thread-safe because there serial communication with the module has to be inherently.... serial. You should only read/write to the module with one task, or implement your own logic with some sort of lock.