Go Down

Topic: Question on Ethernet webclient and sending variables (Read 899 times) previous topic - next topic

genxweb

I have a arduino sketch that will email a person using a php form that it calls by URL with the variables such as TO=user@domain.com&FROM=Me@domain.com

That all works

But what I want to do is take the a arduino variable from a sensor or another arduino function and use that in the Get statement

Code: [Select]

[b]int mBody = 5;[/b]

if (client.connect(serverName, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
   client.println("GET /~genxweb/armail.php?TO=reciever@gmail.com&FROM=mike@me.net&SUBJECT=Test&MESSAGE=[b]mBody[/b]&CODE=SECRET HTTP/1.0");
    client.println();
    digitalWrite(ledIP, LOW);
    digitalWrite(ledMail, HIGH);
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
digitalWrite(ledIP, LOW);
    digitalWrite(ledMail, LOW);
  }
}


Here is a sample where I try to assign mBody a value of 5 and try to use that variable in the client.print and it will only send it as a string and not use the value. I read somewhere that I need to use string and define it but I am still learning and I dont understand the statement. I spent the last few hours on the forums trying to figure this out with no luck.

If I was doing this in Ruby a language I know I would put #{mBody} in the string and be good. Can some one shed some light on this.

Thanks in advance.

bubulindo

Don't use String. It's a memory hog.

Try this.
Code: [Select]

[b]int mBody = 5;[/b]

if (client.connect(serverName, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
   client.print("GET /~genxweb/armail.php?TO=reciever@gmail.com&FROM=mike@me.net&SUBJECT=Test&MESSAGE=[b]); //CHANGED
   client.print(mBody); //ADDED
   client.println("[/b]&CODE=SECRET HTTP/1.0"); //ADDED
    client.println();
    digitalWrite(ledIP, LOW);
    digitalWrite(ledMail, HIGH);
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
digitalWrite(ledIP, LOW);
    digitalWrite(ledMail, LOW);
  }
}

This... is a hobby.

genxweb

Now I am getting error 408 time outs. Verified the server is still up and the sketch works with original code as well still. I have done this:

Code: [Select]

int mBody = 5;
  if (client.connect(serverName, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
   client.print("GET /~genxweb/armail.php?TO=recieverb@gmail.com&FROM=mike@me.net&SUBJECT=Test&MESSAGE=");
   client.print(mBody);
   client.print("&CODE=SECRET HTTP/1.0");
   client.println();
    digitalWrite(ledIP, LOW);
    digitalWrite(ledMail, HIGH);
  }


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy