[solved]Scheduler looping for the web server

Dear All, I would like to ask how can i use scheduler or other function to let my program repeat every 10 second, so that, it can always upload the status to the web sever...

I tried to find some scheduler header files, but i don't know why it can't work..

Below is the easiest header file and example i found.

poor programming skill... please help....

// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// try to use schedule

#include <SPI.h>
#include <Ethernet.h>
#include <EasyScheduler.h>// include this file to use this library

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "192.168.8.5"; // IP for the server

Schedular Task1;

EthernetClient client;

void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600); // set serial bit 9600

Task1.start();

// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac);
}
// give the Ethernet shield a second to initialize:
delay(1000);

Serial.print("Ethernet IP address:"); Serial.println(Ethernet.localIP()); // if you get a connection, show the ip
Serial.println("Connecting...");

if (client.connect(server,80))//server, 80
{ Serial.println("connected");
client.println("GET /input.asp?Site=test&Charger=test&Status=1"); // i want to repeatly update this status.......
client.println(" HTTP/1.1");
client.println("HOST: 192.168.8.4");
client.println("Connection: close");
client.println();
Task1.check(web,5000);
}

else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}

}

void loop()
{

if (client.available()) {
char c = client.read();
Serial.print(c);

}

// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
while (true);// it should be canceled if i want to loop every 10 second
// do nothing forevermore:
}
}

void web()
{
client.println("GET /input.asp?Site=test&Charger=test&Status=1");
client.println(" HTTP/1.1");
client.println("HOST: 192.168.8.4");
client.println("Connection: close");
client.println();
}

Throw away that library! All you need is an unsigned long and the millis() function. Using libraries for trivial operations usually leads to sorrow.

See one of the hundreds of other threads or guides on using millis() for more info. See also blink without delay example.
Basic idea:

unsigned long lastdidit;
unsigned long interval = 10000;
void loop() {
if (millis()-lastdidit > interval) { // has it been longer than interval since we last did it?
doit(); //if yes, then do it
lastditit=millis(); //and set lastditit to the current time
}
}

You are missing the Task1.Check(10000) method call within the loop.

I advise you to create a simple sketch first which simply lets a LED blink with that library. I think you don't understand how it works.

In contrast to DrAzzy I like the approach, I wrote a similar library (its just 3 methods and like 10 lines of code) because IMO it improves readability a lot if you have multiple events that need to be timed.
And writing the same code over and over is just a waste of time.

Below is the code i used to get a looping, which is mainly focus on this part

""if (millis() - lastConnectionTime > postingInterval) {web();}""

// try to use schedule

#include <SPI.h>
#include <Ethernet.h>
#include <EasyScheduler.h>// include this file to use this library

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "220.246.217.199"; // IP for the server

String inChar; // string for the site name by input
String stat ; // string for status of the charger

int inpin = 1; //analog pin1
float val =0;

EthernetClient client;
Schedular Task1;

unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 20L * 1000L; // delay between updates, in milliseconds
// the "L" is needed to use long type numbers
// 20L = 20 Second

void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600); // set serial bit 9600
pinMode(inpin,INPUT); // set pin1 as input pin
while (!Serial) {; }// wait for serial port to connect. Needed for Leonardo only
//Task1.start();
Ethernet.begin(mac);
val = analogRead(inpin)* (5.0/1023.0);
Serial.print(val);Serial.println("V");// show the analog reading value
if (val >800){stat = "Occupied";Serial.println("Occupied");}
else {stat = "Available";Serial.println("Available");}
Serial.print("Ethernet IP address:"); Serial.println(Ethernet.localIP()); // if you get a connection, show the ip
Serial.println("Connecting...");

// start the Ethernet connection:
//if (Ethernet.begin(mac) == 0) {
//Serial.println("Failed to configure Ethernet using DHCP");
//// no point in carrying on, so do nothing forevermore:
//// try to congifure using IP address instead of DHCP:
//Ethernet.begin(mac);
// }
}

void loop()
{
// Task1.check(web,2000);

//Sch.dispatchTasks();
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (millis() - lastConnectionTime > postingInterval) {
web();
// if the server's disconnected, stop the client:
// if (!client.connected()) {
// Serial.println();
// Serial.println("disconnecting.");
// client.stop();
//while (true);// it should be canceled if i want to loop every 10 second
// // do nothing forevermore:
}
}

void web()
{
//delay(1000);// give the Ethernet shield a second to initialize:
client.stop();
if (client.connect(server,80))//server, 80
{
Serial.println("connected");
client.println("GET /input.asp?Site=SSP&Charger=1&Status=Available");
client.println(" HTTP/1.1");
client.println("HOST: 220.246.217.199");
client.println("Connection: close");
client.println();
lastConnectionTime = millis();
}

else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}

}