Teensy 4.1: TeensyThreads with NativeEthernet Client

Harry888

Member
Hello,

I'm developing a project where I collect the data from the can interfaces and send it with EthernetClient to the cloud.

EthernetClient is running in a thread function and sends the data regularly to the cloud.
In the main loop, I collect the data from the can interfaces.

Basically It works.

The problem that I have is that the EthernetClient seems to block the switch from the thread function to the main loop for approximately 8 seconds.
The function sends the data in 1 to 2 sec. So every time I send the data, I lose approximately 6 seconds

How can I achieve a faster change to the main loop?

Thank you
Harry
 
What happens if you don’t use threads? I.e. call functions one after the other, and if any need to be done periodically, use time measurement.
 
If I call the functions one after the other, there is no blocking behavior. The functions in the same thread are running without hesitation.

The switch back to the main thread comes after approximately 6 seconds
 
I was suggesting to not use the threading library.

Please clarify one point: did you want blocking behaviour or not? I’m unclear from the description.
 
I don't want to have blocking behavior.

It should POST the data to the cloud and immediately return to the main function
 
approximately 6 seconds
Reading this goes back to lost time indicated in OP #1.
lose approximately 6 seconds

Are there any thread.delay() - or whatever the call is - to say I've done enough for now switch threads.

Long times assures a task isn't exited at a bad time - but cycling quicker would keep anything from starving - not sure how seconds of inattention to ethernet can affect it for instance
 
the program has this structure

void postData()
{
while(1) {
// POST data to the cloud

delay(10'000); //threads.yield();
}
}

void loop()
{
int id = threads.addThread(postData);

while(1)
{
// Collect and Check data from CAN

delay(1); //threads.yield();
}
}

To not miss CAN signals I have to check the inputs everey 1ms. But after every POST I miss a lot of CAN inputs
 
Thought it was threads.delay()! Indeed that must be used to do a thread switch and not just put the current thread in a wait loop causing the thread to 'stall' until thread time expires.
 
I’m going to bookmark this thread and point to it in the future because it’s a perfect example of why including some code in one’s question will very possibly lead to a solution much more quickly.
 
I’m going to bookmark this thread and point to it in the future because it’s a perfect example of why including some code in one’s question will very possibly lead to a solution much more quickly.
It does save the effort of speculating ... my preceding post #6 wouldn't have had to recall the proper function to use and infer some relation.
 
Back
Top