Hello all
I am having some trouble with a for loop and need help as i can't find any solution on line. The below code was designed to run through the for loop 100 times checking my temperatures on my solar system. After 100 times it would send the data to my data base on line.
If i run the code with a 15 times loop it works all OK and will run happily for over a day when testing. But if i increase it to 100 or more it will only send the data once then it stops sending data as if the arduino has locked up.
Any one got any idea what is happening or a work around please.
I could run the program on a 15 times loop but will have to put code into my php script to limit the amount of data coming in to MySql. I would prefer the arduino to limit this data so i can hold more long turn data on line.
thanks
#include <SPI.h>
#include <Ethernet.h>
#include<OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 3
#define TEMPERATURE_PRECISION 12
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
//IPAddress ip (192, 168, 1, 74);
//IPAddress server (184,168,138,128);//ip address for my web server
char serverName[] = "88888888888";
OneWire oneWire(ONE_WIRE_BUS);
EthernetClient client;
DallasTemperature sensors(&oneWire);
DeviceAddress panelTemp = { 0x28, 0xB4, 0x52, 0x9D, 0x04, 0x00, 0x00, 0x31 };
DeviceAddress lowerCylinder = { 0x28, 0x7C, 0xB4, 0xA0, 0x04, 0x00, 0x00, 0x9C};
DeviceAddress upperCylinder = {0x28, 0xC4, 0xB5, 0xA1, 0x04, 0x00, 0x00, 0x78 };
int panelin;// variable to store panel temperature
int lowerin;// variable to store lower cylinder temperature
int upperin;// variable to store upper cylinder
int pump = 8;
int diff;
void setup(){
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
Serial.begin(9600);
Serial.println("Start setup");
pinMode(pump, OUTPUT);
Serial.println ("setup end");
}
void loop (){
//Serial.println ("start loop");
for (int x=0; x<100; x++)
{
//Serial.println (x);
panelin = sensors.getTempC(panelTemp);// read sensor into var panelin to send to GET function
lowerin = sensors.getTempC(lowerCylinder);
upperin = sensors.getTempC (upperCylinder);
sensors.requestTemperatures ();
//Serial.println (panelin);// serial print for fault finding
//Serial.println (lowerin);// fault finding
//Serial.println (upperin);
pumpcontrol ();
}
sendGET();
}
void sendGET() //client function to send/receive GET request data.
{
//Serial.println ("send data");
if (client.connect(serverName, 80)) { //starts client connection, checks for connection
//Serial.println("connected");
client.print("GET /88888888.php?panel=");//send panel = to server
client.print(panelin);//add panelin temperature to above line note no println in code
client.print("&lower=");
client.print(lowerin);
client.print("&upper=");
client.print(upperin);
client.println(" HTTP/1.0");// add to end of GET send with println
client.println("Host: 8888888888");// my web host address
client.println(); //end of get request
// Serial.println ("end send data");
}
else {
Serial.println("connection failed"); //error message if no client connect
Serial.println();
}
while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available()) { //connected or data available
char c = client.read(); //gets byte from ethernet buffer
//Serial.print(c); //prints byte to serial monitor
}
//Serial.println();
//Serial.println("disconnecting.");
//Serial.println("==================");
//Serial.println();
client.stop(); //stop client
}
void pumpcontrol(){
diff = lowerin + 25;
if (diff < panelin){
digitalWrite (pump, HIGH);
delay(5000);
digitalWrite (pump, LOW);
delay(9000);
}
else{
delay (10000);
}
}