Sending sensor data through system firmware blocking send

Hi, I am trying to create a new system message and system firmware call in Particle Photon that would send encrypted data to the local cloud (set-up in my linux machine) using the blocking_send routine. I successfully implemented the same and am sending sensor data at 10Hz (4274 bytes at a time) to the local cloud, which decrypts it and adds it to the repository. I gather all sensor data (using adafruit libraries) and call the firmware routine for encrypting and sending in the application loop.

However, after encrypting, sending, receiving and decrypting the data well for about 10-15 iterations of the loop, the device goes into error mode. it flashes the red SOS signal with 1 Blink in between (Hard Fault as per Does anyone know why this happens? I have placed the system call code in the end of this post.

I also get the CryptoStream error on the local server as per shown below. Any help in this direction would be appreciated.
CryptoStream transform error TypeError: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt

int SparkProtocol::mysend(const uint8_t *data, size_t length)
  if (updating)
    return false;
  uint16_t msg_id = next_message_id();
  size_t msglen = Messages::mysend(queue + 2, msg_id, data, length);
  size_t wrapped_len = wrap(queue, msglen);
  return (blocking_send(queue, wrapped_len));
1 Like

Are you freeing all memory you are allocating and are all your buffers big enough?
You could add a printout of freeMemory() to see if you’re producing a memory leak.

Yes, the free memory remains constant to 16K bytes. What could be other ‘hard’ issues that might be causing the failure?

Could you post your full code?
Can you add some more Serial.print() statements and delays to narrow down which exact statement causes the crash?

If you have a Programmer shield or any other JTAG/SWD adapter, you could use OpenOCD to debug in-process.