Hi,
I'm making a weatherstation for my sailclub, which besides showing data on an LCD display also transfers it to a MySQL database so you can look at the data from home. Everything is working fine, I can gather all the data, show it on the LCD screen and transfer it successfully to the database.
Since the club is on a remote location, I started adding some error handling routines so it can recover from power loss and connectivity loss. The power loss got covered by using the watchdog routines so it will reset itself if the DHCP server is not responding yet.
Connectivity loss is not working at this moment. I'm trying to simulate all kind of failures, like just attaching it to an unconnected ethernet hub or pointing to an URL that does not exist and to my big surprise it doesn't complain at all and reports the connection is still working.
During my debugging I discovered that client.connect is always returning success even if it must fail. I made a second version of my sketch that I stripped down to the essentials.
int i = client.connect(server, 80);
// Serial.print("RC = ");
// Serial.println(i);
if (i == 1) {
//if (client.connect(server, 80)) {
client.println(datastring);
...
If I take the client.connect out of the if statement it kind of works. At least in the simple version it works, in the original version it's erratic. Bear in mind that I'm trying to improve the error handling, so when things go wrong. When there's no connectivity issue it works.
I read on this forum that ethernet2 SPI is kind of flakey, I followed the recommendation to set pin 4 high but it didn't help.
I'm using the official ethernet2 shield from arduino.org, the UNO board is a rev3 board from Ali Express, as for the LCD too. I switched to a REV3 board so the pins are compatible between both and can be easily stacked. On these boards SCL/SDA have their own pins.
I'm powering it externally over a 9V power supply, since the wind sensors require a higher voltage than 5 volt
The power rails are properly decoupled, I use a TSR 1-2450 5V/1A voltage regulator to power the Arduino from the 9V supply.
I added a couple of pictures + the two sketches
simple.ino (2.68 KB)
ws.ino (5.31 KB)