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();
}