Pages: [1]   Go Down
Author Topic: Question on Ethernet webclient and sending variables  (Read 608 times)
0 Members and 1 Guest are viewing this topic.
PA
Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
[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.
Logged

'round the world...
Offline Offline
Faraday Member
**
Karma: 42
Posts: 3221
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Try this.
Code:
[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);
  }
}
Logged

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

PA
Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);
  }
Logged

PA
Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I resolved this. Thanks for the help.

Logged

Pages: [1]   Go Up
Jump to: