send value char (ON or OFF) via ethernet

hi maters…

my project is ‘system monitor level of firepump online’.the data must be send by arduino like this

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[] = "";
// If no domain name, use the ip address above
// char serverName[] = "";

// 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() {

  // 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"));



void loop()
  thisMillis = millis();

  if(thisMillis - lastMillis > delayMillis)
    lastMillis = thisMillis;

    // Modify next line to load different page
    // or pass values to server
    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];
   // sprintf(pageAdd,"/insertareg.php?level=%s&press=%s",levelBuffer,pressBuffer);

    if(!getPage(server,serverPort,pageAdd)) Serial.print(F("Fail "));
    else Serial.print(F("Pass "));
    //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];



    sprintf(outBuf,"GET %s HTTP/1.1",page);
    sprintf(outBuf,"Host: %s",serverName);
    client.println(F("Connection: close\r\n"));
    return 0;

  // connectLoop controls the hardware fail timeout
  int connectLoop = 0;

      inChar =;
      // set connectLoop to zero if a packet arrives
      connectLoop = 0;


    // if more than 10000 milliseconds since the last packet
    if(connectLoop > 10000)
      // then close the connection from this end.
    // this is a delay for the connectLoop timing


  // close client end

  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

sprintf(stp1Buffer,"%s",stat1); sprintf(stp2Buffer,"%s",stat1); sprintf(stp3Buffer,"%s",stat1); sprintf(stp4Buffer,"%s",stat1);

It's pretty silly to use sprintf() to copy one string to another. It's even sillier to expect sprintf() to handle a String using %s. It's even sillier to be making 4 copies of the same crap.

  // disable SD SPI
//  pinMode(4,OUTPUT);
 // digitalWrite(4,HIGH);

Is your delete key broken. Get it fixed.

sorry for my mistake..may be that so silly sketch,, :P in my opinion like this :


did its dtill silly sketch master?? how to fix for including values "ON/OFF" to pageadd?? i try like this :


but never correct. :(

and about

// disable SD SPI
//  pinMode(4,OUTPUT);
 // digitalWrite(4,HIGH);

i think i have no problem to delete this? cause i use Xboard v.2 which no have SD on its hardware. hope your correction please..thx

The %s format specifier applies to strings, NOT Strings. Shitcan the stupid Strings.

SOLVED,its work i use strcpy and strcat from c++, and then moved to data string with sprintf. like this..

    char c1[32];
    char c3[32];
    char c4[32];
    char* c5[]={"ON","OFF"};

    strcpy (c1, "stpump1=");
    strcat (c1, c5[0]);            //c5[0] in here "ON"
    strcpy (c3, "stpump2=");
    strcat (c3, c5[1]);       /c5[1] in here "ON"

thx for your guidance master..hope this sketch not like a silly again..:P


Pretty heavy code to combine strcpy() and strcat() into one function call. Lighter weight code:

strcpy(c4, c1);
strcat(c4, c3);

like that combination so much.hope my coding will be improved more and more… :slight_smile: