hi maters...
my project is 'system monitor level of firepump online'.the data must be send by arduino like this
http://xxx.com/insertareg.php?level=160&press=2.9&stpump1=ALARM&stpump2=OFF&stpump3=OFF&stpump4=OFF
the table of update data like in the pic :
this is my sketch :
/*
sistem monitoring level kolam pemadam via website
Posted January 16 by fixduino
Last modified January 30, 2014
*/
#include <SPI.h>
#include <Ethernet.h>
// this must be unique
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// change to your network settings
IPAddress ip(192,168,3,x);
IPAddress gateway(192, 168, 3, 1);
IPAddress subnet(255, 255, 255, 0);
// change to your server
IPAddress server(31,xx,xx,xx);
//Change to your domain name for virtual servers
char serverName[] = "www.xx.com";
// If no domain name, use the ip address above
// char serverName[] = "74.125.227.16";
// change to your server's port
int serverPort = 80;
EthernetClient client;
//int totalCount = 0;
float levelValue=0;
float pressValue = 0;
int stp1Value = 0;int stp2Value = 0;int stp3Value = 0;int stp4Value = 0;
String stat1;
String stat2;String stat3;String stat4;
char* myStrings[]={"ON", "OFF"}; //declare status pump
char pageAdd[128];
// set this to the number of milliseconds delay
// this is 30 seconds
#define delayMillis 30000UL
unsigned long thisMillis = 0;
unsigned long lastMillis = 0;
void setup() {
Serial.begin(9600);
// disable SD SPI
// pinMode(4,OUTPUT);
// digitalWrite(4,HIGH);
// Start ethernet
Serial.println(F("Starting ethernet..."));
Ethernet.begin(mac, ip, gateway, gateway, subnet);
// If using dhcp, comment out the line above
// and uncomment the next 2 lines
// if(!Ethernet.begin(mac)) Serial.println(F("failed"));
// else Serial.println(F("ok"));
digitalWrite(10,HIGH);
Serial.println(Ethernet.localIP());
delay(2000);
Serial.println(F("Ready"));
}
void loop()
{
thisMillis = millis();
if(thisMillis - lastMillis > delayMillis)
{
lastMillis = thisMillis;
// Modify next line to load different page
// or pass values to server
//sprintf(pageAdd,"/",totalCount);
levelValue=analogRead(A0);
pressValue=analogRead(A1); // Serial.println(totalCount,DEC);
stp1Value=analogRead(A2); // status pump1
stp2Value=analogRead(A3); //status pump2
stp3Value=analogRead(A4); //status pump3
stp4Value=analogRead(A5); //status pump4
levelValue = (levelValue/1023.0)*200.0; //convert the analog data tolevel .max 200cm
pressValue = (pressValue/1023.0)*10.0; //convert the analog data to press. max 10kg/cm2
if (stp1Value>0){
stat1= myStrings[0]; //if any value ,make status pump1 ON
} else {
stat1= myStrings[1]; //make status pump1 OFF
}
if (stp2Value>0){
stat2= myStrings[0];
} else {
stat2= myStrings[1];
}
if (stp3Value>0){
stat3= myStrings[0];
} else {
stat3= myStrings[1];
}
if (stp4Value>0){
stat4= myStrings[0];
} else {
stat4= myStrings[1];
}
char levelBuffer[8];
char pressBuffer[8];
char stp1Buffer[8];
char stp2Buffer[8];
char stp3Buffer[8];
char stp4Buffer[8];
dtostrf(levelValue,3,1,levelBuffer);
dtostrf(pressValue,3,1,pressBuffer);
sprintf(stp1Buffer,"%s",stat1);
sprintf(stp2Buffer,"%s",stat1);
sprintf(stp3Buffer,"%s",stat1);
sprintf(stp4Buffer,"%s",stat1);
// sprintf(pageAdd,"/insertareg.php?level=%s&press=%s",levelBuffer,pressBuffer);
//sprintf(pageAdd,"/insertareg.php?level=%s&press=%s&stpump1=%s&stpump2=%s&stpump3=%s&stpump4=%s",levelBuffer,pressBuffer,stat1,stat2,stat3,stat4);
sprintf(pageAdd,"/insertareg.php?level=%s&press=%s&stpump1=%s&stpump2=%s&stpump3=%s&stpump4=%s",levelBuffer,pressBuffer,stp1Buffer,stp2Buffer,stp3Buffer,stp4Buffer);
if(!getPage(server,serverPort,pageAdd)) Serial.print(F("Fail "));
else Serial.print(F("Pass "));
//totalCount++;
//Serial.println((byte)tempValue); //send the data to the computer
Serial.println(levelValue); //send the data to the computer
Serial.println(pressValue); //send the data to the computer
Serial.println(stat1); //
delay(1000); //wait one second before sending new data
}
}
byte getPage(IPAddress ipBuf,int thisPort, char *page)
{
int inChar;
char outBuf[128];
Serial.print(F("connecting..."));
if(client.connect(ipBuf,thisPort))
{
Serial.println(F("connected"));
sprintf(outBuf,"GET %s HTTP/1.1",page);
client.println(outBuf);
sprintf(outBuf,"Host: %s",serverName);
client.println(outBuf);
client.println(F("Connection: close\r\n"));
}
else
{
Serial.println(F("failed"));
return 0;
}
// connectLoop controls the hardware fail timeout
int connectLoop = 0;
while(client.connected())
{
while(client.available())
{
inChar = client.read();
Serial.write(inChar);
// set connectLoop to zero if a packet arrives
connectLoop = 0;
}
connectLoop++;
// if more than 10000 milliseconds since the last packet
if(connectLoop > 10000)
{
// then close the connection from this end.
Serial.println();
Serial.println(F("Timeout"));
client.stop();
}
// this is a delay for the connectLoop timing
delay(1);
}
Serial.println();
Serial.println(F("disconnecting."));
// close client end
client.stop();
return 1;
}
and now,my little problem is just send value status of pump (ON or OFF).i am still have no understand about char[]. thanks