My program uses temp sensor to monitor and turn relay on/off . Temp data and temp value to be controlled via ethernet.
Simular program is working for my Mega2560. But trying to implement on Uno give me non response after like 15 hours running. Having console open I see no output to indicate the problem. Output is just stopped and no response to client request. Just ping response still work.
Been trying to trouble shoot with freeRam() console output at various places in code. Lowest value I had was 848 bytes when in NTP code. Else value stay stable at 920 bytes when inside loop.
I'm guessing it's some kind of program problem .... since every time it bails out after like 15 hours.
I print some data on console once every minut in loop. This stop output on console so it's like program loop is broken.
Memory after compile:
Sketch uses 24922 bytes (77%) of program storage space. Maximum is 32256 bytes.
Global variables use 816 bytes (39%) of dynamic memory, leaving 1232 bytes for local variables. Maximum is 2048 bytes
Any hint on how to track memory usage in more detail other than using freeRam() ?
I'm using delay(500) once .... could that be a problem ?
Or any other thought on my problem.
Remove all uses of Strings and replace them with c-style char arrays. The String class uses the heap, which is the 1232 for simplicity... Using the String class is basically making swiss cheese of your memory, corrupting it beyond usable after 15 minutes.
Yes I will do that. Though if that is the problem I would expect this to be reflected in the freeRam() output decreasing. My String vars is mostly static lenght so that should not eat memory ...
If you search the forum with any depth, you will find countless discussions about Strings doing exactly what you describe. You will find just as many discussions about memory reports that are either misunderstood, misused or inaccurate or bogus.
sidhabo:
Yes I will do that. Though if that is the problem I would expect this to be reflected in the freeRam() output decreasing. My String vars is mostly static lenght so that should not eat memory ...
Let's say, for example, freeRam() calculates the difference between the stack and the total memory, to report the heap as free ram. disclaimer I don't know what freeRam does, and I don't care, but this is a common method to report free memory Using the heap will not change what is reported by freeRam().
Yes, just haven't got around to using char bufs instead of String. Have to go at it now ....
What about String in functions. Less problem I would think if they are just defined once and discarded at return. Howto return a char buff from function ?
sidhabo:
Yes, just haven't got around to using char bufs instead of String. Have to go at it now ....
What about String in functions. Less problem I would think if they are just defined once and discarded at return. Howto return a char buff from function ?
You are applying principles of the stack to the heap. Strings abuse the heap. The stack is organized and managed with scope and permanence etc. the heap is no-man's land, where bits aren't managed. It's easily abused by large operating systems with plenty of RAM, but detrimental to micro-controllers with limited RAM. The leap to char arrays isn't very big.
Good link Perehama. Thanks. Getting the basic buffery .... But a little problem returning buffer values instead of String values from functions. Is this proper ?
Sooo , finally got around to clean out String
Result was like minor improvment .... sometimes program run 2-3 days now instead of less than 24 hours. Still crash, now like after 16 - 48 hours.
So can you see any problem now in my attached no String code ?
I will have time later to look at your code. I suggest also you use a REST client to send specific packets to your server to see if it hangs on a particular keyword or resource etc. You can also connect a serial monitor and log the traffic to your server to look for clues.
Total newbie to REST client. Checked out a couple of them. Did not grok at all how to use them.
Not sure how I could log via serial. I'll have a go with Wireshark and log traffic to/from the Webserver that is on my local network.