OK. Trying to understand why strange behaviour on the board.
I have the code working, but still don't understand why I had problems.
My setup :
Mega 2560
new Ethernet Shield
Port forwarding for port 82 set in the router.
Current IP xx.xx.xx.xx:82 viewed from a browser which displays the test page from the Arduino 100% OK : Zoomkat's simple Arduino 1.0 button ON OFF
I had the inputs for my home panic system ( linked to a remote security company ) on pins 14 & 15
The relay that activates the radio signal is on pin 9
LCD was on 2,3,4,5,6,7
I moved the LCD to 18,17,16,5,6,7
Also moved the panic inputs to 2,3
pins 4 and 10 both empty
System works fine, until I try to GET data to my php page.
in my temperature sensor reading code, I have added the LogItWeb line here :
float tempC1 = readTemperature(outsideThermometer);
float tempC2 = readTemperature(insideThermometer);
LogItC("Temp In : ",0);
LogItF(1,tempC2,0,4);
LogItWeb(1,tempC2);
LogItC(" -- Out : ",0);
LogItF(2,tempC1,1,4);
The LogItWeb goes to :
void LogItWeb(int Location, float LogTxt){
if (client.connect(myserver, 80)) {
Serial.println("connected");
client.print("GET http://www.myserver.com/serveit.php?data=");
client.print(Location);
client.print("--");
client.print(LogTxt);
client.println(" HTTP/1.1");
client.println("Host: www.myserver.com"); // i found my server rejects the connection if this line is not present
client.println();
while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available()) { //connected or data available
char c = client.read();
Serial.print(c);
}
client.stop();
Serial.println("disconnected");
Serial.println("==================");
}
else {
Serial.println("connection failed");
Serial.println("==================");
}
}
I can see that the ethernet code is calling the php file and writing to the txt file on my web server.
I am getting exactly as expected :
IP address : xx.xx.xx.xx 2012-04-01---12:02:27 1--26.25
However, once it has run once, it seems to activate my panic system relay ( pin 9) and then freezes the system. The temp readings on the LCD are not updating and I have to re-set the system.
Can you see anything in the LogItWeb function that would cause this erratic behaviour ?
What I am seeing in the Serial Monitor as soon as I reset is :
server/client 1.0 test 12/08/11
Send get1 in serial monitor to test client
Setup Completed - System Operational
Setup Completed - Checking SMS state
EEProm read
EEProm = 0 (sms OFF, Home)
Temp In : 26.25
connected
HTTP/1.1 200 OK
Date: Sun, 01 Apr 2012 10:02:56 GMT
Server: Apache/2.2.16 (Debian) mod_fcgid/2.3.6 mod_ssl/2.2.16 OpenSSL/0.9.8o mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.3-7+squeeze8
Content-Length: 0
Content-Type: text/html
I would expect the next line to be :
-- Out : 26.25
but it would appear that the sketch is freezing in the section where it waits for a reply from the web server.
Next, I added a short delay (250) and commented out the section of code that I think waits for a response from the web server. Everything seems to be working fine now. Could it be that because my web side php script receives the data and writes it to a web side txt file, but doesn't actually send anything back to the Arduino ?
I found that before this mod the Rx LED on the ethernet board was on constantly. Was that because it was always waiting for incoming data ?
I just don't understand why the unmodified code would activate my panic system relay on pin 9 ( activates the relay with a ground / low signal ).
The new function :
void LogItWeb(int Location, float LogTxt){
if (client.connect(myserver, 80)) {
Serial.println("connected");
client.print("GET http://www.imagedisk.co.za/serveit.php?data=");
client.print(Location);
client.print("--");
client.print(LogTxt);
client.println(" HTTP/1.1");
client.println("Host: www.imagedisk.co.za");
client.println();
delay(250);
// while(client.connected() && !client.available()) delay(1); //waits for data
// while (client.connected() || client.available()) { //connected or data available
// char c = client.read();
// Serial.print(c);
// }
client.stop();
Serial.println("disconnected");
Serial.println("==================");
}
else {
Serial.println("connection failed");
Serial.println("==================");
}
}