WiFi shield reliability issue

Hi all

I'm developing a temperature sensor system which will measure temperature in a certain intervals and send measurement results to ThingSpeak web service via WiFi shield. There is also a functionality to send emails if the measured temperature is below the threshold.
There will be other feature as well (battery backup, battery voltage monitoring and email notification if battery voltage is below threshold, power outage detection etc.) but I would like to get current setup working properly before adding the rest of the features.

Problem is the reliability of the WiFi shield. Usually WiFi shield works max. about 24h in a row and after that it's usually not able to connect ThingSpeak anymore and in some point it is not able to connect WiFi network either. I've tried different kinds of approaches and tricks to get it more reliable but haven't been able to improve the situation.

Same issue is seen with other WiFi network with different AP HW in different place as well. I've added reset functionality to my sketch in order to get things up and running again after WiFi shield has jammed... It think WiFi shield should work much more reliably instead of adding reset functionality to the sketch.

My sketch attached (I've removed personal data from the sketch and replaced the data with capital letters). Please note that SD functionality has been added for debugging purposes only and won't be present in final code. The sketch is attached because size of the message exceeded the max. allowed length of the posting... :wink:

ThingSpeak graph can be found via the link below. The ThingSpeak graph correlates to LOG.TXT file that is attached as well.

https://www.thingspeak.com/channels/7423/charts/1?width=1450&height=960&results=336&dynamic=true

Please let me know if there is something in the code etc. that can be changed in order to improve the reliabity and uptime of WiFi shield. All help is appreciated!!!

I do have following HW and SW version in use:
-Arduino Uno R3
-Arduinu official WiFi shield and the latest firmware
-Arduino IDE 1.05
-Mac OS X 10.9

LOG.TXT (2.11 MB)

Hinnerjoki_temp_logger_with_DS18B20_DEBUG.ino (12.2 KB)

How does it fail? Does it lock up (freeze) or stops communicating with the server?

I recommend not using the String data type. That has caused me grief every time I have used it. It has always caused a crash.

This also sounds like the same problem the ethernet shield has/had. If the connection breaks (fails), the code may not get a disconnect message from the server. Here is my code for the ethernet shield, but it should work for the wifi shield also, just like the email. That appears to be my email code you are using now. It has a timeout. Look at eRcv() function and the variable loopCount.

There is a GET and POST example here.
http://playground.arduino.cc/Code/WebClient
Give it a try for a while as a test, and see if it fails.

Note the timeout code in the getPage() and postPage() functions. In the "while(client.connected())" loop is most likely where it will fail/freeze (edit:) without my timeout code. The timeout code will go right through a connection fail. No need for a reset.

Thanks for the reply.

At the first place it failed on "socket not available" issues but I was able to overcome those issues by adding client.flush and client.stop functions to correct places in my sketch. Nowadays it just stops communicating with the ThingSpeak server and after a while it isn't able to connect WiFi network anymore (there is a restart WiFi function in the sketch if ThingSpeak connections fails too many times in a row).

LOG.txt file which can be found from my first post would give a hint about what has gone wrong in my latest test drive.

I do have same "send data to ThingSpeak with Strings" code running on my other system and it has been working flawlessly. It uses ethernet connection via Etherner shield though... I guess there are a lot of differencies in WiFi vs ethernet firmwares, libraries etc. so probably one shouldn't draw conclusion that it should work with the WiFi shield even if it's working with the ethernet shield.

I'll try what you suggested and let you know is it working better or not.

By the way, thanks for the excellent email code which is working perfectly... :wink:

It looks like the demo sketch (based on POST sketch posted by SurferTim) is working very well. To be honest I haven't seen any issues yet so it's going very well.

Next I'll modify my original sketch and remove all the Strings and do some testing with that one.