MySQL Forums
Forum List  »  Connector/Arduino

Re: I use MySQL connectorl and after some time it stops. PLEASE HELP
Posted by: Daniel Wee
Date: February 04, 2017 04:48AM

Hi Chuck - I think I traced the problem and this might be useful for other users.

Basically, the problem comes down to two different issues:-

1. The use of delay(1000) in the connect function, and delay(100) in the wait_for_client function. While this works most of the time, there seems to be some incompatibilities with other interrupt functions with the ESP8266 system under Arduino.

I changed the delay(1000) to use:-

unsigned long sttime=millis();
while (millis()-sttime < 1000) yield();

*likewise for everywhere else delay() appears - especially in MySQL_Packet.cpp

and some other judicious placements of yield() - this completely resolved the apparently random resets and exceptions. After months of experimenting, this actually completely got rid of the problems.

2. There was still the occasional watchdog timeout which I tracked down to the wait_for_client function. This function is called by read_packet and is expected to return an integer.

The way the code is written, however, allows wait_for_client to timeout but without any indication to the read_packet that this has happened. As a result, you could potentially have a situation where the read_packet loops indefinitely while waiting for data that is not forthcoming and thus resulting in a watchdog timeout.

To fix this, I altered wait_for_packet to return a -1 in the event of a timeout, and to check for this result in read_packet so that it can abort in the event of a timeout. Basically, this looks like:-

int avail_bytes = wait_for_client();
if (avail_bytes < 0) return;

* this works after modifying wait_for_client to return a -1 if it timed out.

These two changes fixed all the problems I had been having with mysterious resets. There may be a need to check for timeouts with wait_for_data as well but I have not done that as yet. If I continue to experience problems I may do that.

Could you look at these changes to see if you could incorporate it into the official code. This way I won't have to make the changes manually when new code is released.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: I use MySQL connectorl and after some time it stops. PLEASE HELP
208
February 04, 2017 04:48AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.