Hi,
In an university project I need to implement a package resending for the CoAP-simple library for arduino. Theoretically, I would consider this an easy task, since it only envolves a few lines of code. As I am more of a Java programmer and not very well versed in C++ and arduino stuff I am a bit desperate with the error I have got since I cannot find a solution to it.
In my code, if a confirmable packet is sent, I want to create a thread which sleeps for a timeout, then checks if the packet needs to be resent and then possibly retransmits it. I have already tested creating and calling a thread like that in a separate C++ program and it worked flawlessly.
The problems began when trying to include it into the actual library. While compiling and everything works, as soon as my library tries to create threads I get the following error in the serial monitor:
14:35:19.810 -> Send Request
14:35:19.843 -> abort() was called at PC 0x40136f9f on core 1
14:35:19.876 ->
14:35:19.876 -> Backtrace: 0x4008ec3c:0x3ffb1d10 0x4008ee6d:0x3ffb1d30 0x40136f9f:0x3ffb1d50 0x40136fe6:0x3ffb1d70 0x400d2a37:0x3ffb1d90 0x400d2d69:0x3ffb1dd0 0x400d2e42:0x3ffb1ef0 0x400d2e71:0x3ffb1f40 0x400d11a7:0x3ffb1f80 0x400d3a65:0x3ffb1fb0 0x4008b009:0x3ffb1fd0
14:35:20.141 ->
14:35:20.141 -> Rebooting...
What is happening in my code is that, when sending a message, the function resend is called that is supposed to create a new thread for the resending. In a try to eliminate variables while trying to find the error cause it was reduced to the code below:
library cpp file (includes header file):
int Coap::resend(int delay) {
test_thread.reset(new std::thread(test));
return 0;
}
library header file:
class Coap {
private:
std::unique_ptr<std::thread> test_thread;
[...]
}
static void test() {
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
std::cout << "Thread created!";
}
I have tried searching for the error but most cases do barely apply to my use case and one that i found has been applied, but did not help me: https://github.com/espressif/arduino-esp32/issues/2814
The library I'm working with is this one: GitHub - hirotakaster/CoAP-simple-library
I'm using two ESP32 WROVER modules with one arduino client and one arduino server implementation which are connected to each other over my smartphones hotspot network. Communication has worked flawlessly without the thread creation.
My gut feeling is telling me that it is an issue that I cannot solve without alot of indepth knowledge, which is why I'm asking you to help me.
Thank you for your time!