Skip to content

ESPLwIPClient setTimeout conflicts with Stream setTimeout #5558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JAndrassy opened this issue Aug 18, 2021 · 27 comments · Fixed by #6676
Closed

ESPLwIPClient setTimeout conflicts with Stream setTimeout #5558

JAndrassy opened this issue Aug 18, 2021 · 27 comments · Fixed by #6676
Assignees
Labels
Area: BT&Wifi BT & Wifi related issues Status: Test needed Issue needs testing Type: Bug 🐛 All bugs
Milestone

Comments

@JAndrassy
Copy link
Contributor

ESPLwIPClient::setTimeout conflicts with Stream::setTimeout

the classes hierarchy is Print <- Steam <- Client <- ESPLwIPClient <- WiFiClient

void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second

virtual int setTimeout(uint32_t seconds) = 0;

@rin67630
Copy link

rin67630 commented Aug 18, 2021

+1
That bug has hard consequences and prevents me to control my ESP32 devices over the network since a stream will timeout upon a manual input and
client.setTimeout(60000);
has no effect.
Please categorize it to a high priority.
Besides that, it is not admissible that ESP32 and ESP8266 behave that differently on standard methods.

@VojtechBartoska VojtechBartoska added Status: To be implemented Selected for Development Status: Awaiting triage Issue is waiting for triage labels Mar 30, 2022
@VojtechBartoska
Copy link
Contributor

Hello @JAndrassy, sorry for late reply. We will take a look on this if we can fix this.

@P-R-O-C-H-Y P-R-O-C-H-Y added Type: Bug 🐛 All bugs Status: Test needed Issue needs testing Area: BT&Wifi BT & Wifi related issues and removed Status: To be implemented Selected for Development Status: Awaiting triage Issue is waiting for triage labels Apr 5, 2022
@VojtechBartoska VojtechBartoska moved this from Todo to Under investigation in Arduino ESP32 Core Project Roadmap Apr 20, 2022
@P-R-O-C-H-Y
Copy link
Member

Hi @JAndrassy , @rin67630
Can you provide some sketch, so I can test and fix that? :) Thanks

@JAndrassy
Copy link
Contributor Author

so you should not change the Arduino API (Stream.h). I don't know what for is the other setTimeout but it should be removed or renamed

@P-R-O-C-H-Y
Copy link
Member

Sure the change will be in ESPLwIPClient class or WiFiClient class.
But @rin67630 mentioned that the timeout does not have any effect. So I would like to test that to be able to fix everything at once.

@JAndrassy
Copy link
Contributor Author

Sure the change will be in ESPLwIPClient class or WiFiClient class. But @rin67630 mentioned that the timeout does not have any effect. So I would like to test that to be able to fix everything at once.

I guess rin's problem is that it has effect on something else than expected

@VojtechBartoska VojtechBartoska moved this from Under investigation to In Progress in Arduino ESP32 Core Project Roadmap Apr 29, 2022
@VojtechBartoska VojtechBartoska added this to the 2.0.3 milestone Apr 29, 2022
@P-R-O-C-H-Y
Copy link
Member

@JAndrassy How did you compile that? I have no errors / warning during compilation and the timeout is working fine for me.

@JAndrassy
Copy link
Contributor Author

@JAndrassy How did you compile that? I have no errors / warning during compilation and the timeout is working fine for me.

which of the two possibilities is working?

@P-R-O-C-H-Y
Copy link
Member

P-R-O-C-H-Y commented May 2, 2022

Can you test WifiClient.cpp and WifiClient.h files from my fork? I'm making changes now, because the virtual cannot be there :)

link to my repo + branch with fixes

@P-R-O-C-H-Y
Copy link
Member

Can you test WifiClient.cpp and WifiClient.h files from my fork? I'm making changes now, because the virtual cannot be there :)

link to my repo + branch with fixes

You can test changes from this PR

@JAndrassy
Copy link
Contributor Author

sorry, I assumed you know the Arduino API Print and Stream classes as I think it is a very important part of Arduino core.

setTimeout and _timeout exist in Stream.h/cpp. _timeout is used in timed read functions readBytes, readBytesUntil, readString, readStringUntil, parseInt, parseFloat, find.
the _timeout in Stream class can't be set if setTimeout and _timeout exist in WiFiClient

@P-R-O-C-H-Y
Copy link
Member

Can you check latest changes in linked PR? setTimeout is removed from WifiClient / WifiClientSecure.

@JAndrassy
Copy link
Contributor Author

JAndrassy commented May 2, 2022

Stream timeout is now OK, but how is _timeout in WiFiClient set? and what is its purpose? is it for closing inactive TCP connections? I guess users would choose a very different timeout for TCP connection timeout than for Stream timed read functions. For TCP connection timeout seconds are a good scale. So if I understand this right the setTimeout in ESPLwIPClient and WiFiClent should be renamed to setConnectionTimeout(millis)? (and it should not call setTimeout of Stream)

and it would be good to know for HttpCliemt, which timeout was meant to be set

@P-R-O-C-H-Y
Copy link
Member

Also feel free to comment and suggest changes to the PR if I missed something.

@P-R-O-C-H-Y
Copy link
Member

the setTimeout is for read/write functions. This change will make the timeouts to be set in milliseconds to be same as Arduino Stream setTimeout. The connection timeout can be set in call Client.connect() function eg.
int connect(IPAddress ip, uint16_t port, int32_t timeout);

@podaen
Copy link

podaen commented May 3, 2022

Having troubles to analyse the the stream input. I want to serial.print the count of the readed bytes in the stream.cpp but nothing is shown. If I serial.print in stream.h I got an error...

Stream.h: 104:9: error: 'Serial' was not declared in this scope
Serial.print("read bytes stream.h")

@P-R-O-C-H-Y
Copy link
Member

P-R-O-C-H-Y commented May 3, 2022

Having troubles to analyse the the stream input. I want to serial.print the count of the readed bytes in the stream.cpp but nothing is shown. If I serial.print in stream.h I got an error...

Stream.h: 104:9: error: 'Serial' was not declared in this scope
Serial.print("read bytes stream.h")

Instead of Serial.print("read bytes stream.h") use log_d("read bytes stream.h") and set Core debug level to DEBUG.

@JAndrassy
Copy link
Contributor Author

JAndrassy commented May 3, 2022

@podaen why do you hijack my issue report for an unrelated problem? please delete your comments

@podaen
Copy link

podaen commented May 3, 2022

Why making a new one?? If I had that same issue, I want to see if it works for me too.

@podaen
Copy link

podaen commented May 3, 2022

@P-R-O-C-H-Y Can you do this for client.h as well?

@VojtechBartoska
Copy link
Contributor

VojtechBartoska commented May 3, 2022

Why making a new one?? If I had that same issue, I want to see if it works for me too.

Hi @podaen, up to your comment it seems you are facing different issue (correct me if I'm wrong). Due to that it's better to open an new issue if it's needed. The goal is to uncover specific problem in particular issue and solved it directly.

Other benefit of opening a new issue is providing more complex information thanks to the issue template. From a single comment it's almost impossible to just reproduce your code and at least verify the issue.

Also, if you are more experienced and as I can see you have specific request, don't hesitate to open a Pull Request. Generally it's much faster approach comparing to opened issue.

I hope you understand all parts mentioned above. We would like to help you as much as possible but please keep in mind that are resources are also limited.

Thanks.

@podaen
Copy link

podaen commented May 3, 2022

Why so defendant? I admit that it was wrong to print in the stream over the hardware serial. I investigated it and it was is not the right thing to do... My attention didn't came out of nowhere, it came out of the stream and timeout. And I make some correction and I will test too!

@VojtechBartoska
Copy link
Contributor

it wasn't meant to be defendant. Oki, looking forward for your feedback then! :)

@podaen
Copy link

podaen commented May 3, 2022

@JAndrassy The socket will have the timeout when connecting to the wificlient. So, you can close this topic. The conflict was already checkt by you I think.

Still under investigation: The timeout is not been shared from the wificlient or the sll client to the stream.h. The client.h is the link for sharing to stream.h! I have to keep this in mind to continue tomorrow.

@JAndrassy
Copy link
Contributor Author

JAndrassy commented May 3, 2022

@podaen I created this issue report not for some troubleshooting, but to resolve a code design mistake in the esp32 WiFi library which can't be resolved without a breaking change and a decision must be made about it by the maintainers.
your comments are out of context here. there is nothing to debug (and learn how to debug)

@VojtechBartoska VojtechBartoska modified the milestones: 2.0.3, 2.1.0 May 4, 2022
@VojtechBartoska VojtechBartoska moved this from In Review to In Progress in Arduino ESP32 Core Project Roadmap May 4, 2022
@VojtechBartoska
Copy link
Contributor

Issue postponed to 2.1.0 milestone. More investigation and testing is needed. Thanks for understanding.

@VojtechBartoska VojtechBartoska moved this from In Progress to In Review in Arduino ESP32 Core Project Roadmap May 18, 2022
@VojtechBartoska VojtechBartoska modified the milestones: 2.0.6, 3.0.0 Oct 11, 2022
@JAndrassy
Copy link
Contributor Author

Other libraries have client.setConnectionTimeout. It was first used in the 2.0.0 version of the Ethernet library in 2018. There it is used in client.stop() too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BT&Wifi BT & Wifi related issues Status: Test needed Issue needs testing Type: Bug 🐛 All bugs
Projects
Development

Successfully merging a pull request may close this issue.

5 participants